c ++整理链接器错误

时间:2014-11-25 21:13:35

标签: c++ tidy

我是c ++的新手,我遇到以下问题:

文件:   - main.cpp   - utils.h   - utils.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:在函数_start': (.text+0x18): undefined reference to main'   utils.o:在函数clean_html(std::string const&)': utils.cpp:(.text+0xfa): undefined reference to tidyCreate'   utils.cpp :(。text + 0x118):未定义引用tidyOptSetBool' utils.cpp:(.text+0x13b): undefined reference to tidyOptSetBool'   utils.cpp :(。text + 0x15e):未定义引用tidyOptSetBool' utils.cpp:(.text+0x181): undefined reference to tidyOptSetBool'   utils.cpp :(。text + 0x1a4):未定义引用tidyOptSetBool' utils.cpp:(.text+0x1c7): undefined reference to tidyOptSetValue'   utils.cpp :(。text + 0x1ea):未定义引用tidyOptSetValue' utils.cpp:(.text+0x209): undefined reference to tidyOptSetBool'   utils.cpp :(。text + 0x228):未定义引用tidyOptSetBool' utils.cpp:(.text+0x247): undefined reference to tidyOptSetInt'   utils.cpp :(。text + 0x281):未定义引用tidyParseString' utils.cpp:(.text+0x295): undefined reference to tidyCleanAndRepair'   utils.cpp :(。text + 0x2b0):未定义引用tidySaveBuffer' utils.cpp:(.text+0x322): undefined reference to tidyBufFree'   utils.cpp :(。text + 0x32d):未定义引用`tidyRelease'   collect2:错误:ld返回1退出状态

在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     #include

tidy.h位于/usr/include/tidy.h

1 个答案:

答案 0 :(得分:4)

您需要在链接命令中添加-ltidy