【发布时间】:2011-05-28 02:56:42
【问题描述】:
我正在尝试使用 boost 进行文件/目录操作的跨平台项目。我一直在使用visual studio,但是为了在linux上编译,我决定切换到SConstruct。
但是,我无法 [正确?] 链接到文件系统库。
我的 SConstruct 文件如下:
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)
我不断收到类似的错误
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 ) 在函数“void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)”中引用 (??__Eposix_category@system@boost@@YAXXZ)
如果我使用 Visual Studio,我会收到类似的错误:
错误 2 错误 LNK2001: 无法解析的外部符号 "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 温度
直到我将库添加到项目中,之后错误消失并且编译正常(在 Visual Studio 中不是 SConstruct)。
我已经尝试了库的每种组合(共享/非共享/运行时共享/运行时非共享/调试),但我总是遇到相同的错误。
我在过去 6 个多小时内一直在寻找答案,所以我很感激任何帮助。
注意:我没有使用自动链接(#define BOOST_ALL_NO_LIB),因为 gcc 不支持它)
这是 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.
【问题讨论】:
-
请贴出 scons 生成的链接命令行。通常
LIBS是一个库名列表(例如boost_system-vc100-mt-1_44),而不是完整的文件名。 -
是的,lib 扩展不应该在那里,但无论哪种方式都没有区别 - 如果没有扩展,它会给出相同的错误。在这里,我逐字复制了名称,以确保它在 Visual Studio 中有效,但在 scons 中无效。
-
另一个猜测:上一个问题 (stackoverflow.com/questions/1066071/…) 暗示它可能是架构问题:32 位与 64 位库。
-
我没有看到这个问题(希望我有 - 可以节省我 6 多个小时)。我曾假设 scons 默认使用 32 位(如 Visual Studio),但事实并非如此。 “env = 环境(TARGET_ARCH='x86');”解决了这个问题。我真的很想给你答案戴夫,你救了我无数小时的痛苦!
标签: c++ visual-studio boost linker scons