"Undefined symbols for arch. i386" when including C++ library in iOS simulator build
-
Hi all,
I have been struggling for a long time to include the simplest C++ library in a Qt Quick iOS application. I'm able to include C++ code directly in the project, but not from a lib. Any help would be highly appreciated. I use Qt for iOS and Android 5.5.0, Qt creator 3.4.2 and Xcode 6.4.
- First I start a new project and choose the C++ library template. I have tried to choose both shared and static library.
This is my header file with an empty constructor.
#ifndef TESTLIB_STATIC_H #define TESTLIB_STATIC_H class Testlib_static { public: Testlib_static(); void void_testBeskjed(); }; #endif // TESTLIB_STATIC_H
And this is the .pro file:
\#------------------------------------------------- \# \# Project created by QtCreator 2015-10-01T11:14:00 \# \#------------------------------------------------- QT -= gui TARGET = testlib_static TEMPLATE = lib CONFIG += staticlib SOURCES += testlib_static.cpp HEADERS += testlib_static.h unix { target.path = /usr/lib INSTALLS += target } QMAKE_IOS_DEPLOYMENT_TARGET = 8.4
-
I build this library with the iphonesimulator-clang toolkit. I have Xcode 6.4 installed. Then I run lip to check the file:
$lipo -info libtestlib_static.a
Architectures in the fat file: libtestlib_static.a are: i386 x86_64 -
Then I start a new project and choose the Qt Quick Application.
I right click the project and select add external library and select the libtestlib_static.a which I have built. It says it will be linked statically, both when I have tried to create a shared and static library in point 1 above.
- I create a Testlib_static object in the Qt Quick application, but get the compile/link error described in the beginning.
#include <QApplication> #include <QQmlApplicationEngine> #include <testlib_static.h> int main(int argc, char *argv[]) { Testlib_static lib; QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
Here is the .pro file of my project:
TEMPLATE = app QT += qml quick widgets SOURCES += main.cpp RESOURCES += qml.qrc QMAKE_IOS_DEPLOYMENT_TARGET = 8.4 # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Default rules for deployment. include(deployment.pri) macx: LIBS += -L$$PWD/../testlib_static/build-testlib_static-iphonesimulator_clang_Qt_5_5_0_ios-Debug/ -ltestlib_static INCLUDEPATH += $$PWD/../testlib_static/testlib_static DEPENDPATH += $$PWD/../testlib_static/testlib_static macx: PRE_TARGETDEPS += $$PWD/../testlib_static/build-testlib_static-iphonesimulator_clang_Qt_5_5_0_ios-Debug/libtestlib_static.a
- Here is the error message. I can not figure out why the i386 is missing:
Undefined symbols for architecture i386: "Testlib_static::Testlib_static()", referenced from: _qtmn in main.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) ** BUILD FAILED ** The following build commands failed: Ld Debug-iphonesimulator/qtQuick_testJon.app/qtQuick_testJon normal i386 (1 failure) make[1]: *** [iphonesimulator-debug] Error 65 make: *** [debug-iphonesimulator] Error 2 11:05:27: The process "/usr/bin/make" exited with code 2. Error while building/deploying project qtQuick_testJon (kit: iphonesimulator-clang Qt 5.5.0 (ios)) When executing step "Make" 11:05:27: Elapsed time: 00:03.
-
So I finally found a part in the documentation saying:
PRE_TARGETDEPS
Lists libraries that the target depends on. Some backends, such as the generators for Visual Studio and Xcode project files, do not support this variable. Generally, this variable is supported internally by these build tools, and it is useful for explicitly listing dependent static libraries.Apparently I have to include the lib manually in the .xcodeproj file. That worked, but isn't Add Library... supposed to add the necessary commands to the .pro file?