IOS QT linker error entry point (_main) is undefined
I am currently trying to compile a QT based project on IOS. I am using cmake to create and configure .xcodeproject and xcode to run my app on a device.
I manage to remove all the previous linker error and now I am dealing with an entry point.
My main.cpp looks like this
int main(int argc, char **argv) {
QApplication app(argc, argv);
return app.exec();
}
this threw an error:
Error: You are creating QApplication before calling UIApplicationMain. If you are writing a native iOS application and only want to use Qt for parts of the application, a good place to create a QApplication is from within 'applicationDidFinishLaunching' inside your UIApplication to delegate.
I found in this post that you should rename main and qt will do the job for you and start the application lifecycle
Runtime error for Qt for ios application built with CMake
#if defined(Q_OS_IOS)
extern "C" int qtmn(int argc, char** argv) {
#else
int main(int argc, char **argv) {
#endif
QApplication app(argc, argv);
return app.exec();
}
but now i am dealing with this error
ld: entry point (_main) is undefined. for arm64 architecture
In the first post they say I must have your / qt / root / path / mkspecs / macx-ios-clang / rename_main.sh script
I don't have anything, in another post the answer answers:
renaming main -> qtmn (to qt sourced), restoring QT and calling qt_main_wrapper from my main ().
but i dont know what i can do with "rebuilt and called qt_main_wrapper"
source to share
The fix was adding linker flags
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-Wl,-e,_qt_main_wrapper")
Qt needs UIApplication to be instanciate, this application is defined inside UIKit. You can specify the definition of qt_main_wrapper inside: qtbase / src / plugins / platform / ios / qioseventdispatcher.mm
The -e parameter specifies a different entry point for your program, this will create this UIApplication.
If you follow the QApplication constructor, it will end up with the ios plugin and throw an error if the single unicast "UIApplication" is not installed.
Finally, if your application uses QML
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-u _qt_registerPlatformPlugin")
You will need to load all other plugin inside your main.cpp
Q_IMPORT_PLUGIN(QtQuick2Plugin)
and also add the path to .a in your LD Flags like:
set (LINK_LIBRARIES ${LINK_LIBRARIES} "${USE_QT_DIR}/qml/QtQuick/Controls.2/libqtquickcontrols2plugin_debug.a")
for QtControls2 you will also need to add
set (LINK_LIBRARIES ${LINK_LIBRARIES} "${USE_QT_DIR}/lib/libQt5QuickControls2_debug.a")
set (LINK_LIBRARIES ${LINK_LIBRARIES} "${USE_QT_DIR}/lib/libQt5QuickTemplates2_debug.a")
It's a little cumbersome, but you can run qmlimportscanner
, located at Qt / 5.7 / ios / bin in your project:
qmlimportscanner -rootPath path/to/app/qml/directory -importPath path/to/qt/qml/directory
This will give you JSON with all the plugin your project is using. This is a script called by qmake, if I have some time I will add a script to add another plugin later.
source to share