提升库无法在Windows上正确链接
Boost Libraries not linking properly on Windows
我有一个最初建立在MacOS上的大型项目,我正在尝试在Windows上进行编译。该项目的MakeFile如下:
CC=C:/cygwin64/bin/g++.exe
BASE_FLAGS = -std=c++14
LDFLAGS = -I/usr/local/Cellar/boost/1.69.0/include -I/opt/local/include -I include/
LLIBFLAGS = -L/usr/local/Cellar/boost/1.68.0/lib
LINKFLAGS = -lboost_thread -lboost_system -l boost_filesystem -l boost_regex -ll -lm
FLAGS = $(BASE_FLAGS) $(LLIBFLAGS) $(LDFLAGS) $(LINKFLAGS)
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SRCS := $(call rwildcard,src/,*.cpp) $(call rwildcard,src/,*.c)
mac:
cd src; bison -d parse.y --debug -t; flex lex.l
time ./runscripts.sh
$(CC) $(FLAGS) -o main.out $(SRCS)
BASE_FLAGS_WIN = -std=gnu++11
LDFLAGS_WIN = -I include/ -I C:UserselllzDownloadsboost_1_69_0
LLIBFLAGS_WIN = -LC:UserselllzDownloadsboost_1_69_0stagelib
LINKFLAGS_WIN = -lm -lboost_system -lboost_regex -lboost_filesystem -lboost_thread
FLAGS_WIN = $(BASE_FLAGS_WIN) $(LDFLAGS_WIN) $(LLIBFLAGS_WIN) $(LINKFLAGS_WIN)
win:
bison -d .srcparse.y -t -g
flex .srclex.l
.scriptsALL_HEADER_TOKENS.bat
cp .parse.tab.h .srcparse.tab.h
cp .parse.tab.c .srcparse.tab.c
cp .lex.yy.c .srclex.yy.c
rm .parse.tab.h .parse.tab.c .lex.yy.c
$(CC) $(FLAGS_WIN) $(SRCS)
请注意,第一秒是(工作)MacOS目标,稍后是Windows目标。在尝试链接Windows上的链接时,我一直在遇到很多未定义的参考错误,例如:
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x15): undefined reference to `boost::filesystem::path::codecvt()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x32): undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcS3_RSbIwSt11char_traitsIwESaIwEE]+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/cc1jUol1.o:FileVerification.cpp:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x7e): undefined reference to `boost::re_detail_106900::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::c_regex_traits<char> > >::match()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::re_detail_106900::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::c_regex_traits<char>
> >::match()'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j]+0x31): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
/cygdrive/c/Users/elllz/AppData/Local/Temp/ccbzCEFH.o:Token.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_14c_regex_traitsIcEEEEE6assignEPKcS7_j]+0x31): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
那只是一个片段,我能找到的所有信息都说这是一个促进链接问题,但我不能为我的一生固定。我正在用命令编译Boost 1.69.0:
.boostrap.bat
./bjam
./bjam install
以类似于此处的说明类似。我已经尝试了有关我能想到的一切的JSUT,并且花了很多时间重新编译,因此您可能会提供的任何帮助都将不胜感激!
我尝试过的事情:
- 检查诽谤确实存在于/stage/lib中,它们确实存在。
- 将整个Boost文件夹移动到我的构建文件夹的相对路径中,以防我指定链接/包含文件夹错误。
- 通过许多选择重新编译的提升,我无法接近回忆它们。
我怀疑您可能有多个问题...
您的makefile
指定boost
库的不同版本:1.69.0
和1.68.0
LDFLAGS = -I/usr/local/Cellar/boost/1.69.0/include -I/opt/local/include -I include/
LLIBFLAGS = -L/usr/local/Cellar/boost/1.68.0/lib
可能和那样简单。
但是,在Windows
机器上,命令:
.boostrap.bat
通常假设使用Visual Studio
构建boost
库。因此,根据您从构建boost
库的位置,您可能已经构建了Visual Studio
LIB文件,而不是g++
LIB文件。您可以从库文件名来分辨:
// gcc, actually mingw73: mgw73
libboost_filesystem-mgw73-mt-x64-1_69.dll.a
// msvc 2017: vc141
boost_filesystem-vc141-mt-x64-1_69.lib
听起来您的正确,但是您可以在构建boost
时明确指定g++
编译器,例如:
.boostrap.bat gcc
最后,很难维护跨平台makefiles
,尤其是使用boost
。
我建议改用Cmake。
相关文章:
- Windows 链接器是否使用 LoadLibrary 解析 DLL 中未定义的符号?
- 如何链接 DLL 以供 LoadLibrary() 使用(在 Windows 上的 C++ 中)并从调用 exe 导入变
- 如何在Windows上链接动态构建的cmake文件
- 动态链接-Linux与Windows
- 尝试将 sfml 和 c++ 与 Windows 10 上的可移植 vscode 链接起来
- CMake Qt建立在Windows链接器问题之上
- CMake 生成的程序无法在 Windows 上链接:尝试链接到不存在的文件
- Godbolt 在 MSVC 上包含 Windows.h 时无法链接?
- SQLite 在 Windows 上的编译时不链接
- 使用 MINGW 和 CPLEX 库链接从 Linux 编译 Windows 可执行文件
- 如何强制Windows.h在Visual Studio中静态链接而不是动态链接?
- 链接 .lib 并在 Windows 中使用 .dll 在 C++ 在 Eclipse 中
- QT库链接Windows中的错误
- cmake cuda在Windows上单独的编译静态LIB链接错误,但在Ubuntu上没有
- cmake在Windows上与CPPRESTSDK链接
- 静态链接再次链接boost.test和cmake在Windows上的mingw
- libigl,GLEW,GLFW和Eigen在CLion,Windows 10上.链接器错误
- 在 Code::Blocks 中使用自定义安装目录在 Windows 上链接 SDL-bgi
- 在VS2010控制台应用程序中链接Windows.h (WNDCLASSEX)代码
- 如何查找指向文件/文件夹的所有硬链接和符号链接(Windows和UNIX)