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

2019-01-11 19:50发布

问题:

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

回答1:

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.



回答2:

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.