Problems using Cmake with Qt 5.4 for iOS
-
I am having a hell of a time trying to get xCode to link Qt for my iOS simulator project. I am using CMake to generate the xCode project file. Here are the relevant OSX lines I am using in my CMake script:
set(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk)
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)")
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")I set the search path for Qt here:
set(CMAKE_PREFIX_PATH ${QT_DIR})
I use find_package to get the Qt info for my project:
find_package(Qt5 COMPONENTS Qml Network OpenGL REQUIRED)
When I load the resulting project in xCode, it does not appear to like the project file, since it does not appear that the proper build settings are set. Oddly it still builds and links for the most part, and it appears that xCode knows that its an iOS simulator project considering the search paths its using to try and find the Qt libraries:
ld: warning: directory not found for option '-L/Users/droscoe/Documents/workspace/dar_new_display_20141230_view/aop_build_d/lib/Debug-iphonesimulator'
ld: warning: directory not found for option '-L/Users/droscoe/Documents/workspace/SW_Library/ace/6.3.1/iOS/lib/Debug-iphonesimulator'But when it finally searches in the correct spot, its trying to link the wrong library:
iphonesimulator'
ld: warning: ld: warning: ld: warning: ignoring file /Users/droscoe/Qt/5.4/ios/lib/libQt5Qml_debug.a, missing required architecture x86_64 in file /Users/droscoe/Qt/5.4/ios/lib/libQt5Qml_debug.a (2 slices)ignoring file /Users/droscoe/Qt/5.4/ios/lib/libQt5Network_debug.a, missing required architecture x86_64 in file /Users/droscoe/Qt/5.4/ios/lib/libQt5Network_debug.a (2 slices)ignoring file /Users/droscoe/Qt/5.4/ios/lib/libQt5OpenGL_debug.a, missing required architecture x86_64 in file /Users/droscoe/Qt/5.4/ios/lib/libQt5OpenGL_debug.a (2 slices)There are several more entries like this one. I've done a lipo -info on them, and the warning is correct. The library reference above is for the iOS hardware, not the simulator, so it does not contain the proper architecture. If I do the same with libQt5Qml_iphonesimulator_debug.a, I see the correct architectures.
So, it seems that xCode knows its building an IOS simulator app, since its complaining about the missing architecture, but I can't get Qt to cooperate. I am using xCode Version 6.1.1 (6A2008a) Any help would be appreciated!
-Dave
-
I suspect that the wrong is in the CMakeLists.txt. In particular, you are settings the architecture to ARCHS_STANDARD_32_BIT, but I really doubt that it includes the iOS architecture.
In fact, the ld complains about the fact that "missing required architecture x86_64" ... but the error is not in the Qt library, but in the project. Because an iOS app cannot support x86_64, the iOS hardware is ARM not Intel.
So, it's right that Qt library miss x86_64, because (correctly) the Qt library for iOS is built against ARMv5 and ARMv7 (including the 64bit ARM devices). -
In the first sentence of my problem description I indicated I was trying an iOS simulator build. That is not an ARM cross-compile build but actually a special native MacOS build. I also stated I ran the lipo -info on both libraries (ARM, iOS Simulator) and confirmed that the architecture it is complaining about is NOT in the ARM library, but IS in the iOS simulator library. I am not saying the warning is wrong. I am saying it shouldn't be trying to link the ARM version of the library in the first place, and I can't figure out how to force it to link the iOS Simulator library instead. In the two previous paths in the search path, its clearly looking for the iOS simulator library, but when it gets to the actual Qt path, its mysteriously (to me) trying to link the ARM library.
I tried explicitly setting the OSX_ARCHITECTURES to x86_64 or i386 (which are architectures in the iOS Simulator library), with no change in behavior. I also tried explicitly limiting the XCODE_EFFECTIVE_PLATFORMS to only specify "iphonesimulator", again with no change in behavior.
What doesn't make any sense is that xCode is correctly identifying the 17 other libraries in my project as iOS Simulator libraries and compiling and linking them without any problems. This is from the same CMake scripts, but is not correctly linking Qt, so it cannot be solely a CMake, issue. What I do know is that when I load the project file that CMake creates, the build settings in xCode do not appear to be correct, so CMake is implicated somewhat. Manually fixing the build settings from the xCode IDE does not solve the problem. I know I must be doing SOMETHING wrong with the CMake script, and since Qt and Cmake are historically, tightly integrated, it makes sense (to me) to pose my question here. I've been using CMake to build my project for Windows and MacOS for over a year, without a problem. My new project is meant for iOS and uses several common libraries with my legacy native Windows/MacOS project.
I tried using Qt Creator to build my project instead, but it does not appear to fit the bill. Most of my code is in legacy c++ libraries, which I do not intend on abandoning, and I cannot get Qt Creator to build the libraries for me, with the proper dependencies. I am left compiling my libraries with xCode and telling Qt Creator to link them as part of my Qt Quick application. This poses a serious workflow issue for me.
-
Hi and welcome to devnet,
Can you create a minimal example that reproduces this ?
-
I take a look and the *.cmake files included into the Qt5 distribution, and I didn't found any point on which they specify the _iphonesimulator variant of the libraries in the linking process.
So, I suspect you found a bug into the *.cmake import files produced by Qt distribution.
I don't know how to fix the *.cmake files, but I can suggest you a workaround in the meanwhile Qt developers find a solutions (of course, you need to provide a small example and file a bug to the bug reports).
The workaround is to copy the Qt/ios directory to Qt/ios_simulator and in this directory remove all non iphonesimulator libraries and rename the iphonesimulator libraries removing the "_iphonesimulator" suffix:
libQt5Core_iphonesimulator.a -> libQt5Core.a
and so on. -
Thanks for the workaround! I may give it a try. I am not too confident in any solution at this point, since xCode clearly does not appear to like the resulting project file generated by CMake. None of the build settings appear correct upon initial loading of the project file, yet xCode "seems" to know what to do.. emphasis on "seems"