# ld searches in wrong folder for libraries when cross-compiling

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:

• 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 ...
edit retag close merge delete

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

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

( 2013-10-18 12:56:47 -0600 )edit

Sort by » oldest newest most voted

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

more

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.

( 2019-02-06 00:50:24 -0600 )edit

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)

more