Linking to boost through SConstruct

故事扮演 提交于 2019-12-12 09:58:23

问题


I'm trying to work on a cross-platform project that uses boost for the file/directory operations. I've been using visual studio, but in order to compile on linux, I've decided to switch to SConstruct.

I cannot [correctly?] link to the filesystem library however.

my SConstruct file is as follow:

vLibs = [   
            'libboost_system-vc100-mt-1_44.lib',
            'libboost_filesystem-vc100-mt-1_44.lib'];
# LIBS=vLibs,
env = Environment();

env.AppendUnique(CXXFLAGS=Split("/EHsc"));
env.Append(CPPPATH = ["C:\\Program Files (x86)\\boost\\boost_1_44"]);
env.Append(LIBPATH = ["C:\\Program Files (x86)\\boost\\boost_1_44\\lib"]);

env.Program( Glob('test.cpp'),LIBS=vLibs)

I keep getting errors like

test.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" (??__Eposix_category@system@boost@@YAXXZ)

If I use visual studio, I get similar errors:

Error 2 error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ) T:\VS\temp\test.obj temp

Until I add the libraries to the project, after which the errors go away and it compiles fine (in visual studio not SConstruct).

I've tried every combination of the libraries (shared/unshared/runtime-shared/runtime-unshared/debug), but I always get the same errors.

I've been searching for an answer for the last 6+ hours, so I'm grateful for any help.

NOTE: I'm not using autolinking (#define BOOST_ALL_NO_LIB) because gcc doesn't support it)

Here's the output of Scons:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...


link /nologo /OUT:build\test.exe "/LIBPATH:C:\Program Files (x86)\boost\boost_1_44\lib" libboost_system-vc100-mt-1_44.lib     libboost_filesystem-vc100-mt-1_44.lib build\test.obj
test.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl     boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" (??    __Eposix_category@system@boost@@YAXXZ)
test.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl     boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??    __Enative_ecat@system@boost@@YAXXZ)
build\test.exe : fatal error LNK1120: 2 unresolved externals
scons: *** [build\test.exe] Error 1120
scons: building terminated because of errors.

回答1:


I got the exact same error until I rebuilt boost with the address-model=64 parameter to bjam




回答2:


By default Boost builds for x86 and SConstruct builds by default for x64. To change SConstruct to use x86, use env = Environment(TARGET_ARCH='x86'); or to change Boost to x64, pass the address-model=64 parameter to bjam.




回答3:


I don't think the lib prefix nor suffix should be present. Try these it like this in your SCons LIBS:

boost_filesystem-vc100-mt-1_44


来源:https://stackoverflow.com/questions/4487646/linking-to-boost-through-sconstruct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!