QT IOS linker error entry point (_main) undefined

Viewed 1139

I am currently trying to compile a QT based project on IOS. I am using cmake to create and configure the .xcodeproject and xcode to run the app on the device.

I succeed to remove all the previous linker error and now i am dealing with the entry point.

My main.cpp looks like that

    int main(int argc, char **argv) {
        QApplication app(argc, argv);
        return app.exec();
     }

this got me the following 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 QApplication is from within 'applicationDidFinishLaunching' inside your UIApplication delegate.

I found on this post that you should rename the main and qt will do the job for you and launch the application life cycle

Run-time error for Qt application on ios built via CMake

Qt XCode iOS entry point

#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) undefined. for architecture arm64

In the first post they say that i should have a your/qt/root/path/mkspecs/macx-ios-clang/rename_main.sh script

I got none, in the other post the answer says to:

renaming main -> qtmn (in qt sourced), rebuilt QT, and called qt_main_wrapper from my main().

but I don't know what sould i do with the "rebuilt and called qt_main_wrapper"

2 Answers

I just tested with Qt 5.15.1, and most of the CMake iOS build problems now appear to have been fixed. The only ad-hoc project setting left is

set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-Wl,-e,_qt_main_wrapper")

This will also be fixed when https://bugreports.qt.io/browse/QTBUG-87060 is released as part of Qt 6.

Related