What is the C library "rt"? [duplicate] - c

i'm getting some troubles with QT it builds with option "-lrt"
i'm using mac os 10.6 with QT creator 1.2.1, heeeeeeelp !
this is the full build command :
g++ -headerpad_max_install_names -o
AMiningCoreTest main.o tokenizer.o
DictionnaryToolBox.o mysql.o btree.o
BTreeDataTable.o tcaccess.o
-L/Library/Frameworks -L/usr/lib/mysql -lmysqlclient -L/usr/local/lib/ -ltokyocabinet -lz -lbz2 -lrt -lpthread -lm -lc
and it ends with
ld: library not found for -lrt
collect2: ld returned 1 exit status

The linker cannot find librt which is probably the Posix real time extensions library. I don't think this is available on OSX. Googling gives this from Apple developer lists
Question from list
I'm trying to build a simulator developed in my university (on Linux)
and I get error by the linker that seems unable to find librt.a - in
the code is used for clock_gettime() and I would like to know if
there's a port of such library, or some other similar function that
allows me to compile even on Mac OS X.
Answer
librt.a is the System V name of the library containing the POSIX
Advanced Realtime [RT} Option functions. The specific function you are
asking about is part of the [TMR] option. If Mac OS X supported it, it
would be in libSystem.B,dylib, not librt.a. The function in question
is not supported by Mac OS X.
Your code should check to see whether optional to implement things
above and beyond the UNIX standard are implemented in the target OS,
and if they aren't, use a different interface.

Why does the program need librt?
I know that some platforms (Solaris comes to mind) require librt for some functions which might exist in other libraries in your OS. (sem_init() et al. are like this)
You might try to link without -lrt and see if it works.

Related

Shared Memory Library -lrt in C on macOS

I'm doing a university assignment on shared memory on C, I need to use the functions shm_open(), mmap(), ftruncate(), shm_unlink(), etc. using a Mac with macOS Mojave 10.14
My teacher told me I need to use the -lrt library in my Makefile to make it work but when I "make" I got an error which goes
ld: library not found for -lrt
clang: error: linker command failed with exit code 1
Is the library spelled work? If I don't have it, I need to download it? Do I even need a specific library? ('cause on the internet I didn't find anybody using one...)
I'm very confused.

gcc -lnsl error in socket programming on mac os

I am trying to compile my C socket programming files using gcc with -lnsl option on MAC OS but it gives me this error:
ld: library not found for -lnsl
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
This is the gcc command:
gcc -o server -lnsl server.c
I looked all over the internet but I can't find sth relevant to help me. How to install the missing library? Or should I reinstall gcc? Please help!
Thanks!
Mac OS X has no libnsl. Functions that live in libnsl on Linux are found in the standard C library on Mac OS X. No additional flags are necessary for building programs that use these functions.
If your program works on Linux and doesn't work on a Mac, then your program has a bug that is triggered on Mac OS X but not on Linux. No amout of fiddling with linker flags is likely to change that.

How to get linker to report where it is linking to for a given function

I have an issue trying to cross build win32 and win64 exes on a linux host.
I am using the mingw cross build toolchains
my .c file includes time.h in order to use clock_gettime() in main()
now this is a POSIX thing so no guarantee it is windows portable
however, on another laptop with a similar (but obviously not identical) setup it does compile and link no problem
on this laptop (a new one I am migrating to) I get a linker error:
undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
what I would like to be able to do is somehow have the linker on the other machine tell me where it is finding the .dll with clock_gettime() in it
In order for me to see whether the similar .dll is present on the new laptop and whether the clock_gettime() symbol is avaiable in it
Is it possible to get the linker to report this info, some sort of verbose mode perhaps. I've gone down the GIYF route but drawn a blank thus far.
Compile with -lrt which is needed for for glibc version < 2.17.
What probably happens on the other laptop is that it has a recent version of glibc >=2.17 in which the the clock_gettime() is part of the libc. But older in glibcs, it's a separate library. Hence, you needed to link it yourself.
To use clock_gettime() as defined in <time.h> when cross building for windows using mingw toolchain on a linux host you must link to pthread not rt
for example:
source code, example.c, looks like this:
#include <time.h>
...
struct timespec t1;
...
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t1);
native build looks like this:
gcc example.o -lrt -o example
win32 cross-build looks like this:
i686-w64-mingw32-gcc -I/usr/local/i686-w64-mingw32/include example.o -L/usr/local/i686-w64-mingw32/bin -lpthread -lws2_32 -o example.exe
Unfortunately, I am none the wiser on how to get the linker to tell me in which library it has found a function that it has successfully linked to
i.e. if I could have somehow got the linker to inform me that it had found clock_gettime() in libpthread on my other machine that was successfully linking, I could have saved a lot of messing about fixing the link error issue on this machine.

Compile shared library with link to other .so

I want to link an existing shared library (FlashRuntimeExtensions.so) to my C-code while compiling my own shared library. But whatever I try I always get the same error; that the file is in a wrong format. Does anybody have an idea on how to solve this?
Here is my compile command:
$ g++ -Wall ane.c FlashRuntimeExtensions.so -o aneObject
FlashRuntimeExtensions.so: could not read symbols: File in wrong format
collect2: ld gaf exit-status 1 terug
Your command line tries to generate x86 code and link it to ARM code using the native g++ available in your distribution.
This will not work. Use the Android NDK available here: http://developer.android.com/tools/sdk/ndk/index.html
The NDK includes a set of cross-toolchains (compilers, linkers, etc..) that can generate native ARM binaries on Linux, OS X, and Windows (with Cygwin) platforms.
In general .so will be linked using -l.
for example, pthread -lpthread we use.
gcc sample.c -o myoutput -lpthread
But as per #chill's statement, what you are doing in command is correct only.
I suggest you to refer the following link.
C++ Linker Error SDL Image - could not read symbols
It should be an architecture mismatch. I faced this problem once, I have solved it by building the libs in same target platform and it is obvious. If you are using linux or Unix like OS you can see that by file command and if you are using windows you can see that using Dependency Walker. You need to make sure that all the libs matches architecture.

library not found for -lrt with QtCreator [mac os]

i'm getting some troubles with QT it builds with option "-lrt"
i'm using mac os 10.6 with QT creator 1.2.1, heeeeeeelp !
this is the full build command :
g++ -headerpad_max_install_names -o
AMiningCoreTest main.o tokenizer.o
DictionnaryToolBox.o mysql.o btree.o
BTreeDataTable.o tcaccess.o
-L/Library/Frameworks -L/usr/lib/mysql -lmysqlclient -L/usr/local/lib/ -ltokyocabinet -lz -lbz2 -lrt -lpthread -lm -lc
and it ends with
ld: library not found for -lrt
collect2: ld returned 1 exit status
The linker cannot find librt which is probably the Posix real time extensions library. I don't think this is available on OSX. Googling gives this from Apple developer lists
Question from list
I'm trying to build a simulator developed in my university (on Linux)
and I get error by the linker that seems unable to find librt.a - in
the code is used for clock_gettime() and I would like to know if
there's a port of such library, or some other similar function that
allows me to compile even on Mac OS X.
Answer
librt.a is the System V name of the library containing the POSIX
Advanced Realtime [RT} Option functions. The specific function you are
asking about is part of the [TMR] option. If Mac OS X supported it, it
would be in libSystem.B,dylib, not librt.a. The function in question
is not supported by Mac OS X.
Your code should check to see whether optional to implement things
above and beyond the UNIX standard are implemented in the target OS,
and if they aren't, use a different interface.
Why does the program need librt?
I know that some platforms (Solaris comes to mind) require librt for some functions which might exist in other libraries in your OS. (sem_init() et al. are like this)
You might try to link without -lrt and see if it works.

Resources