我的设置如下:我在Windows上有一个基于CMake的C ++项目。作为编译器,我使用由Qt 5.7 for Windows(MinGW 5.3.0)提供的MinGW 32位编译器。我使用这个编译器,因为它适用于生成的Makefile。发电机是“MinGW Makefiles”。像Clang for Windows这样的其他编译器无法编译生成的Makefile,可能是因为缺少Windows版本的Make?
由于Boost Libraries的手动编译需要很长时间,因此我使用msvc14.0-32的预构建二进制文件(https://sourceforge.net/projects/boost/files/boost-binaries/1.62.0_b2/)。我已经设置了CMake变量等,并找到了Boost Release的库。奇怪的是找不到调试库,所以我必须使用CMake构建类型“Release”。
以下是一些变量:
CMAKE_BUILD_TYPE is "Release"
CMAKE_CXX_COMPILER is "C:/Qt/Tools/mingw530_32/bin/g++.exe".
CMAKE_GENERATOR is "MinGW Makefiles"
CMAKE_MAKE_PROGRAM is "C:/Qt/Tools/mingw530_32/bin/mingw32-make.exe"
BOOST_ROOT is "C:/local/boost_1_62_0_b2"
BOOST_LIBRARYDIR is "C:/local/boost_1_62_0_b2/lib32-msvc-14.0", Boost_COMPILER is "-vc140"
Boost_LIBRARY_DIR_DEBUG is "C:/local/boost_1_61_0/lib64-msvc-14.0"
Boost_LIBRARY_DIR_RELEASE is "C:/local/boost_1_61_0/lib64-msvc-14.0"
Boost_FILESYSTEM_LIBRARY_DEBUG is "Boost_FILESYSTEM_LIBRARY_DEBUG-NOTFOUND"
Boost_FILESYSTEM_LIBRARY_RELEASE is "C:/local/boost_1_61_0/lib64-msvc-14.0/libboost_filesystem-vc140-mt-1_61.lib"
当我编译项目时,它会生成许多未定义的引用错误:
CMakeFiles\wc3libmpq.dir/objects.a(hash.cpp.obj):hash.cpp:(.text+0x559): undefined reference to `boost::filesystem::path::codecvt()'
CMakeFiles\wc3libmpq.dir/objects.a(hash.cpp.obj):hash.cpp:(.text+0x571): undefined reference to `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::codecvt<wchar_t, char, int> const&)'
CMakeFiles\wc3libmpq.dir/objects.a(hash.cpp.obj):hash.cpp:(.text+0x586): undefined reference to `boost::filesystem::path::codecvt()'
CMakeFiles\wc3libmpq.dir/objects.a(hash.cpp.obj):hash.cpp:(.text+0x59e): undefined reference to `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::codecvt<wchar_t, char, int> const&)'
CMakeFiles\wc3libmpq.dir/objects.a(hash.cpp.obj):hash.cpp:(.text+0x78b): undefined reference to `boost::filesystem::path::codecvt()'
CMakeFiles\wc3libmpq.dir/objects.a(hash.cpp.obj):hash.cpp:(.text+0x7a7): undefined reference to `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::codecvt<wchar_t, char, int> const&)'
这些是其中一些。我猜它不起作用,因为它们是用不同的编译器(vc140)而不是Qt的MinGW 32编译的,但我没有找到任何预装的Boost Libraries with MinGW32 for Windows。
理想情况下,我想用Clang 64 Bit设置构建,但是我编写了CMake的Generator“MinGW Makefiles”和指定的Make工具CMAKE_MAKE_PROGRAM,其值为“C:/ Qt / Tools / mingw530_32 / bin / mingw32-make.exe“无法使用适用于Windows的CLang版本。 Qt 5不提供任何MinGW 64版本。除了未定义的引用错误,因为Boost已经使用msvc构建。
所以我的问题是:
是否有适用于Windows的Boost Libraries的基于MinGW32的版本可与Qt的MinGW32编译器配合使用?
OR会更有用
是否有一个CMake Generator和Make工具与Windows上的64位CLang一起工作,还有一个用于Windows的Boost Libraries的构建,它还可以与CLang一起使用?在这种情况下,我还需要一个与CLang一起使用的Qt 5.7 Windows版本,因为Qt 5.7的MinGW版本是32位,所以它是64位。
我想避免在Windows上自行编译任何依赖库。
修改
在我用Cygwin(GCC)自己编译Boost库之后,我仍然得到了对Boost Libraries的未定义引用。我链接到静态库(.a)文件:
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x8d4): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x8d4): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x964): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x964): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xae8): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xae8): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xb08): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xb08): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xb22): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xb22): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xf19): more undefined references to `boost::system::system_category()' follow
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xf19): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0xf40): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x1019): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x1040): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x1119): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x1140): additional relocation overflows omitted from the output
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x47bc): undefined reference to `boost::system::generic_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4bcb): undefined reference to `boost::system::generic_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4d69): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4d92): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4db5): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4e9c): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4ef6): undefined reference to `boost::system::system_category()'
E:/Projekte/boost_1_61_0/stage/lib/libboost_filesystem.a(operations.o):operations.cpp:(.text+0x4f38): more undefined references to `boost::system::system_category()' follow
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(bzip2.o):bzip2.cpp:(.text+0x327): undefined reference to `BZ2_bzDecompressEnd'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(bzip2.o):bzip2.cpp:(.text+0x341): undefined reference to `BZ2_bzCompressEnd'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(bzip2.o):bzip2.cpp:(.text+0x390): undefined reference to `BZ2_bzDecompressInit'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(bzip2.o):bzip2.cpp:(.text+0x3af): undefined reference to `BZ2_bzCompressInit'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(bzip2.o):bzip2.cpp:(.text+0x145): undefined reference to `BZ2_bzCompress'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(bzip2.o):bzip2.cpp:(.text+0x155): undefined reference to `BZ2_bzDecompress'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x12c): undefined reference to `crc32'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x1a5): undefined reference to `deflateReset'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x1c5): undefined reference to `inflateEnd'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x1e1): undefined reference to `inflateReset'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x1f3): undefined reference to `deflateEnd'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x407): undefined reference to `inflateInit2_'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x450): undefined reference to `deflateInit2_'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x174): undefined reference to `deflate'
E:/Projekte/boost_1_61_0/stage/lib/libboost_iostreams.a(zlib.o):zlib.cpp:(.text+0x184): undefined reference to `inflate'
collect2: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [src/mpq/libwc3libmpq.dll] Error 1
mingw32-make.exe[1]: *** [src/mpq/CMakeFiles/wc3libmpq.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
奇怪的是,我没有获得Boost单元测试库的任何未定义引用。我使用Cygwin的GCC编译了库,我的Boost库路径如下:
E:/Projekte/boost_1_61_0/stage/lib/libboost_unit_test_framework.a
首先我用cygwin编译了iostreams库:
./b2.exe -j4 toolset=gcc --with-iostreams -s BZIP2_SOURCE=E:/Projekte/wc3lib/windows/bzip2-1.0.6 -s ZLIB_SOURCE=E:/Projekte/wc3lib/windows/zlib-1.2.8 stage
我编译了所有其他库:
./b2.exe -j4 toolset=gcc stage
这些是我在CMake中的搜索说明:
if (WIN32)
add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED=1)
set(Boost_USE_STATIC_LIBS ON)
include_directories("C:/Program Files/GnuWin32/include")
endif ()
find_package(Boost COMPONENTS system filesystem serialization program_options iostreams regex REQUIRED)