Cannot build a package
I did the following steps and got error 'tried to find library pthread...'. I am using ros lunar and trying to build a package.
Thanks for your help!.
$ cd /data/ros/src
$ catkin_create_pkg ch2_tut std_msgs roscpp
$ cd /data/ros
$ catkin build
----------------------------------------------
Profile: default
Extending: [env] /opt/ros/lunar
Workspace: /data/ros
----------------------------------------------
Source Space: [exists] /data/ros/src
Log Space: [exists] /data/ros/logs
Build Space: [exists] /data/ros/build
Devel Space: [exists] /data/ros/devel
Install Space: [unused] /data/ros/install
DESTDIR: [unused] None
----------------------------------------------
Devel Space Layout: linked
Install Space Layout: None
----------------------------------------------
Additional CMake Args: None
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False
----------------------------------------------
Whitelisted Packages: None
Blacklisted Packages: None
----------------------------------------------
Workspace configuration appears valid.
----------------------------------------------
[build] Found '1' packages in 0.0 seconds.
[build] Updating package table.
Warning: generated devel space setup files have been deleted.
Starting >>> catkin_tools_prebuild
Finished <<< catkin_tools_prebuild [ 2.4 seconds ]
Starting >>> ch2_tut
_____________________________________________________________________________________________
**Errors << ch2_tut:cmake /data/ros/logs/ch2_tut/build.cmake.000.log
CMake Error at /opt/ros/lunar/share/roscpp/cmake/roscppConfig.cmake:148 (message):
Project 'ch2_tut' tried to find library 'pthread'. The library is neither
a target nor built/installed properly. Did you compile project 'roscpp'?
Did you find_package() it before the subdirectory containing its code is
included?**
Call Stack (most recent call first):
/opt/ros/lunar/share/catkin/cmake/catkinConfig.cmake:76 (find_package)
CMakeLists.txt:10 (find_package)
cd /data/ros/build/ch2_tut; catkin build --get-env ch2_tut | catkin env -si /usr/bin/cmake /data/ros/src/ch2_tut --no-warn-unused-cli -DCATKIN_DEVEL_PREFIX=/data/ros/devel/.private/ch2_tut -DCMAKE_INSTALL_PREFIX=/data/ros/install; cd -
.............................................................................................
Failed << ch2_tut:cmake [ Exited with code 1 ]
Failed <<< ch2_tut [ 2.3 seconds ]
[build] Summary: 1 of 2 packages succeeded.
[build] Ignored: None.
[build] Warnings: None.
[build] Abandoned: None.
[build] Failed: 1 packages failed.
[build] Runtime: 4.7 seconds total.
[build] Note: Workspace packages have changed, please re-source setup files to use them.
Output from CMakeError.log file:
Determining if the pthread_create exist failed with the following output:
Change Dir: /data/ros/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_1a580/fast"
/usr/bin/make -f CMakeFiles/cmTC_1a580.dir/build.make CMakeFiles/cmTC_1a580.dir/build
make[1]: Entering directory '/data/ros/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_1a580.dir/CheckSymbolExists.c.o
/home/parth/anaconda3/bin/cc -o CMakeFiles/cmTC_1a580.dir/CheckSymbolExists.c.o -c /data/ros/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_1a580
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1a580.dir/link.txt --verbose=1
/home/parth/anaconda3/bin/cc CMakeFiles/cmTC_1a580.dir/CheckSymbolExists.c.o -o cmTC_1a580 -rdynamic
**CMakeFiles/cmTC_1a580.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_1a580.dir/build.make:97: recipe for target 'cmTC_1a580' failed
make[1]: *** [cmTC_1a580] Error 1
make[1]: Leaving directory '/data/ros/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_1a580/fast' failed
make: *** [cmTC_1a580/fast] Error 2**
File /data/ros/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
**#include <pthread.h ...
Using compile options via CMakeLists.txt worked for me
add_compile_options(-pthread)
Thanks for answering, Mikhail. I tried adding add_compile_options(-pthread) to the package's CMakeLists.txt, unfortunately, the error still persists.
as I see from the log /home/parth/anaconda3/bin/cc is your compiler, although simple gcc should be used instead
Thanks Mikhail!.
I just switched to a new laptop with Ubuntu 18.04 (bionic), installed ROS Melodic and tried the above steps, they worked like a charm.
Thanks again for your prompt responses.
You can even try
export CC=/usr/bin/gcc
andexport CXX=/usr/bin/g++
before compiling on the old machineExcuse me, how should I do this step?
@luna these are the environment variables pointing at the current C and C++ compiler accordingly. You type them right into the terminal, with which you are going to compile your package, in order to correct automatically detected compiler paths.
@Mikhail K. Thank you very much for your prompt reply. I have entered them into the terminal, but nothing was reflected. Am I doing this right?
I am a student who just studied ubuntu, and I also encountered this problem with the blogger. Any of your suggestions will help me. Thanks
https://answers.ros.org/question/3924...