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

ld searches in wrong folder for libraries when cross-compiling

asked 2013-02-13 12:12:47 -0600

Hououin Kyouma gravatar image

updated 2013-02-13 12:17:03 -0600

Hi guys,

I'm trying to cross-compile my own packages for armv7, so far I've been able to specify the correct toolchain by using the rostoolchain.cmake file. I also fixed a lot of other things I've had trouble with, but the only thing I'm having trouble with right now is specifying the correct folder for ld to search for libraries. I have stored all the ARM-compiled .so files I need in /opt/armv7/usr/lib, but ld still tries to look for libraries in /opt/ros/groovy/lib and /usr/lib. Since the files in those directories are compiled for Intel, that doesn't work of course. This is the error I get when I try to compile:

/opt/armv7/bin/../lib/gcc/arm-v7a8-linux-gnueabi/4.4.1/../../../../arm-v7a8-linux-

gnueabi/bin/ld: skipping incompatible /opt/ros/groovy/lib/libroscpp.so when searching for -lroscpp
/opt/armv7/bin/../lib/gcc/arm-v7a8-linux-gnueabi/4.4.1/../../../../arm-v7a8-linux-gnueabi/bin/ld: cannot find -lroscpp

How do I specify the correct folder for ld to look into? So far, I've tried the following "solutions" with no success:

  • Adding /opt/armv7/usr/lib to LD_LIBRARY_PATH, which didn't work. Seems like the directories I added were ignored completely.

  • Adding lines like set(CMAKE_SYSTEM_LIBRARY_PATH ...) or set(CMAKE_LIBRARY_PATH) to rostoolchain.cmake with the same result as with the LD_LIBRARY_PATH solution.

  • Setting the LD_PRELOAD variable, which gave me:

    ERROR: ld.so: object '/opt/armv7/usr/lib/libroscpp.so' from LD_PRELOAD cannot be preloaded: ignored.

  • Using the /etc/ld.so.conf.d and /etc/ld.so.conf files, which gave the same results as the first and second solutions (in other words, no results..)

  • Linking manually using target_link_libraries, which helped for direct dependencies of my project, but not for the second level dependencies. For example, if I manually link /opt/armv7/usr/lib/libroscpp.so then it is able to find libroscpp.so, but not /usr/lib/libboost_date_time-mt.so.

  • Replacing the whole lib folder in /opt/ros/groovy by my own lib folder, except for rospack.so because ROS needs that in order to make use of the Makefile. This didn't work since ld still looks for libraries in /usr/lib. I prefer not to replace my /usr/lib folder for the arm libraries..

  • Only replacing specific Intel library files I need by their ARM counterparts, which worked for those libraries, but not for the rest of course. This solution is actually the same as the one above, except that I'm not replacing everything altogether. I do not prefer to replace all the libraries one by one..

I think I tried even more, but I forgot.. At least these are the most important things I tried. I'm stuck for weeks now so I'd really appreciate it if someone is able to help me. My rostoolchain.cmake file looks like this by the way:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER /opt/armv7/bin/arm-v7a8-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /opt/armv7/bin/arm-v7a8-linux-gnueabi-g++)
set(CMAKE_FIND_ROOT_PATH /opt/armv7/usr ...
(more)
edit retag flag offensive close merge delete

Comments

Did you ever get answer to your question? I'm in a similar situation.

lboltzmann gravatar image lboltzmann  ( 2013-07-26 05:08:47 -0600 )edit

Hi, sorry for the late reply, I just noticed this post.. I never succeeded in solving this problem, so I can' t help you with this unfortunately. I basically gave up on this, but mainly because of the switch from rosbuild to catkin, so it became rather useless for me to try this anymore.

Hououin Kyouma gravatar image Hououin Kyouma  ( 2013-10-18 12:56:47 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-10-14 04:42:45 -0600

random_random gravatar image

updated 2019-02-06 02:34:42 -0600

gvdhoorn gravatar image

If someone's get here, there's a solution: You just have to add this flag: --sysroot=your_sysroot_dir and everything will work

edit flag offensive delete link more

Comments

It is extremely disappointing to see a "half solution" as the accepted one. Many novices and other users who are desperately looking for a solution would want to see the exact place for this magical flag.

tahsinkose gravatar image tahsinkose  ( 2019-02-06 00:50:24 -0600 )edit
1

answered 2019-02-06 00:55:20 -0600

tahsinkose gravatar image

For those who are interested in the full solution proposed by @random_random about adding flag "--sysroot=your_sysroot_dir" may inspect the following:

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}" CACHE INTERNAL "" FORCE)
    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}" CACHE INTERNAL "" FORCE)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}" CACHE INTERNAL "" FORCE)
    set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}" CACHE INTERNAL "" FORCE)
edit flag offensive delete link more

Comments

You save my day. Paste those lines to toolchain.cmake file and everything works just fine.

Terrylu87 gravatar image Terrylu87  ( 2020-09-21 20:42:28 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-02-13 12:12:47 -0600

Seen: 9,284 times

Last updated: Feb 06 '19