-isysroot或SDKROOT问题
我是 libhistory 的新手,所以我正在查看使用 readline 库找到的示例。使用以下命令在命令提示符下编译它:
gcc -o ./a.out /usr/local/share/readline/histexamp.c -lreadline -L/usr/local/lib/
It compiles and maintains history.然后使用相同的文件创建一个 xcode 项目,并链接到 readline 库,它可以正常编译。但是当我运行时,它不会保留历史记录,并且在枚举历史条目时会崩溃。经过一番试验,我发现 -isysroot 参数是导致此问题的原因:
-isysroot /Developer/SDKs/MacOSX10.6.sdk
The gcc man page says isysroot is like the --sysroot option, but applies only to header files.为什么同一个程序使用此选项会有不同的行为?
I am a newbie to libhistory, so I was looking at the sample found with readline library. Compiled it on command prompt using:
gcc -o ./a.out /usr/local/share/readline/histexamp.c -lreadline -L/usr/local/lib/
It compiles and maintains history.
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:
-isysroot /Developer/SDKs/MacOSX10.6.sdk
The gcc man page says isysroot is like the --sysroot option, but applies only to header files.
Why the same program behaves differently with this option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-isysroot 用于定义您构建时使用的 SDK。如果您使用 10.6 SDK 进行构建,然后尝试在 OS X 10.5 上运行,那么您可能会失败。您应该使用与您的程序所需的最低操作系统相对应的 SDK 进行构建(以获得最大的向后兼容性)。
-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).
sysroot会覆盖系统路径/usr/local等。
在我看来,通过XCode使用SDK路径是有问题的。
这将导致一条不存在的路径,例如
/开发者/SDKs/MacOSX10.6.sdk/usr/local/lib/
如果你想在用户链接-L/usr/local/lib/中搜索,
我认为仅仅为了使用SDK而更改sysroot根本不是一个好主意
the sysroot will overwrite the system path /usr/local etc.
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/
I don't think it is a good idea at all to change sysroot just in order to use SDK