macos 使用 QtCreator [mac os] 找不到用于 -lrt 的库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1505402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:26:58  来源:igfitidea点击:

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

cmacoscompiler-constructionqt4compilation

提问by Houssem

i'm getting some troubles with QT it builds with option "-lrt"

我在使用 QT 时遇到了一些麻烦,它使用选项“-lrt”构建

i'm using mac os 10.6 with QT creator 1.2.1, heeeeeeelp !

我正在使用 mac os 10.6 和 QT creator 1.2.1,heeeeeeeelp!

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

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

ld:找不到用于 -lrt collect2 的库:ld 返回 1 个退出状态

回答by user151019

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

链接器找不到 librt,它可能是 Posix 实时扩展库。我不认为这在 OSX 上可用。谷歌搜索从Apple 开发者列表中得到了这个

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.

我正在尝试构建在我的大学(在 Linux 上)开发的模拟器,但链接器出现错误,似乎无法找到 librt.a - 在代码中用于 clock_gettime() 我想知道是否有此类库的端口,或其他一些类似的功能,即使在 Mac OS X 上也可以编译。

答案 librt.a 是包含 POSIX Advanced Realtime [RT} Option 函数的库的 System V 名称。您询问的特定功能是 [TMR] 选项的一部分。如果 Mac OS X 支持它,它将在 libSystem.B,dylib 中,而不是 librt.a。Mac OS X 不支持相关功能。

您的代码应该检查是否在目标操作系统中实现了可选的实现超出 UNIX 标准的东西,如果没有,请使用不同的接口。

回答by asveikau

Why does the program need librt?

为什么程序需要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)

我知道某些平台(想到 Solaris)需要 librt 来执行操作系统中其他库中可能存在的某些函数。(sem_init()等都是这样的)

You might try to link without -lrt and see if it works.

您可以尝试在不使用 -lrt 的情况下进行链接,看看它是否有效。