Open yuggieg opened 5 years ago
Probably due to set (CMAKE_CXX_STANDARD 17)
in log4cplus
Probably
set (CMAKE_CXX_STANDARD 17)
in log4cplus
Nope, sorry, didn't work...
Nope, sorry, didn't work...
What I mean is that log4cplus is setting CMAKE_CXX_STANDARD so you must set your CMAKE_CXX_STANDARD to the same value.
I see what you mean. I installed log4cplus as a vcpkg, so I don't have direct control. I checked the CMakeLists.txt of log4cplus however and it is indeed set to CMAKE_CXX_STANDARD 17, and I modified it in my CMakeLists.txt to match. To no avail, unfortunately.
build logs also tell me that /std:c++17
is not set although CMAKE_CXX_STANDARD 17
is set. Ah probably you can only use it as a static library? Can you give x64-windows-static a try
Thanks for your help, but unfortutely still not working. Installed the x64-windows-static variant and modified my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12.4)
set(CMAKE_TOOLCHAIN_FILE c:/software/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(VCPKG_TARGET_TRIPLET x64-windows-static)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
project(log4cplustest VERSION 0.1 LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 17)
find_package(log4cplus CONFIG REQUIRED)
add_executable(log4cplustest main.cpp)
target_link_libraries(log4cplustest PRIVATE log4cplus::log4cplusSU)
But still the same stuff:
Microsoft (R) Build Engine version 15.6.85.37198 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
You are not using DLL C run time library. You must call log4cplus::initialize() once before you use any other log4cplus API.
main.obj : error LNK2019: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function main [C:\software\log4plus_test_vcpkg\build\log4cplustest.vcxproj]
main.obj : error LNK2019: unresolved external symbol "class std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> > & __cdecl log4cplus::detail::get_macro_body_oss(void)" (?get_macro_body_oss@detail@log4cplus@@YAAEAV?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function main [C:\software\log4plus_test_vcpkg\build\log4cplustest.vcxproj]
main.obj : error LNK2019: unresolved external symbol "void __cdecl log4cplus::detail::macro_forced_log(class log4cplus::Logger const &,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *,int,char const *)" (?macro_forced_log@detail@log4cplus@@YAXAEBVLogger@2@HAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDH2@Z) referenced in function main [C:\software\log4plus_test_vcpkg\build\log4cplustest.vcxproj]
C:\software\log4plus_test_vcpkg\build\Release\log4cplustest.exe : fatal error LNK1120: 3 unresolved externals [C:\software\log4plus_test_vcpkg\build\log4cplustest.vcxproj]
I also find it weird that I have no problems when I start a new clean Visual Studio project. Then it works. It's just when I use CMake it gives the linker errors.
Missing?
// Initialization and deinitialization.
log4cplus::Initializer initializer;
also:
You are not using DLL C run time library. You must call log4cplus::initialize() once before you use any other log4cplus API.
I also find it weird that I have no problems when I start a new clean Visual Studio project and then it work. It's just when I use CMake it gives the linker errors.
That means it is missing some library to link to but that also what the error says. In VS the whole lib folder gets linked into the project. Could you check the link command if the required linked libraries are added?
That is just a warning on the usage of log4cplus on Windows, would cause problems when running, but not during compiling/linking.
With respect to the link command. It seems fine (the library file also exists):
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Tracker.exe /a /d "C:\Program Files (x86)\MSBuild\15.0\FileTracker\FileTracker32.dll" /i C:\software\log4plus_test_vcpkg\build\log4cplustest.dir\Release\log4cplustest.tlog /r C:\SOFTWARE\LOG4PLUS_TEST_VCPKG\BUILD\LOG4CPLUSTEST.DIR\RELEASE\MAIN.OBJ /b MSBuildConsole_CancelEventdc5a61b839c24719a95d34976b6acbc6 /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\bin\HostX86\x64\link.exe" /ERRORREPORT:QUEUE /OUT:"C:\software\log4plus_test_vcpkg\build\Release\log4cplustest.exe" /INCREMENTAL:NO /NOLOGO "C:\software\vcpkg\installed\x64-windows\lib\log4cplusU.lib" ws2_32.lib advapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"C:/software/log4plus_test_vcpkg/build/Release/log4cplustest.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/software/log4plus_test_vcpkg/build/Release/log4cplustest.lib" /MACHINE:X64 /machine:x64 log4cplustest.dir\Release\main.obj
Also tried to see what the workign VS solution looked like, but couldn't figure out where that gets the libary from. It's a system wide thing it seems. The solution generated by CMake is definetly different, also when I look at it in Visual Studio.
Found something else by looking at the error and the exported symbols from the library. From the error:
"public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
And from the library:
public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@AEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
The difference between the two being something with the basic_string@_WU and basic_string@DU and other string related things. Is this some compiler options that's set in VS?
After looking at the log4cplus macro defintions, I found in tchar.h that that is typedef'd to either char or wchar_t depending on whether UNICODE is defined. After defining UNICODE in my main.cpp, the linker succeeds.
@yuggieg: That means that the log4cplus target is not correctly setup to provide the required compiler definitions/flags for downstream targets. Maybe report that upstream?
@Neumann-A yeah, I'll report it to the log4cplus guys. Thanks for your help!
Hi @yuggieg, thanks for reporting this issue! I've fixed this issue just now. Please update vcpkg and rebuild log4cplus.
Thanks.
I'm still getting errors with log4cplus 2.1.1
error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >
const &)" (?getInstance@Logger@log4cplus@@SA?AV12@AEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
I had to specify unicode
feature in vcpkg.json
to fix the linker error.
{
"name": "log4cplus",
"features": ["unicode"]
}
Sharing to help others.
cc @Cheney-W to confirm whether this issue still exist.
I have issues linking against the log4plus library on Windows, x64, running visual studio 2017.
When using the following main.cpp:
and the accompanying CMakeListst.txt:
Running CMake as follows:
cmake -G "Visual Studio 15 2017 Win64" ..
And building:
cmake --build . --config Release
Give the following linking error:
Any ideas? I also use the cpprestsdk vcpkg and that is not giving me any problems. When creating a new project in Visual Studio and using that instead of CMake, it also works.