CMakeList.txts: transfer from cmake to catkin_make
Hi,
I'm trying to transfer the opentld program into ROS package.
What I'm trying now is
- init a catkin package
- copy the content of opentld into
src
folder of catkin package - copy the folder 3rdparty and libopentld into
include
folder of catkin package - modify the
CMakeLists.txt
file in catkin package according to theCMakeLists.txt
of TLD program
4.1. add the include_directories
4.2. add the add_library
4.3 add the if(BUILD_QOPENTLD)
Then I use catkin_make and no library or file missing is reported, but there are many errors about undefined reference when linking.
####
#### Running command: "make cmake_check_build_system" in "/home/aqua/catkin/build"
####
####
#### Running command: "make -j4 -l4" in "/home/aqua/catkin/build"
####
Linking CXX executable /home/aqua/catkin/devel/lib/tld/tld_node
Linking CXX shared library /home/aqua/catkin/devel/lib/libsrc/main.so
/usr/bin/ld: cannot open output file /home/aqua/catkin/devel/lib/libsrc/main.so: No such file or directory
collect2: ld returned 1 exit status
make[2]: *** [/home/aqua/catkin/devel/lib/libsrc/main.so] Error 1
make[1]: *** [tld/CMakeFiles/src/main.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
CMakeFiles/tld_node.dir/src/main/Main.cpp.o: In function `Main::doWork()':
Main.cpp:(.text+0x29): undefined reference to `tld::Trajectory::Trajectory()'
Main.cpp:(.text+0x3a): undefined reference to `imAcqGetImg(ImAcq*)'
Main.cpp:(.text+0x88): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
...
can anyone give me some idea what to do next?
Thanks.
=================
Thanks @ahendrix for helping me with the link problem. I should add the target_link_libraries
command.
But now it becomes:
[ 85%] Building CXX object tld/CMakeFiles/tld.dir/src/main/Trajectory.cpp.o
Linking CXX shared library /home/aqua/catkin/devel/lib/libtld.so
/usr/bin/ld: cannot find -llibopentld
/usr/bin/ld: cannot find -lcvblobs
I don't think I need to build the share library in the /usr/lib
since the original doesn't do that. It should also be a makefile problem.
The original is: includedirectories(main ../libopentld/imacq ../libopentld/mftracker ../libopentld/tld ../3rdparty/cvblobs ${OpenCVINCLUDE_DIRS})
add_library(main
main/Config.cpp
main/Gui.cpp
main/Main.cpp
what I did:
include_directories(tld
include/libopentld/imacq
include/libopentld/mftracker
include/libopentld/tld
include/3rdparty/cvblobs
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS})
add_library(tld
src/main/Config.cpp
src/main/Gui.cpp
src/main/Main.cpp
src/main/Settings.cpp
what the original is:
target_link_libraries(main libopentld cvblobs config++ ${OpenCV_LIBS})
add_executable(opentld
OpenTLD.cpp)
target_link_libraries(opentld main libopentld cvblobs config++ ${OpenCV_LIBS})
what I did:
targetlinklibraries(tld libopentld cvblobs config++ ${OpenCVLIBS} ${catkinLIBRARIES})
add_executable(opentld
src/OpenTLD.cpp)
target_link_libraries(opentld tld libopentld cvblobs config++ ${OpenCV_LIBS})
I believe there should be some issues here but I tried some code change but still get the error.
Asked by lanyusea on 2014-08-04 21:33:55 UTC
Answers
I think you should read through the existing cmake files again. Note that there are source files and cmake files in the 3rdparty and libopentld folders, and that they were originally included from the top-level cmake file.
I suspect the issues you're having are mostly because you aren't building the 3rdparty and opentld libraries the same way that the original project did.
Asked by ahendrix on 2014-08-05 01:37:20 UTC
Comments
and is there any possibility to make it as a ROS node although I cannot put it inside my catkin workspace?
Asked by lanyusea on 2014-08-05 02:44:43 UTC
catkin IS cmake. You should be able to re-use most of the existing package structure and build system as a catkin package.
Asked by ahendrix on 2014-08-05 11:01:59 UTC
@ahendrix is right. You have to build these libraries within your package.
See the openTLD CMakeList files here and here.
Add the add_library
commands to your CMakeLists.txt or use sub CMakeLists.txt in this case you may even be able to simply copy the original CMakeLists.txts.
There the original openTLD project builds them.
Asked by BennyRe on 2014-08-05 02:32:49 UTC
Comments
thanks. I compiled the original project directly and got the library file cvblobs.a and libopentld.a; I copied them to /usr/lib directly (not sure if I can do this), then the cvblobs.a is found but there is still /usr/bin/ld: cannot find -llibopentld I will try more then give up, if still failed
Asked by lanyusea on 2014-08-05 02:48:05 UTC
Don't compile anything by hand and place it in /usr/lib. Build these libraries in your project. See my updated answer.
Asked by BennyRe on 2014-08-05 02:52:35 UTC
there is the add_library as what the original project does and I correct the path. and I think I need to use include_directories in order to specify the additional locations of header files
Asked by lanyusea on 2014-08-05 03:09:08 UTC
Comments
The cmake
target_link_libraries
command performs linking.Asked by ahendrix on 2014-08-04 21:39:01 UTC
Just for information, OpenTLD is old and the team now recommends CMT instead, http://www.gnebehay.com/cmt/ it is implemented in Python for now and integrating it in ROS goes straight-forward.
Asked by Mehdi. on 2014-08-04 21:55:22 UTC
@ahendrix thanks! you are always awesome! now it shows
/usr/bin/ld: cannot find -llibopentld /usr/bin/ld: cannot find -lcvblobs
but I already add the path of libopentld and cvblobs intoinclude_directories
and they are not .so file so I cannot copy them into/usr/lib
any suggestion?Asked by lanyusea on 2014-08-04 21:56:51 UTC
thanks @mehdi, I tested both of them and think the TLD performs better and run faster than the CMT. maybe that is the problem caused by the difference of c and python
Asked by lanyusea on 2014-08-04 21:58:21 UTC
Do you build these two libraries? Side note: Copying anything by hand to /usr/lib should never be your first solution.
Asked by BennyRe on 2014-08-04 23:45:58 UTC
@BennyRe I updated the question. I don't think I need to build that two libraries individually, they should be build when I make the package I think.
Asked by lanyusea on 2014-08-05 00:44:50 UTC
update: the owner of this ROS repo has catkinized this package. https://github.com/Ronan0912/ros_opentld
Asked by lanyusea on 2014-08-10 21:47:22 UTC