Ask Your Question
0

Cannot build a package

asked 2018-07-17 22:01:38 -0500

jitsunen gravatar image

updated 2018-07-17 23:16:15 -0500

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 ...
(more)
edit retag flag offensive close merge delete

Comments

Using compile options via CMakeLists.txt worked for me add_compile_options(-pthread)

Mikhail K. gravatar image Mikhail K.  ( 2018-07-18 03:48:10 -0500 )edit

Thanks for answering, Mikhail. I tried adding add_compile_options(-pthread) to the package's CMakeLists.txt, unfortunately, the error still persists.

jitsunen gravatar image jitsunen  ( 2018-07-18 22:13:07 -0500 )edit

as I see from the log /home/parth/anaconda3/bin/cc is your compiler, although simple gcc should be used instead

Mikhail K. gravatar image Mikhail K.  ( 2018-07-19 02:30:35 -0500 )edit

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.

jitsunen gravatar image jitsunen  ( 2018-07-20 23:00:19 -0500 )edit

You can even try export CC=/usr/bin/gcc and export CXX=/usr/bin/g++ before compiling on the old machine

Mikhail K. gravatar image Mikhail K.  ( 2018-07-21 01:49:13 -0500 )edit

Excuse me, how should I do this step?

You can even try export CC=/usr/bin/gcc and export CXX=/usr/bin/g++ before compiling on the old machine
luna wu gravatar image luna wu  ( 2021-12-08 20:51:41 -0500 )edit

@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. gravatar image Mikhail K.  ( 2021-12-08 21:00:03 -0500 )edit

@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?

wjh@wjh:~$ export CC=/usr/bin/gcc
wjh@wjh:~$ export CXX=/usr/bin/g++

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...

luna wu gravatar image luna wu  ( 2021-12-08 21:13:06 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-03-10 02:21:24 -0500

Charing Lau gravatar image

Edit the CMakeLists.txt, remove roscpp and change the line "find_package(catkin COMPONENTS roscpp xxx xxx)" to "find_package(catkin COMPONENTS xxx xxx)", then add roscpp when link_libraries like this: target_link_libraries(${project} roscpp ${catkin_LIBRARIES}) :-)

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-07-17 22:01:38 -0500

Seen: 1,442 times

Last updated: Mar 10 '20