Linux上Codelite,Unittest ++和G ++的链接器错误 [英] Linker errors with codelite, unittest++ and g++ on linux

查看:107
本文介绍了Linux上Codelite,Unittest ++和G ++的链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用c ++进行单元测试,并在Linux(Mint)上编写c ++.我正在使用CodeLite作为我的IDE.我在stackoverflow上找到了有关链接器错误的几个答案,但是经过数小时的尝试各种解决方案后,我仍未成功实现正确的解决方案.

I'm new to unit testing in c++, and writing c++ on Linux (Mint). I'm using CodeLite as my IDE. I have found several answers on stackoverflow about linker errors, but after hours of trying various solutions I have not succeeded in implementing a solution correctly.

我通过apt-get安装了unittest ++. unittest ++头文件安装在/usr/include中,因此我将其添加到Codelite的Compiler链接器选项中(右键单击项目名称-> Settings,Compiler): Codelite屏幕截图

I installed unittest++ through apt-get. The unittest++ header files were installed in /usr/include, so I added this to the Compiler linker options in Codelite (Right click project name->Settings, Compiler): Codelite screenshot

然后我有一个非常简单的程序,它完全由一个main.cpp文件组成:

I then have a very simple program, which consists entirely of one main.cpp file:

#include <unittest++/UnitTest++.h>
//See if unit tests are working
TEST(MyMath) {
    CHECK(false);
}

int main()
{
    UnitTest::RunAllTests();
    return 0;
}

此时运行项目会生成其他用户遇到的链接器错误流,例如:

Running the project at this point generates a stream of linker errors other users have experienced, for example:

main.cpp:4:对UnitTest::CurrentTest::Details()

main.cpp:4: undefined reference to UnitTest::CurrentTest::Details()

在这一点上,我的理解是,我现在需要告诉g ++编译器有关目标文件的信息,并将它们链接到unittest ++文件.这就是我被困住的地方.我看到的唯一.o文件位于 Debug/main.cpp.o 中,并运行命令
g ++ main.cpp -o main.cpp.o -Lunittest ++ 以及带有I和o标志的变体,但它们都返回与我在尝试编译时遇到的相同的链接器错误.我还尝试过复制论坛中的每条g ++行,但只会遇到各种错误.

At this point, my understanding is that I now need to tell the g++ compiler about the object files and link them to the unittest++ files. And this is where I'm stuck. The only .o file I see is in Debug/main.cpp.o and running the command
g++ main.cpp -o main.cpp.o -Lunittest++ as well as variations with the I and o flags, but all of them return the same linker errors I get when I try to compile. I've also tried to copy every g++ line in the forums and only get various errors.

我试图在g ++手册页中找到解决方案,阅读了我一直在使用的标志,但没有推断出解决方案.然后,我很快就被男人条目中的大量页面埋没了. CodeLite和unittest ++的文档似乎已经过时了,所以作为最后的选择,我在这里发布了stackoverflow.

I've tried to find a solution in the g++ man pages, read about the flags I've been using and did not infer a solution. I then quickly got buried in quantity of pages in the man entry. The documentation for CodeLite and unittest++ seems woefully out of date, so I posted here on stackoverflow as a last resort.

我可以肯定我只是在犯一个菜鸟错误.如果有人收到反馈,我将不胜感激.

I'm fairly certain I'm just making a rookie mistake. If someone has feedback, I'd be grateful.

推荐答案

在您的解释中,您尝试手动与g++ -c main.cpp -o main.cpp.o -Lunittest++链接,但是-L选项提供了用于搜索库的其他目录的路径.您可能希望-lunittest++与unittest ++库链接.该库应提供您在未定义的引用"错误中看到的符号.

In your explanation, you try to link manually with g++ -c main.cpp -o main.cpp.o -Lunittest++ , but the -L option gives the path to additional directories to search for libraries. You probably want -lunittest++ to link with the unittest++ library. That library should provide the symbols you see in the "undefined reference" errors.

请注意,"/usr/include"应位于默认搜索路径中,无需显式添加它.

As a side note, "/usr/include" should be in the default search path and there's no need to add it explicitly.

这篇关于Linux上Codelite,Unittest ++和G ++的链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆