xcode -isysroot 或 SDKROOT 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2279499/
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-09-14 19:07:56  来源:igfitidea点击:

-isysroot or SDKROOT problem

cxcodemacoshistoryreadline

提问by Raviprakash

I am a newbie to libhistory, so I was looking at the sample found with readline library. Compiled it on command prompt using:

我是 libhistory 的新手,所以我正在查看使用 readline 库找到的示例。使用以下命令在命令提示符下编译它:

gcc -o ./a.out /usr/local/share/readline/histexamp.c -lreadline -L/usr/local/lib/
它编译和维护历史。

Then crated a xcode project with the same file and linked against readline library it compiles fine. But when I run , it won't maintain history and crashing while enumeration of history entries. After some trials i found that -isysroot argument is the cause for this problem:

然后用相同的文件创建一个 xcode 项目并链接到它编译良好的 readline 库。但是当我运行时,它不会在枚举历史条目时保持历史和崩溃。经过一些试验,我发现 -isysroot 参数是导致此问题的原因:

-isysroot /Developer/SDKs/MacOSX10.6.sdk
gcc 手册页说 isysroot 类似于 --sysroot 选项,但仅适用于头文件。

Why the same program behaves differently with this option?

为什么同一个程序使用这个选项会有不同的表现?

回答by Paul R

-isysroot is used to define the SDK that you build with. If you build with the 10.6 SDK and then try and run on OS X 10.5 then you will probably fail. You should build with whichever SDK corresponds to the minimum required OS for your program (for maximum backward-compatibility).

-isysroot 用于定义您构建时使用的 SDK。如果您使用 10.6 SDK 构建,然后尝试在 OS X 10.5 上运行,那么您可能会失败。您应该使用与您的程序所需的最低操作系统相对应的任何 SDK 进行构建(以获得最大的向后兼容性)。

回答by yushen

-isysroot /Developer/SDKs/MacOSX10.6.sdk

the sysroot will overwrite the system path /usr/local etc.

sysroot 将覆盖系统路径 /usr/local 等。

In my opinion, it is a problematic way to use the SDK path by XCode. It will result in a non-existent path like /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib/ if you want to search in the user link -L/usr/local/lib/

在我看来,通过 XCode 使用 SDK 路径是一种有问题的方式。如果你想在用户链接 -L/usr/local/lib/ 中搜索,它会导致一个不存在的路径,比如 /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib/

I don't think it is a good idea at all to change sysroot just in order to use SDK

我认为仅仅为了使用 SDK 而改变 sysroot 根本不是一个好主意