高分请教 C++ boost filesystem 静态链接的问题

一个简单win32控制台程序,使用了boost::filesystem库.链接过不去,提示错误
error LNK2001: 无法解析的外部符号 "class boost::system::error_category const & __cdecl boost::system::system_category(void)
error LNK2001: 无法解析的外部符号 "class boost::system::error_category const & __cdecl boost::system::generic_category(void)
完整源代码
----------------------------------------------
#include "stdafx.h"

/// 设置宏开关连接到静态库.
#undef _DLL
#include <boost/filesystem.hpp>
#define _DLL

/// 连接lib.
#pragma comment(lib, "libboost_filesystem-vc90-mt-s-1_46_1.lib")
#pragma comment(lib, "libboost_system-vc90-mt-s-1_46_1.lib")

void main()
{
using namespace boost::filesystem;
/// 随便实例化一个对象.
path test;
}
----------------------------------------------
我确定已经成功编译了boost最新的版本
编译采用的jam语句如下:(我只需要静态连接不用动态库)
bjam --toolset=msvc-9.0 release link=static runtime-link=static threading=multi
编译后dll的列表如下,且均已放入VC的lib搜索路径下:
libboost_date_time-vc90-mt-s-1_46_1.lib
libboost_filesystem-vc90-mt-s-1_46_1.lib
libboost_graph-vc90-mt-s-1_46_1.lib
libboost_iostreams-vc90-mt-s-1_46_1.lib
libboost_math_c99-vc90-mt-s-1_46_1.lib
libboost_math_c99f-vc90-mt-s-1_46_1.lib
libboost_math_tr1-vc90-mt-s-1_46_1.lib
libboost_math_tr1f-vc90-mt-s-1_46_1.lib
libboost_prg_exec_monitor-vc90-mt-s-1_46_1.lib
libboost_program_options-vc90-mt-s-1_46_1.lib
libboost_random-vc90-mt-s-1_46_1.lib
libboost_regex-vc90-mt-s-1_46_1.lib
libboost_serialization-vc90-mt-s-1_46_1.lib
libboost_signals-vc90-mt-s-1_46_1.lib
libboost_system-vc90-mt-s-1_46_1.lib
libboost_test_exec_monitor-vc90-mt-s-1_46_1.lib
libboost_thread-vc90-mt-s-1_46_1.lib
libboost_unit_test_framework-vc90-mt-s-1_46_1.lib
libboost_wave-vc90-mt-s-1_46_1.lib
libboost_wserialization-vc90-mt-s-1_46_1.lib
----------------------------------------------
使用lib查看工具我也能在libboost_system-vc90-mt-s-1_46_1.lib中看到导出函数,但是就是链接不过,请高手指点.
000066F6 class boost::system::error_category const & __cdecl boost::system::generic_category(void)
----------------------------------------------
我的一些想法
1. 我认为肯定不是路径的问题,因为如果路径不对VC会提示无法找到xxxx.lib
2. 我的操作系统是x64的,但是我比对过用clx86与clx64生成的dll二进制是一样的(boost对x64,x86不敏感)

请指点一下,非常感谢!

最后这个是连接的平台不对导致的, boost也区分x64和win32平台。
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-06-19
看了很久,不好意思,不知道~
第2个回答  2011-06-19
先声明所使用的外部函数:使用 extern 关键字追问

是boost库自己的链接不过去,我怎么可能去修改人家的源代码?

追答

无法解析的外部符号category 。这是因为编译器不认识这个函数,也就是没有做声明吧。而不是因为别人的库有问题。别人的库有问题那也不是无法解析的外部符号这种错误的。

追问

已经解决,原因是我没设置x64编译选项,按x86编译导出函数的格式不匹配造成的

相似回答