C++ CMake 可以在 Mac OS X 上指定基础 SDK 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10165335/
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
Can CMake specify the base SDK on Mac OS X?
提问by Nick Bolton
Does anyone know how to do specify the Mac OS X SDK to build against with CMake? I have searched for cmake mac "base sdk"
but this turned up nothing.
有谁知道如何指定要使用 CMake 构建的 Mac OS X SDK?我已经搜索过,cmake mac "base sdk"
但这没有任何结果。
I am using CMake to generate Unix makefiles.
我正在使用 CMake 生成 Unix 生成文件。
Update
更新
On my 10.6 install, I see that /Developer/SDKs
has the following:
在我的 10.6 安装中,我看到/Developer/SDKs
有以下内容:
- MacOSX10.4u.sdk
- MacOSX10.5.sdk
- MacOSX10.6.sdk
- MacOSX10.4u.sdk
- MacOSX10.5.sdk
- MacOSX10.6.sdk
Perhaps I can get CMake to pass one of these paths to the compiler somehow?
也许我可以让 CMake 以某种方式将这些路径之一传递给编译器?
Also, my 10.7 install only has:
另外,我的 10.7 安装只有:
- MacOSX10.6.sdk
- MacOSX10.7.sdk
- MacOSX10.6.sdk
- MacOSX10.7.sdk
Does this mean that it can only build for these platforms?
这是否意味着它只能为这些平台构建?
Update 2
更新 2
Damn, I just realised that actually I'm not using Xcode -- so this may affect some answers. Also, I am now trying with Mac OS X 10.8 developer preview (with some weird results, see my answer).
该死,我才意识到实际上我没有使用 Xcode——所以这可能会影响一些答案。另外,我现在正在尝试使用 Mac OS X 10.8 开发人员预览版(有一些奇怪的结果,请参阅我的回答)。
回答by Nick Bolton
After trying sakra's valid answer (valid as far as CMake is suposed to behave) unsucessfully, I had a dig around and found that if I specify the --sysroot
flag to the compiler, it seems to use the correct SDK!
在尝试了 sakra 的有效答案(就 CMake 的行为而言有效)失败后,我进行了一番挖掘,发现如果我--sysroot
向编译器指定了标志,它似乎使用了正确的 SDK!
However, I now see this error when I compile against 10.7 (which I don't see with 10.8):
但是,我现在在针对 10.7 进行编译时看到此错误(在 10.8 中看不到):
Undefined symbols for architecture i386:
"_NXArgv", referenced from:
execSelfNonDaemonized() in libarch.a(CArchDaemonUnix.o)
CArchDaemonUnix::daemonize(char const*, int (*)(int, char const**)) in libarch.a(CArchDaemonUnix.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/synergyc] Error 1
make[1]: *** [src/cmd/synergyc/CMakeFiles/synergyc.dir/all] Error 2
make: *** [all] Error 2
Note: CArchDaemonUnix
is a class in Synergy (an open source project I'm working on).
注意:CArchDaemonUnix
是 Synergy 中的一个类(我正在开发的一个开源项目)。
Update:
更新:
Just tried this on my 10.6 install, and I was getting a linker error when trying to compile for 10.5 -- turns out you also need to specify the MACOSX_DEPLOYMENT_TARGET
environment variable!
刚刚在我的 10.6 安装上尝试过这个,当我尝试为 10.5 编译时出现链接器错误——结果你还需要指定MACOSX_DEPLOYMENT_TARGET
环境变量!
Anyway, here's what I'm doing when running on Mountain Lion (OSX 10.8) to compile for 10.7:
无论如何,这是我在 Mountain Lion (OSX 10.8) 上运行以编译 10.7 时正在做的事情:
Command line:
命令行:
MACOSX_DEPLOYMENT_TARGET=10.7
cmake -G "Unix Makefiles" -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.7.sdk/ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.7 ../..
CMakeLists.txt:
CMakeLists.txt:
set(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
I hope this helps someone! :-)
我希望这可以帮助别人!:-)
回答by vtoukas
Add the following commands on your CMakeLists.txt
在 CMakeLists.txt 上添加以下命令
set(CMAKE_OSX_SYSROOT macosx10.10)
设置(CMAKE_OSX_SYSROOT macosx10.10)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5")
设置(CMAKE_OSX_DEPLOYMENT_TARGET“10.5”)
This should be fine.
这应该没问题。
回答by sakra
You can set the variable CMAKE_OSX_SYSROOT
to the chosen SDK upon configuring the project. E.g.:
您可以CMAKE_OSX_SYSROOT
在配置项目时将变量设置为所选的 SDK。例如:
cmake -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.4u.sdk/ ..
See the documentation here.
请参阅此处的文档。
Also note that CMake versions before 2.8.8 do not supportXcode 4.3.
另请注意,2.8.8 之前的 CMake 版本不支持Xcode 4.3。