简体   繁体   中英

First CppUnit Test: undefined reference to CppUnit::SourceLine::SourceLine

I am trying to use the CppUnit test for the first time. When I try to compile the testing code I get:

testing.cpp:(.text+0xca): undefined reference to `CppUnit::SourceLine::SourceLine(std::basic_string, std::allocator > const&, int)'

And many other error messages.

I guess that the reason is that compiler does not know what UnitTest library is. Here I found a person asking the same question. I try to use the recommendation from the answers of the linked questions but it still does not work. When I try c++ -lunittest++ testing.cpp I get:

/usr/bin/ld: cannot find -lunittest++
collect2: ld gives back 1 as End-Status

In the make files that are used by others and that work I see: LDLIBS := -lcppunit . So I tried c++ -lcppunit++ testing.cpp but I get the same error message as with the -lunittest .

Does anybody know how I can find location of the UnitTest library and pass this information to the compiler?

这就是我设法编译代码的方式:

g++ testing.cpp -lcppunit

I am compiling in netbeans. I added the option -lcppunit in

Properties > Linker > Additional Options

and that let my test files compile and run. Remember to not leave any spaces between options, as that will cause your code to fail to compile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM