使用Xcode 8.0,我可以使用sysroot
为iOS进行交叉编译:
/Applications/Xcode.app/Contents/Developer/usr/bin/g++ \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk \
-miphoneos-version-min=10.0 -arch armv7s -stdlib=libc++ -std=gnu++11 \
helloworld.cpp
但是,使用Xcode 8.1,它会下降:
/Applications/Xcode.app/Contents/Developer/usr/bin/g++ \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk \
-miphoneos-version-min=10.1 -arch armv7s -stdlib=libc++ -std=gnu++11 \
helloworld.cpp
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
In file included from helloworld.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:215:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/wchar.h:70:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/_types.h:27:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/sys/_types.h:32:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/sys/cdefs.h:761:2: error: Unsupported architecture
#error Unsupported architecture
关于
using sysroot for 'MacOSX' but targeting 'iPhone'
的警告似乎表明sysroot
参数已被忽略(并且在错误中明确指出其使用MacOSX10.12.sdk)。这些论点改变了吗?如何正确指定sysroot?
最佳答案
由于Apple的gcc / g++只是在clang / clang++之上的垫片,我们可以直接使用clang吗?
原来可行:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk \
-miphoneos-version-min=10.1 -arch armv7s -stdlib=libc++ -std=gnu++11 \
helloworld.cpp
苹果公司的gcc / g++似乎因更改sysroot而被淘汰。但是,我们似乎能够使用gcc样式的
--sysroot
参数。方便!奇怪的是,如果我尝试使用不带前缀的clang,则必须使用
-isysroot
:clang++ \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk \
-miphoneos-version-min=10.1 -arch armv7s -stdlib=libc++ -std=gnu++11 \
helloworld.cpp
关于ios - 带有iOS sysroot和xcode 8.1的g++,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41007556/