Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. "Undefined symbols for arch. i386" when including C++ library in iOS simulator build

"Undefined symbols for arch. i386" when including C++ library in iOS simulator build

Scheduled Pinned Locked Moved Mobile and Embedded
iosstatic libraryc++mac
2 Posts 1 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jonei
    wrote on last edited by
    #1

    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.

    1. 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
    
    1. 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

    2. 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.

    1. 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
    
    1. 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.
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      jonei
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved