【发布时间】:2015-07-02 14:24:06
【问题描述】:
我有一个 VC++ 项目,我正在尝试使用 gumbo-query 库的扩展,发现 here。这个库包装/扩展了 Google 的 gumbo-parser 发现 here。以下是我采取的确切步骤 - 我对导入库不是很熟悉,所以我已经完成了使用 Boost 库的操作:
在 Visual Studio(VS Community 2013)中,在项目设置 -> 配置属性 -> C/C++ -> 常规下,我已将路径放置到一个文件夹中,该文件夹包含来自上面链接的两个项目的所有源文件.具体来说,我从两个项目的 src 文件夹中放置了 .c、.cpp 和 .h 文件,并在我的项目设置中将它们作为包含目录引用。
按照扩展 Google 的 gumbo-parser (found here) 的项目的示例文件,我添加了这两行来导入库:
#include "Document.h"
#include "Node.h"
此时,我的解决方案编译良好。不过,继续按照示例文件,添加第一个变量声明:
CDocument d;
导致链接器错误,如下:
1>Main.obj : error LNK2028: unresolved token (0A0003B7) "public: __thiscall CDocument::CDocument(void)" (??0CDocument@@$$FQAE@XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork@Main@MyApplication@@$$FA$AAMXP$AAVObject@System@@P$AAVDoWorkEventArgs@ComponentModel@4@@Z)
1>Main.obj : error LNK2028: unresolved token (0A0003B8) "public: virtual __thiscall CDocument::~CDocument(void)" (??1CDocument@@$$FUAE@XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork@Main@MyApplication@@$$FA$AAMXP$AAVObject@System@@P$AAVDoWorkEventArgs@ComponentModel@4@@Z)
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall CDocument::CDocument(void)" (??0CDocument@@$$FQAE@XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork@Main@MyApplication@@$$FA$AAMXP$AAVObject@System@@P$AAVDoWorkEventArgs@ComponentModel@4@@Z)
1>Main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CDocument::~CDocument(void)" (??1CDocument@@$$FUAE@XZ) referenced in function "private: void __clrcall MyApplication::Main::worker_DoWork(class System::Object ^,class System::ComponentModel::DoWorkEventArgs ^)" (?worker_DoWork@Main@MyApplication@@$$FA$AAMXP$AAVObject@System@@P$AAVDoWorkEventArgs@ComponentModel@4@@Z)
1>..{omitted}..\MyApplication.exe : fatal error LNK1120: 4 unresolved externals
无论我将 CDocument 实例放在何处,都会出现此错误。
我能做些什么来纠正这个问题? VS 似乎认为包含很好,而且当我放入 CDocument d 时更是如此;它会亮起,表明它可以识别 CDocument 类型。
【问题讨论】:
-
那不是编译错误,而是链接错误。您可能需要在 Visual Studio 项目中包含该 gumbo-parser 中的所有类,以便这些类将被编译并可以在链接期间使用。
-
你的意思是我需要在我的项目中包含更多的 .h 文件吗?我注意到我已经在他们自己的代码中包含的两个 .h 文件似乎包含了所有其他必需的文件。
-
在 Visual Studio 的项目工作区中并不真正包含,而是添加这些文件,包括 .h 和 .cpp。这样它就会被编译。
-
我可以尝试一下,尽管考虑到我目前的方法适用于 Boost 库,这似乎很奇怪。我注意到这个库的所有文件都在解决方案资源管理器的 External Dependencies 文件夹下正确找到。
-
我也在 VS2010 中编译该库。您是否已经将gumbo C编译为您现在要编译的那个,我只是一个warppe
标签: c++ compiler-errors unresolved-external