我是 c++ 新手,遇到以下问题:
文件: - main.cpp -utils.h - 实用程序.cpp
当我在做的时候:
g++ -c -std=c++11 utils.cpp(编译) g++ -c -std=c++11 main.cpp(编译)
当我尝试链接时:
g++ -o main.o utils.o
/usr/lib/gcc/i686-redhat-linux/4.8.3/../../../crt1.o: In function
_start': (.text+0x18): undefined reference to
main' utils.o: In functionclean_html(std::string const&)': utils.cpp:(.text+0xfa): undefined reference to
tidyCreate' utils.cpp:(.text+0x118): undefined reference totidyOptSetBool' utils.cpp:(.text+0x13b): undefined reference to
tidyOptSetBool' utils.cpp:(.text+0x15e): undefined reference totidyOptSetBool' utils.cpp:(.text+0x181): undefined reference to
tidyOptSetBool' utils.cpp:(.text+0x1a4): undefined reference totidyOptSetBool' utils.cpp:(.text+0x1c7): undefined reference to
tidyOptSetValue' utils.cpp:(.text+0x1ea): undefined reference totidyOptSetValue' utils.cpp:(.text+0x209): undefined reference to
tidyOptSetBool' utils.cpp:(.text+0x228): undefined reference totidyOptSetBool' utils.cpp:(.text+0x247): undefined reference to
tidyOptSetInt' utils.cpp:(.text+0x281): undefined reference totidyParseString' utils.cpp:(.text+0x295): undefined reference to
tidyCleanAndRepair' utils.cpp:(.text+0x2b0): undefined reference totidySaveBuffer' utils.cpp:(.text+0x322): undefined reference to
tidyBufFree' utils.cpp:(.text+0x32d): undefined reference to `tidyRelease' collect2: error: ld returned 1 exit status
在 utils.cpp 中我有一个函数 clean_html。当我删除此功能时,代码会成功链接。
我使用的是 gcc 版本 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC)。
Tidy 是通过 fedora repos 安装的,使用: 软件包 libtidy-devel-0.99.0-28.20091203.fc19.i686 已经安装并且是最新版本 软件包 libtidy-0.99.0-28.20091203.fc19.i686 已经安装并且是最新版本
编辑:
忘了说: - 我包括 tidy.h 使用 #包括
tidy.h 位于/usr/include/tidy.h
最佳答案
您需要将 -ltidy
添加到您的链接命令。
关于C++ 整洁链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27136772/