main.cpp.obj : error LNK2019: 无法解析的外部符号 "public: class tree > > const & __cdecl htmlcxx::HTML::ParserDom::parseTree(class std::basic_string,class std::allocator > const &)" (?parseTree@ParserDom@HTML@htmlcxx@@QEAAAEBV?$tree@VNode@HTML@htmlcxx@@V?$allocator@V?$tree_node_@VNode@HTML@htmlcxx@@@@@std@@@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z),函数 main 中引用了该符号
main.cpp.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl htmlcxx::HTML::ParserDom::beginParsing(void)" (?beginParsing@ParserDom@HTML@htmlcxx@@MEAAXXZ)
main.cpp.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl htmlcxx::HTML::ParserDom::foundTag(class htmlcxx::HTML::Node,bool)" (?foundTag@ParserDom@HTML@htmlcxx@@MEAAXVNode@23@_N@Z)
main.cpp.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl htmlcxx::HTML::ParserDom::foundText(class htmlcxx::HTML::Node)" (?foundText@ParserDom@HTML@htmlcxx@@MEAAXVNode@23@@Z)
main.cpp.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl htmlcxx::HTML::ParserDom::foundComment(class htmlcxx::HTML::Node)" (?foundComment@ParserDom@HTML@htmlcxx@@MEAAXVNode@23@@Z)
main.cpp.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl htmlcxx::HTML::ParserDom::endParsing(void)" (?endParsing@ParserDom@HTML@htmlcxx@@MEAAXXZ)
main.cpp.obj : error LNK2019: 无法解析的外部符号 "class std::basic_ostream > & __cdecl htmlcxx::HTML::operator<<(class std::basic_ostream > &,class tree > > const &)" (??6HTML@htmlcxx@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV23@AEBV?$tree@VNode@HTML@htmlcxx@@V?$allocator@V?$tree_node_@VNode@HTML@htmlcxx@@@@@std@@@@@Z),函数 main 中引用了该符号
D:\testHTML\firset\third_party\htmlcxx\lib\htmlcxx.lib : warning LNK4272:库计算机类型“x86”与目标计算机类型“x64”冲突
firset.exe : fatal error LNK1120: 7 个无法解析的外部命令
ninja: build stopped: subcommand failed.
20:34:43: 进程"D:\qt\Tools\CMake_64\bin\cmake.exe"退出,退出代码 1 。
该回答引用于gpt与OKX安生共同编写:
你提到的错误信息中包含了以下内容:
这些错误都是链接器(linker)在生成可执行文件时遇到的问题。其中,LNK2019 和 LNK2001 错误表示链接器无法找到某些函数或变量的定义;LNK1120 错误则表示存在未解决的符号引用。
根据你提供的错误信息,可以看出该程序使用了 htmlcxx 库,并且链接器无法找到该库的相关符号。根据警告信息提示,可能是因为你使用了 64 位系统,而预编译库却是 32 位的。因此,你需要下载适合 64 位系统的 htmlcxx 库,并在项目中正确配置库文件的路径和链接选项。
你可以尝试下载并使用以下预编译版本的 htmlcxx 库(已针对 64 位系统进行编译):
解压后,将 libhtmlcxx.a 或 libhtmlcxx.lib 文件复制到你的项目目录下(例如,放在 third_party\htmlcxx\lib 目录下),并在 CMakeLists.txt 中添加以下代码,以链接 htmlcxx 库:
# 设置 htmlcxx 库的路径
set(HTMLCXX_LIB_PATH "${CMAKE_SOURCE_DIR}/third_party/htmlcxx/lib")
# 设置链接选项
if (WIN32)
set(HTMLCXX_LINK_OPTIONS "-llibhtmlcxx")
else ()
set(HTMLCXX_LINK_OPTIONS "-lhtmlcxx")
endif ()
# 添加可执行文件
add_executable(firset main.cpp)
# 链接 htmlcxx 库
target_link_libraries(firset ${HTMLCXX_LINK_OPTIONS} ${HTMLCXX_LIB_PATH})
这里假设 libhtmlcxx.a 或 libhtmlcxx.lib 文件被放置在了 third_party\htmlcxx\lib 目录下,并且库文件的名字为 libhtmlcxx。如果你的库文件名称不同,需要相应地修改链接选项。
希望这些信息能够帮助你解决问题。
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
根据错误提示,这是一个链接错误,可能是由于缺少依赖库或库与目标计算机不兼容造成的。
你需要确认你的HTMLCXX库是正确的,并且是64位版本。如果你使用的是32位版本,则需要使用64位版本重新编译库。
同时,你也需要确认你的项目是64位版本,如果你的项目是32位版本,则需要将项目设置为64位版本,并重新编译项目。
另外,需要确保在Linker选项中添加了HTMLCXX库路径,并在Linker选项中添加HTMLCXX库。
下面是一些可能有用的代码示例,用于将HTMLCXX库添加到CMakeLists.txt文件中:
find_library(HTMLCXX_LIB htmlcxx PATHS /path/to/htmlcxx/lib)
target_link_libraries(yourtarget ${HTMLCXX_LIB})
其中,/path/to/htmlcxx/lib
为HTMLCXX库的路径,yourtarget
是你的目标名称。
希望这能帮到你解决问题。
如果我的回答解决了您的问题,请采纳!
参考GPT和自己的思路:根据您提供的信息,问题似乎出现在链接器无法找到所需的函数和类的定义。由于出现库计算机类型与目标计算机类型不匹配的警告,我推测您可能是在将32位的预编译库用于64位平台上。您需要使用64位预编译库来解决这个问题。如果您真的需要使用32位的预编译库,您需要在编译器选项中指定目标CPU架构为32位。另外,请确保您的库文件与您的编译器版本兼容。