Configuring the library for inclusion in C ++ - test

I would like to use the UnitTest ++ library in the test file. However, it is difficult for me to bring down the library at compile time. So here is my current directory structure:

tests/
  UnitTests++/
    libUnitTest++.a
    src/
      UnitTests++.h
  unit/
    test.cpp

I just used UnitTest ++ start to just get the library setup. Here is test.cpp:

// test.cpp
#include <UnitTest++.h>

TEST(FailSpectacularly)
{
 CHECK(false);
}

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

And currently I'm trying to compile with:

gcc -lUnitTest++ -L../UnitTest++/ -I../UnitTest++/src/ test.cpp

I am currently getting output with ld: symbol(s) not foundat the end. So, how could I properly include the UnitTest ++ library when it is compiled? I am on a Mac, and I would also like there to be an easy way for people on a Linux machine to run the same tests.

Hope this will provide enough information if you don't tell me.

+3
4

gcc -L../UnitTest++/ -I../UnitTest++/src/ test.cpp -lUnitTest++ -lstdc++

g++ -L../UnitTest++/ -I../UnitTest++/src/ test.cpp -lUnitTest++

libstd++.


GCC :

-llibrary

-l

library . ( ​​ POSIX .)

, ; , .

, foo.o -lz bar.o' searches library z ' foo.o, bar.o. bar.o `z ', .

, , -lUnitTest ++, test.cpp

+1

test.cpp, test.o

g++ test.o libUnitTest ++. a -o./exectest

. /exectest

libUnitTest ++. a - UnitTest ++. ( + libUnitTest ++. A)

make , unittest ++,

+1

ld: symbol(s) not found , . UnitTest ++, .

MAC, Linux :

./configure
make
make install

UnitTest ++ :

make install

Then you will have UnitTest ++. so the library is in the library folder of your OS. Now the library can be linked to your program with the -lUnitTest ++ command.

0
source

Usually you need to put -Lsomething before it is required.

0
source

Source: https://habr.com/ru/post/1739073/


All Articles