User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

crosscompiling and librt.so.1

Thu Oct 11, 2012 2:23 pm

Hello smart people,

I'm succesfully crosscompiling OpenGL ES applications for the Raspberry Pi on my 32-bit Ubuntu machine. Setting it up was easy. I cloned the 'tools' and 'firmware' directories from github, and told cmake where to look for headerfiles, libraries and the hard-fp compiler/linker. Works great.

Now I need to do some timekeeping to spawn particles. That's where things go wrong. Relevant code from the timer-class (timer.cpp):

Code: Select all

#include <time.h>
[...]
timespec tS;
clock_gettime(CLOCK_REALTIME, &tS);
On the Raspberry Pi, it compiles and works without problems. But when crosscompiling, timer.cpp compiles but doesn't link:

Code: Select all

/home/panik/code/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../lib/gcc/arm-bcm2708hardfp-linux-gnueabi/4.7.1/../../../../arm-bcm2708hardfp-linux-gnueabi/bin/ld: ../../lib/libgametools.a(timer.cpp.o): undefined reference to symbol '[email protected]@GLIBC_2.4'
/home/panik/code/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../lib/gcc/arm-bcm2708hardfp-linux-gnueabi/4.7.1/../../../../arm-bcm2708hardfp-linux-gnueabi/bin/ld: note: '[email protected]@GLIBC_2.4' is defined in DSO /home/panik/code/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/librt.so.1 so try adding it to the linker command line
/home/panik/code/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/librt.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [demo/particle/particle] Error 1
make[1]: *** [demo/particle/CMakeFiles/particle.dir/all] Error 2
make: *** [all] Error 2
The errormessage is pretty clear, so I tried adding the path to librt.so.1 in cmake with 'link_directories("all/paths/to/librt.so.1/that/could/possibly/be/correct")', but no cigar.

The file librt.so.1 is actually a symbolic link to librt-2.13.so. Could that have something to do with it? It's hard to google, because the word 'link' in combination with 'ld' has different meanings, but is always relevant. My google-fu fails spectacularly on this one. Any ideas?

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: crosscompiling and librt.so.1

Thu Oct 11, 2012 2:42 pm

Derp! Nevermind.

When compiling on the Raspberry Pi it somehow didn't need the '-lrt' flag. When crosscompiling, it does.
I don't know why it works on the Pi without it, but it works in all cases now. Sorry for wasting your time.

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: crosscompiling and librt.so.1

Thu Oct 11, 2012 2:45 pm

Someone had a similar thing https://github.com/Bumblebee-Project/Bu ... /issues/76 not sure how relevant it is, but the google search was

Code: Select all

librt.so linking symbols
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: crosscompiling and librt.so.1

Thu Oct 11, 2012 3:01 pm

Thanks! Your post crossed with my second post. I really appreciate your time to reply, but it's fixed now. I misinterpreted the (otherwise very clear) error message.
It just needed the '-lrt' flag. Thanks again!

Edit: And yes, it was the same fix. I better start working on that google-fu.

vassiskansa
Posts: 6
Joined: Fri Mar 20, 2015 10:09 am

Re: crosscompiling and librt.so.1

Fri Mar 20, 2015 10:12 am

Hi,
sorry for my bad english... how can i set this flag into my building command?

I need to build ZoneMinder 1.28.x ... and this is my problem...

Code: Select all

[email protected]:/usr/local/src/ZoneMinder-1.28.1# make install
Making install in src
make[1]: ingresso nella directory "/usr/local/src/ZoneMinder-1.28.1/src"
g++ -D__STDC_CONSTANT_MACROS -g -O2  -L/usr/bin/lib -L/usr/lib/  -L/usr/lib/mysql -L/usr/lib/mariadb  -o zmc zmc.o zm_box.o zm_buffer.o zm_camera.o zm_comms.o zm_config.o zm_coord.o zm_curl_camera.o zm.o zm_db.o zm_logger.o zm_event.o zm_exception.o zm_file_camera.o zm_ffmpeg_camera.o zm_image.o zm_jpeg.o zm_libvlc_camera.o zm_local_camera.o zm_monitor.o zm_ffmpeg.o zm_mpeg.o zm_poly.o zm_regexp.o zm_remote_camera.o zm_remote_camera_http.o zm_remote_camera_rtsp.o zm_rtp.o zm_rtp_ctrl.o zm_rtp_data.o zm_rtp_source.o zm_rtsp.o zm_rtsp_auth.o zm_sdp.o zm_signal.o zm_stream.o zm_thread.o zm_time.o zm_timer.o zm_user.o zm_utils.o zm_zone.o  -lz -lavformat -lavcodec -lavutil -lz -lpcre -lgnutls-openssl -lgnutls -lgcrypt -ldl -lpthread -ljpeg -lmysqlclient 
/usr/bin/ld: zm_mpeg.o: undefined reference to symbol '[email protected]@GLIBC_2.4'
//lib/arm-linux-gnueabihf/librt.so.1: error adding symbols: DSO missing from command line
collect2: ld returned 1 exit status
Makefile:481: set di istruzioni per l'obiettivo "zmc" non riuscito
make[1]: *** [zmc] Errore 1
make[1]: uscita dalla directory "/usr/local/src/ZoneMinder-1.28.1/src"
Makefile:445: set di istruzioni per l'obiettivo "install-recursive" non riuscito
make: *** [install-recursive] Errore 1
Thank you.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: crosscompiling and librt.so.1

Fri Mar 20, 2015 3:37 pm

Wow, that 'bug in upstream ld' must still be there after 3 years. I'm not a cmake wizard and don't know how to do it 'properly', so I would just 'hack it' in there.

Searching for 'target_link_libraries(...)', found a couple in 'ZoneMinder/src/CMakeLists.txt' (with zmc on line 20). I'm probably showing my ignorance here, but I would try adding it to that line.

Code: Select all

target_link_libraries(zmc zm ${ZM_EXTRA_LIBS} ${ZM_BIN_LIBS} rt)
Since that's the one that generated the error and the compiling stopped, you may need to add it to the other lines as well (if it works for zmc in the first place).
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

scar75
Posts: 4
Joined: Sun Apr 12, 2015 6:31 am

Re: crosscompiling and librt.so.1

Sun Apr 12, 2015 6:36 am

Hi all,
I am not much into cross compiling unfortunately. I am experiencing the same problems and it is not clear from your posts how to solve the problem. Where exactly shall I add the CFLAG? I am trying to compile a ROS package. I understand these flag should be added to the MakeFile file is it? Please help me out.
Thank you

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: crosscompiling and librt.so.1

Sun Apr 12, 2015 4:11 pm

In a Makefile, see if you can find an existing "LDFLAGS" entry (or "LDLIBS" maybe) and add '-lrt' to that.

Adding it to "CFLAGS" would only add it to the options for the compiler (gcc), not the linker (ld). In my case, it compiled correctly and only the linker was complaining.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

scar75
Posts: 4
Joined: Sun Apr 12, 2015 6:31 am

Re: crosscompiling and librt.so.1

Sun Apr 12, 2015 7:11 pm

Thank you for your prompt reply.
I am trying hard and yet I don't caome across the problem.
Given my error message:

Code: Select all

/usr/bin/ld: CMakeFiles/rplidarNode.dir/sdk/src/arch/linux/timer.cpp.o: undefined reference to symbol '[email protected]@GLIBC_2.4'
//lib/arm-linux-gnueabihf/librt.so.1: error adding symbols: DSO missing from command line
collect2: ld returned 1 exit status
CMakeFiles/rplidarNode.dir/build.make:204: recipe for target 'devel/lib/rplidar_ros/rplidarNode' failed
make[2]: *** [devel/lib/rplidar_ros/rplidarNode] Error 1
CMakeFiles/Makefile2:403: recipe for target 'CMakeFiles/rplidarNode.dir/all' failed
make[1]: *** [CMakeFiles/rplidarNode.dir/all] Error 2
Makefile:123: recipe for target 'all' failed
make: *** [all] Error 2

****  Installation failed. Aborting package creation.
I added:

Code: Select all

LDFLAGS=-lrt
CFLAGS=-lrt
basically everywhere:
in MakeFile:

Code: Select all

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

LDFLAGS=-lrt
CFLAGS=-lrt

Code: Select all

# Target rules for targets named rplidarNode

# Build rule for target.
LDFLAGS=-lrt
CFLAGS=-lrt
In MakeFile2:

Code: Select all

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
LDFLAGS=-lrt
CFLAGS=-lrt
In build.make:

Code: Select all

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
LDFLAGS=-lrt
CFLAGS=-lrt
I am completely lost.
Thanks again for your help

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: crosscompiling and librt.so.1

Sun Apr 12, 2015 7:40 pm

Are you trying to compile this? https://github.com/robopeak/rplidar_ros That's also a cmake project, so adding LDFLAGS in a Makefile will not work here.

In the root CMakeLists.txt (on line 26) it says:

Code: Select all

target_link_libraries(rplidarNode ${catkin_LIBRARIES})
Does it work if you make that:

Code: Select all

target_link_libraries(rplidarNode ${catkin_LIBRARIES} rt)
Or if it doesn't:

Code: Select all

target_link_libraries(rplidarNode ${catkin_LIBRARIES} -lrt)
The Makefiles you're editing are generated by cmake (and the CMakeLists.txt file), so you'll have to run 'cmake .' again.

Even better would be to create a separate build directory (inside the directory where the root CMakeLists.txt file is):

Code: Select all

mkdir build
cd build
cmake ..
make
Then -to regenerate the Makefiles- you'll only have to delete the build directory or its contents. It'll keep your source directory clean from auto-generated files.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

scar75
Posts: 4
Joined: Sun Apr 12, 2015 6:31 am

Re: crosscompiling and librt.so.1

Mon Apr 13, 2015 8:11 am

Panik,

thank you soooo much, you really got me out of panic! :)
It worked with both 'rt' and '-lrt' options.
I just used the default catkin build folder and add build and install prefix to cmake in order to comply with the workspace folder structure but for the rest worked like a charm.

I sincerily appreciated your help.
Warm regards,
Marcello

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: crosscompiling and librt.so.1

Mon Apr 13, 2015 5:29 pm

Good to know it worked out for you. Thanks for reporting back with the results!
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

Return to “C/C++”