CMake可以在Mac OS X上指定基本SDK吗? [英] Can CMake specify the base SDK on Mac OS X?
问题描述
有人知道如何指定要使用CMake构建的Mac OS X SDK吗?我已经搜索了cmake mac "base sdk"
,但是没有发现任何问题.
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生成Unix makefile.
I am using CMake to generate Unix makefiles.
在我的10.6安装中,我看到/Developer/SDKs
具有以下内容:
On my 10.6 install, I see that /Developer/SDKs
has the following:
- MacOSX10.4u.sdk
- MacOSX10.5.sdk
- MacOSX10.6.sdk
也许我可以让CMake以某种方式将这些路径之一传递给编译器?
Perhaps I can get CMake to pass one of these paths to the compiler somehow?
此外,我的10.7安装仅具有:
Also, my 10.7 install only has:
- MacOSX10.6.sdk
- MacOSX10.7.sdk
这是否意味着它只能针对这些平台构建?
Does this mean that it can only build for these platforms?
该死,我刚刚意识到实际上我没有在使用Xcode,所以这可能会影响一些答案.另外,我现在正在尝试使用Mac OS X 10.8开发人员预览版(有一些奇怪的结果,请参见我的答案).
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).
推荐答案
在尝试了sakra的有效答案(就CMake而言,该行为是有效的)后,我进行了一次挖掘,发现如果我指定了--sysroot
标记到编译器,似乎使用了正确的SDK!
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!
但是,现在我在针对10.7(在10.8中没有看到)进行编译时看到此错误:
However, I now see this error when I compile against 10.7 (which I don't see with 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
注意:CArchDaemonUnix
是Synergy(我正在研究的一个开源项目)中的一类.
Note: CArchDaemonUnix
is a class in Synergy (an open source project I'm working on).
刚在我的10.6安装中尝试过此操作,并且在尝试为10.5进行编译时遇到链接器错误-事实证明,您还需要指定MACOSX_DEPLOYMENT_TARGET
环境变量!
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!
无论如何,这是我在Mountain Lion(OSX 10.8)上运行以编译为10.7时正在做的事情:
Anyway, here's what I'm doing when running on Mountain Lion (OSX 10.8) to compile for 10.7:
命令行:
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! :-)
这篇关于CMake可以在Mac OS X上指定基本SDK吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!