ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

relocation R_X86_64_PC32 against symbol `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC

asked 2021-03-17 04:41:55 -0500

kak13 gravatar image

updated 2021-07-27 10:50:41 -0500

I've done this steps like 7 times. I re-install foxy like 7 times too. I fail to see why it's not working now, it was working another day. This colcon build error drives me crazy

I was following this tutorial: https://emanual.robotis.com/docs/en/p...

I'm on foxy version

bwuk@robot:~/turtlebot3_ws/src$  rosversion -d
foxy

python:

/usr/bin/python

I was able to following until colcon build --symlink -install under 1.1.4 install turtbot3 package

*bwuk@robot:~/turtlebot3_ws/src$ colcon build --symlink-install
Starting >>> turtlebot3_msgs
Starting >>> turtlebot3_description
Starting >>> turtlebot3_cartographer
Starting >>> turtlebot3_navigation2
Starting >>> turtlebot3_teleop
Finished <<< turtlebot3_description [0.60s] 
Finished <<< turtlebot3_cartographer [0.63s]
Finished <<< turtlebot3_navigation2 [0.62s]
--- stderr: turtlebot3_msgs 

/usr/bin/ld: /usr/local/lib/libpython3.9.a(abstract.o): relocation R_X86_64_PC32 against symbol `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC

/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/turtlebot3_msgs__python.dir/build.make:193: rosidl_generator_py/turtlebot3_msgs/libturtlebot3_msgs__python.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:240: CMakeFiles/turtlebot3_msgs__python.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

---

Failed <<< turtlebot3_msgs [0.72s, exited with code 2]
Aborted <<< turtlebot3_teleop [0.77s] 
Summary: 3 packages finished [1.14s]
 1 package failed: turtlebot3_msgs
 1 package aborted: turtlebot3_teleop
 1 package had stderr output: turtlebot3_msgs
 4 packages not processed*

What am I missing here? It was working very well last week. How did it happen?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-07-27 12:07:50 -0500

kak13 gravatar image

This is old. The issue was that I kept download the different version of ROS2.

Select the correct ROS2 version would solve the issue. Please feel free to comment here if you have similar issue as this and we will troubleshoot this together.

Closing this now

edit flag offensive delete link more

Comments

1

Similar problem here, the error I kept getting: /usr/bin/ld: /usr/local/lib/libpython3.7m.a(call.o): relocation R_X86_64_PC32 against symbol `_PyRuntime' can not be used when making a shared object; recompile with -fPIC

The '.a' at the end of the problem file means the linker's trying to compile against something that's not a shared object ('.so') file. This likely means the linker's looking in the wrong directory.

What fixed this for me (run in workspace): colcon build --packages-select tutorial_interfaces --cmake-clean-cache --cmake-clean-first --cmake-force-configure --ament-cmake-args -DCMAKE_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/"

NOTE: your library path (CMAKE_LIBRARY_PATH) may need to point someplace else, look for the .so version of the problem file (eg: libpython3.7m.a is the issue, so find libpython3.7m.so on your system, install libpython37-dev or similar if needed). ALSO: make sure you've sourced your setup.bash file first!

ecentri_adam gravatar image ecentri_adam  ( 2021-09-03 07:30:04 -0500 )edit
1

answered 2022-08-27 19:05:16 -0500

AndyZe gravatar image

updated 2022-08-27 19:06:03 -0500

Eventually I found two ways to fix this recompile with -fPIC type of error. In my case, I think it was occurring because I was trying to link LIB_A (a static library) into LIB_B ( a shared library).

  • Method 1: add the fPIC flag to the CMakeLists of LIB_A, like this:

set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}")

  • Method 2: make LIB_A a shared library, too, like this:

add_library(thread_priority SHARED src/thread_priority.cpp)

as opposed to add_library(thread_priority STATIC src/thread_priority.cpp)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-03-17 04:41:55 -0500

Seen: 1,986 times

Last updated: Aug 27 '22