Ask Your Question
0

Linker error trying to build and run unit tests

asked 2014-08-21 16:15:32 -0500

Kurt gravatar image

updated 2014-08-21 16:37:25 -0500

I am getting an error from the linker when I attempt to run catkin_make run_tests_my_package`

The error I get is: /usr/bin/ld: cannot find -lmy_package collect2: error: ld returned 1 exit status

Under testing in my CMakelist.txt I have the following: catkin_add_gtest(${PROJECT_NAME}-test test/utest.cpp) if(TARGET ${PROJECT_NAME}-test) target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) endif()

include_directories(include ${catkin_INCLUDE_DIRS})

Am I missing something? do I need to use add_executable in my CMakelist.txt?

Another thing to mention is my workspace layout, it's arranged as follows: my_package/ bin/ build/ src/ my_class.h my_class.cpp test/ utest.cpp world/ CMakelist.txt

and inside utext.cpp I am referencing my_class.h list this #include "my_package/my_class.h

Full CMakelist.txt

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-08-21 16:22:01 -0500

ahendrix gravatar image

updated 2014-08-21 16:31:55 -0500

The linker is complaining that my_package is not a library. Do you create a library named my_package in your CMakeLists.txt? (Including your FULL CMakeLists.txt would be useful here).

edit flag offensive delete link more

Comments

Yeah, I'm not actually including a cpp, was just a typo. I don't think I am creating a library called my_package in my CMakelist.txt. Here is the full CMakelist.txt

Kurt gravatar image Kurt  ( 2014-08-21 16:34:43 -0500 )edit

Wow... there's some unusual bits in there. If you're trying to write a test which tests the ActorLibrary, you should probably be linking it against the ActorLibrary in the same way that you link your primary executable.

ahendrix gravatar image ahendrix  ( 2014-08-21 16:46:08 -0500 )edit

Cool that seems to have worked, I've managed to build and the the tests by modifying the target_link_libraries to this target_link_libraries(${PROJECT_NAME}-test ActorLibrary ${catkin_LIBRARIES})

Kurt gravatar image Kurt  ( 2014-08-21 17:11:27 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-08-21 16:15:32 -0500

Seen: 296 times

Last updated: Aug 21 '14