我正在针对一些遗留的第三方库构建一个应用程序,并且在链接阶段遇到了问题。我正在尝试用Visual Studio 9编译。我的编译命令是:
cl -DNT40 -DPOMDLL -DCRTAPI1=_cdecl
-DCRTAPI2=cdecl -D_WIN32 -DWIN32 -DWIN32_LEAN_AND_MEAN -DWNT -DBYPASS_FLEX -D_INTEL=1 -DIPLIB=none -I. -I"D:\src\include" -I"C:\Program Files\Microsoft Visual Studio
9.0\VC\include" -c -nologo -EHsc -W1 -Ox -Oy- -MD mymain.c代码可以干净地编译。link命令为:
link -debug -nologo -machine:IX86
-verbose:lib -subsystem:console mymain.obj wsock32.lib advapi32.lib
msvcrt.lib oldnames.lib kernel32.lib
winmm.lib [snip large list of
dependencies] D:\src\lib\app_main.obj
-out:mymain.exe我得到的错误是:
app_main.obj : error LNK2019:
unresolved external symbol
"_\_declspec(dllimport) public: void
__thiscall std::locale::facet::_Register(void)"
(__imp_?_Register@facet@locale@std@@QAEXXZ)
referenced in function "class
std::ctype<char> const & __cdecl
std::use_facet<class std::ctype<char>
(class std::locale const &)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z)
app_main.obj : error LNK2019:
unresolved external symbol
"__declspec(dllimport) public: static
unsigned int __cdecl
std::ctype<char>::_Getcat(class
std::locale::facet const * *)"
(__imp_?_Getcat@?$ctype@D@std@@SAIPAPBVfacet@locale@2@@Z)
referenced in function "class
std::ctype<char> const & __cdecl
std::use_facet<class std::ctype<char>
(class std::locale const &)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z)
app_main.obj : error LNK2019:
unresolved external symbol
"__declspec(dllimport) public: static
unsigned int __cdecl
std::ctype<unsigned
short>::_Getcat(class
std::locale::facet const * *)"
(__imp_?_Getcat@?$ctype@G@std@@SAIPAPBVfacet@locale@2@@Z)
referenced in function "class
std::ctype<unsigned short> const &
__cdecl std::use_facet<class std::ctype<unsigned short> >(class
std::locale const &)"
(??$use_facet@V?$ctype@G@std@@@std@@YAABV?$ctype@G@0@ABVlocale@0@@Z)
mymain.exe : fatal error LNK1120: 3
unresolved externals注意,这些错误来自遗留代码,而不是我的代码- app_main.obj是遗留代码的一部分,而mymain.c是我的源代码。我已经做了一些搜索,我读到的内容表明,这种类型的错误是由于我的代码和我要链接的库之间的-MD开关不匹配而导致的。由于我正在处理遗留代码,因此必须从我的环境中找到解决方案。我已经很长时间没有做过C++的工作了,甚至更久没有使用Visual Studio了,所以我希望这只是我的一些无知。对如何解决这些问题有什么想法吗?
发布于 2008-08-25 15:02:25
在尝试将这些东西编译到VS2008下之后,我尝试了VS - 2005的早期版本,但出现了警告,而2003就是这样。我仔细检查了链接,没有发现任何问题,所以要么我就是找不到它,要么这不是问题所在。
所以重申一下,降级到VS2003修复了这个问题。
发布于 2008-08-22 19:06:54
这些是标准库参考。确保所有的库(包括标准库)都使用相同的链接。例如,你不能在动态链接标准库的时候静态链接。所使用的线程模型也是如此。请特别注意,您和第三方库使用相同的链接选项。
这在党卫军中可能是一个真正的痛苦。
发布于 2008-08-25 15:18:38
在MSDN上查看此内容
注意:"...这样链接器将使用LIBCMT.lib来解析外部符号“
因此,您需要一组不同的库。
我是如何找到要链接的库的:
G218
老滑头,但它worked为我。
1月
https://stackoverflow.com/questions/23209
复制相似问题