Robotics StackExchange | Archived questions

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

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /data/ros/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_ef001/fast"
/usr/bin/make -f CMakeFiles/cmTC_ef001.dir/build.make CMakeFiles/cmTC_ef001.dir/build
make[1]: Entering directory '/data/ros/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ef001.dir/CheckFunctionExists.c.o
/home/parth/anaconda3/bin/cc    -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_ef001.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.5/Modules/CheckFunctionExists.c
Linking C executable cmTC_ef001
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_ef001.dir/link.txt --verbose=1
/home/parth/anaconda3/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_ef001.dir/CheckFunctionExists.c.o  -o cmTC_ef001 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_ef001.dir/build.make:97: recipe for target 'cmTC_ef001' failed
make[1]: *** [cmTC_ef001] Error 1
make[1]: Leaving directory '/data/ros/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_ef001/fast' failed
make: *** [cmTC_ef001/fast] Error 2

Asked by jitsunen on 2018-07-17 22:01:38 UTC

Comments

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

Asked by Mikhail K. on 2018-07-18 03:48:10 UTC

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

Asked by jitsunen on 2018-07-18 22:13:07 UTC

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

Asked by Mikhail K. on 2018-07-19 02:30:35 UTC

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.

Asked by jitsunen on 2018-07-20 23:00:19 UTC

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

Asked by Mikhail K. on 2018-07-21 01:49:13 UTC

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

Asked by luna wu on 2021-12-08 21:51:41 UTC

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

Asked by Mikhail K. on 2021-12-08 22:00:03 UTC

@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/392435/project-davis_ros_driver-tried-to-find-library-pthread-the-library-is-neither-a-target-nor-builtinstalled-properly/

Asked by luna wu on 2021-12-08 22:13:06 UTC

@luna-wu exactly, these are just variables you set prior to the compilation, they should not output anything. However, I think your problem is more related to the upvoted answer

Asked by Mikhail K. on 2021-12-08 22:16:06 UTC

@Mikhail K. Thanks again.Here is my CMakeLists.tst. I didn't find any information about find_package(catkin COMPONENTS roscpp xxx xxx) Therefore, I don’t know how to change my CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(davis_ros_driver)

find_package(catkin_simple REQUIRED)

set(libcaer_DIR "/usr/lib/x86_64-linux-gnu/cmake/libcaer/")
find_package(libcaer REQUIRED)

catkin_simple()

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")

find_package(Boost REQUIRED COMPONENTS system thread)

# make the executable
cs_add_executable(davis_ros_driver
  src/driver_node.cpp
  src/driver.cpp
)

# make the nodelet into a library
cs_add_library(davis_ros_driver_nodelet
  src/driver_nodelet.cpp
  src/driver.cpp
)

# link the executable to the necesarry libs
target_link_libraries(davis_ros_driver
  ${catkin_LIBRARIES}
  ${Boost_LIBRARIES}
  libcaer::c
)

# Install the nodelet library
cs_install()

# Install other support files for installation
install(FILES davis_ros_driver_nodelet.xml
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

# Export package
cs_export()

Asked by luna wu on 2021-12-08 22:32:13 UTC

Answers

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}) :-)

Asked by Charing Lau on 2020-03-10 02:19:45 UTC

Comments