I tried to compile the following code on ubuntu 11.04:
#include
#include
int main()
My same problem got solved from @anio's answer but I needed to do additional work. As I cannot comment due to low reputation. So I am presenting my pennies, may be someone find it helpful. I am baby stepping everything, so "sorry" if I seem childish.
I am using Eclipse on Debian for cross compiling for arm-linux-gnueabihf-g++. So I first found the location for "librt"
/$ find -iname "librt*"
./home/myuser/targetsysroot/usr/lib/arm-linux-gnueabihf/librt.a
./home/myuser/targetsysroot/usr/lib/arm-linux-gnueabihf/librt.so
./home/myuser/targetsysroot/usr/lib/arm-linux-gnueabihf/librtmp.so.0
./home/myuser/targetsysroot/lib/arm-linux-gnueabihf/librt-2.13.so
./home/myuser/targetsysroot/lib/arm-linux-gnueabihf/librt.so.1
./lib/arm-linux-gnueabihf/librt.so.1
./lib/arm-linux-gnueabihf/librt-2.19.so
./lib/i386-linux-gnu/librt.so.1
./lib/i386-linux-gnu/i686/cmov/librt.so.1
./lib/i386-linux-gnu/i686/cmov/librt-2.19.so
./lib/i386-linux-gnu/librt-2.19.so
As I prefer to sync with the remote target machine I have added "sysroot path" for my library into eclipse project properties "Library Search Path (-L)"
/home/myuser/targetsysroot/usr/lib/arm-linux-gnueabihf
Also added "rt" to Libraries (-l), which ultimately solved my problem.
In case you are compiling with the use
g++ -L $YOUR_PATH_TO_LIB$ shared.o -o shared -lrt
replace $YOUR_PATH_TO_LIB with yours.
shm_open is made available by linking librt. Try passing -lrt flag to the linker.
Try: g++ -c -Wall shared.cpp
g++ -L /lib -lrt shared.o -o shared
g++ -L /lib shared.o -o shared -lrt -lpthread
Just adding to @anio's answer:
While linking, the -lrt flag may need to be added at the end of the command. Try:
g++ -L /lib shared.o -o shared -lrt