Problem with linking files using boost::log with CMake Buildfile
Hi,
I've got problems compiling a program using boost with CMake (using
Windows and MinGW 4.7.2, with -G "MinGW Makefiles"). Boost is compiled
normaly with b2.exe --toolset=gcc --prefix=C:\cppLib\boost_1_55_0 and
the folder seems to contain the right files. The original CMake-File
compiled fine using Ubuntu. I've got a code using only boost::log and a
CMake File containing the following boost-related-code:
ADD_DEFINITIONS("-std=c++0x")
SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/")
link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
if(Boost_FOUND)
MESSAGE("Boost found")
include_directories(${Boost_INCLUDE_DIRS})
add_executable(Hasselbrack ${AUTO_SOURCES})
endif()
This code works right, but when I call make, I get the following errors:
In file included from
C:/cppLib/boost_1_55_0/boost/log/expressions/formatters/c_decorator.hpp:21:0,
from C:/cppLib/boost_1_55_0/boost/log/expressions/formatters.hpp:29,
from C:/cppLib/boost_1_55_0/boost/log/expressions.hpp:26,
from C:\Users\DaGeRe\cpp\Minimalprojekt\main.cpp:3:
C:/cppLib/boost_1_55_0/boost/log/detail/snprintf.hpp:45:9: Fehler:
╗::swprintf½ wurde nicht deklariert
C:/cppLib/boost_1_55_0/boost/log/detail/snprintf.hpp:46:9: Fehler:
╗::vswprintf½ wurde nicht deklariert
In file included from
C:/cppLib/boost_1_55_0/boost/log/expressions/formatters.hpp:29:0,
from C:/cppLib/boost_1_55_0/boost/log/expressions.hpp:26,
from C:\Users\DaGeRe\cpp\Minimalprojekt\main.cpp:3:
C:/cppLib/boost_1_55_0/boost/log/expressions/formatters/c_decorator.hpp:
In statischer Elementfunktion ╗static std::size_t
boost::log::v2s_mt_nt5::exp
ressions::aux::c_decorator_traits
On 12/5/2013 4:13 PM, David Georg Reichelt wrote:
Hi,
I've got problems compiling a program using boost with CMake (using Windows and MinGW 4.7.2, with -G "MinGW Makefiles"). Boost is compiled normaly with b2.exe --toolset=gcc --prefix=C:\cppLib\boost_1_55_0 and the folder seems to contain the right files. The original CMake-File compiled fine using Ubuntu. I've got a code using only boost::log and a CMake File containing the following boost-related-code:
ADD_DEFINITIONS("-std=c++0x") SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/") link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
if(Boost_FOUND) MESSAGE("Boost found") include_directories(${Boost_INCLUDE_DIRS}) add_executable(Hasselbrack ${AUTO_SOURCES}) endif()
Just a quick reaction: why do you link boost libraries before you know whether boost was found? Would it make more sense to move link_libraries() into the if(Boost_FOUND) block? Andy
Am 06.12.2013 00:48, schrieb Michael Chisholm:
On 12/5/2013 4:13 PM, David Georg Reichelt wrote:
Hi,
I've got problems compiling a program using boost with CMake (using Windows and MinGW 4.7.2, with -G "MinGW Makefiles"). Boost is compiled normaly with b2.exe --toolset=gcc --prefix=C:\cppLib\boost_1_55_0 and the folder seems to contain the right files. The original CMake-File compiled fine using Ubuntu. I've got a code using only boost::log and a CMake File containing the following boost-related-code:
ADD_DEFINITIONS("-std=c++0x") SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/") link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
if(Boost_FOUND) MESSAGE("Boost found") include_directories(${Boost_INCLUDE_DIRS}) add_executable(Hasselbrack ${AUTO_SOURCES}) endif()
Just a quick reaction: why do you link boost libraries before you know whether boost was found? Would it make more sense to move link_libraries() into the if(Boost_FOUND) block?
Andy
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks for the advice, you're right, that makes more sense. I changed it, so link_libraries (${Boost_LIBRARIES}) is now in the if-block, but unfortunately, the output is not changed. DaGeRe
AMDG On 12/05/2013 01:13 PM, David Georg Reichelt wrote:
<snip>
ADD_DEFINITIONS("-std=c++0x") SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/") link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
Did you mean Boost 1.55.0?
<snip>
This code works right, but when I call make, I get the following errors:
<snip> C:/cppLib/boost_1_55_0/boost/log/detail/snprintf.hpp:45:9: Fehler: ╗::swprintf½ wurde nicht deklariert <snip>
The problem is swprintf. I'm guessing that MinGW doesn't support it. You'll probably need -DBOOST_LOG_WITHOUT_WCHAR_T.
If I don't use ADD_DEFINITIONS("-std=c++0x"), I got the following errors:
That's odd. Is Boost.Log somehow being compiled with -std=c++0x? It shouldn't be unless you specified it.
CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x12c): undefined reference to `boost::log::v2s_mt_nt5::core::get()' <snip>
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
But nevertheless, boost is found and I can't figure out CMake seems to be unable to link it. The output of $(Boost_LIBRARIES) from CMake also seems correct: C:/cppLib/boost_1_55_0/stage/lib/libboost_log-mgw47-mt-1_55.dll . So I got no clue anymore what I could try.
Has anybody an hint how to solve this?
In Christ, Steven Watanabe
Am 06.12.2013 16:59, schrieb Steven Watanabe:
AMDG
<snip>
ADD_DEFINITIONS("-std=c++0x") SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/") link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
Did you mean Boost 1.55.0? Yes, you're right, that was an error when changing the version.
<snip>
This code works right, but when I call make, I get the following errors:
<snip> C:/cppLib/boost_1_55_0/boost/log/detail/snprintf.hpp:45:9: Fehler: ╗::swprintf½ wurde nicht deklariert <snip>
The problem is swprintf. I'm guessing that MinGW doesn't support it. You'll probably need -DBOOST_LOG_WITHOUT_WCHAR_T. I tried to change ADD_DEFINITIONS to ADD_DEFINITIONS("-std=c++0x -DBOOST_LOG_WITHOUT_WCHAR_T"). This changes the errors to:
If I don't use ADD_DEFINITIONS("-std=c++0x"), I got the following errors:
That's odd. Is Boost.Log somehow being compiled with -std=c++0x? It shouldn't be unless you specified it. Not as I know. Trying to recompile boost leads to the following output: http://nopaste.info/446db7594c.html Has it maybe something to do with
CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x124): undefined reference to `boost::log::v2s_mt_nt5::core::get()' CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x13b): undefined reference to `boost::log::v2s_mt_nt5::core::set_filter(boost::log ::v2s_mt_nt5::filter const&)' CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1bf): undefined reference to `boost::log::v2s_mt_nt5::trivial::logger::get()' CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1df): undefined reference to `boost::log::v2s_mt_nt5::trivial::logger::get()' CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x285): undefined reference to `std::ios_base::Init::~Init()' CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2a6): undefined reference to `std::ios_base::Init::Init()' c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj): bad reloc address 0x138 in s ection `.rdata' c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation collect2.exe: Fehler: ld gab 1 als Ende-Status zurück make[2]: *** [Hasselbrack.exe] Fehler 1 again. But the library is again found correctly in C:/cppLib/boost_1_55_0/stage/lib/libboost_log-mgw47-mt-1_55.dll (And is still correkt in the CMakeCache.txt in Boost_LOG_LIBRARY_RELEASE:FILEPATH=). Is the adding to ADD_DEFINITIONS right, or should I add it somewhere else? At least, it changed the error... the errors? The errors do not realy seem to be related to the log-library.
CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x12c): undefined reference to `boost::log::v2s_mt_nt5::core::get()' <snip>
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
But nevertheless, boost is found and I can't figure out CMake seems to be unable to link it. The output of $(Boost_LIBRARIES) from CMake also seems correct: C:/cppLib/boost_1_55_0/stage/lib/libboost_log-mgw47-mt-1_55.dll . So I got no clue anymore what I could try.
Has anybody an hint how to solve this?
In Christ, Steven Watanabe
Thanks for the advice! Best Regards, DaGeRe
AMDG On 12/07/2013 04:15 AM, David Georg Reichelt wrote:
Am 06.12.2013 16:59, schrieb Steven Watanabe:
AMDG
<snip>
ADD_DEFINITIONS("-std=c++0x") SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/") link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
Wait a minute. Shouldn't link_libraries come /after/ find_package? Does the link command line show that you are linking to boost_log? In Christ, Steven Watanabe
Am 07.12.2013 17:15, schrieb Steven Watanabe:
AMDG
On 12/07/2013 04:15 AM, David Georg Reichelt wrote:
Am 06.12.2013 16:59, schrieb Steven Watanabe:
AMDG
<snip>
ADD_DEFINITIONS("-std=c++0x") SET(BOOST_ROOT "C:/cppLib/boost_1_55_0/") link_libraries (${Boost_LIBRARIES})
find_package( Boost 1.54.0 COMPONENTS log)
Wait a minute. Shouldn't link_libraries come /after/ find_package? Does the link command line show that you are linking to boost_log? Thanks again for the advice! Yes, in the first place it was like this, but after Andy told me that it should be in the if-block it is moved after find_package. The full code now is here: http://nopaste.info/9e73e7d3ac.html
But after that, I googled if there is any hint what I could be doing wrong linking boost log. I found the following thread: http://stackoverflow.com/questions/16540171/boost-log-gcc-4-4-and-cmake It basiacally says that one has to add multiple libraries to get boost log running and that one has to get them in a certain order. After addding them (so now find_package uses find_package( Boost 1.55.0 COMPONENTS system thread filesystem date_time log log_setup REQUIRED) and the code like in http://nopaste.info/65b3273ade.html) I got the errors: CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x285): undefined reference to `std::ios_base::Init::~Init()' CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2a6): undefined reference to `std::ios_base::Init::Init()' c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj): bad reloc addr ection `.rdata' c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation collect2.exe: Fehler: ld gab 1 als Ende-Status zurück So something still does not work with the linker... Do you have any idea what?
In Christ, Steven Watanabe
Best Regards, DaGeRe
On 12/07/2013 08:40 PM, David Georg Reichelt wrote:
CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x285): undefined reference to `std::ios_base::Init::~Init()'
This indicates that you use the C compiler to link a C++ program. In your CMakeLists.txt you explicitly set CMAKE_CXX_COMPILER to gcc, not to g++. In fact, I would not set the compiler variables explicitly as they are auto-detected. It may also be a good idea to tell CMake that you are working on a C++ project: project(TV6 C++)
Am 08.12.2013 12:29, schrieb Bjorn Reese:
On 12/07/2013 08:40 PM, David Georg Reichelt wrote:
CMakeFiles\Hasselbrack.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x285):
undefined reference to `std::ios_base::Init::~Init()'
This indicates that you use the C compiler to link a C++ program.
In your CMakeLists.txt you explicitly set CMAKE_CXX_COMPILER to gcc, not to g++. In fact, I would not set the compiler variables explicitly as they are auto-detected. Thanks, setting the compiler to g++ solved the problem! Now it compiles as normal.
It may also be a good idea to tell CMake that you are working on a C++ project:
project(TV6 C++)
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Bjorn Reese
-
David Georg Reichelt
-
Michael Chisholm
-
Steven Watanabe