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. Calling native function of an iOS static library (Objective-C code) from a QT widget based application
Forum Updated to NodeBB v4.3 + New Features

Calling native function of an iOS static library (Objective-C code) from a QT widget based application

Scheduled Pinned Locked Moved Mobile and Embedded
10 Posts 4 Posters 4.5k Views 3 Watching
  • 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.
  • S Offline
    S Offline
    sachin.srinath
    wrote on 9 Apr 2015, 12:23 last edited by
    #1

    Hi All,

    I am having a simple Qt 5.4 widget based application and I am trying to call a native function (member function of an Objective-C class) that I have written. I followed the solution posted on this link : https://forum.qt.io/topic/46793/solved-using-objective-c-class-in-qt-c.
    Unfortunately I am still getting the error mentioned in the above link :

    symbol(s) not found for architecture ...
    linker command failed with exit code 1 ...

    I would like to know

    1. If there is any standard (QT prescribed) way of calling native code from QT application (widget based).
    2. If it is possible to call a native function from an iOS static library (from .a library and not by including the source files in QT project)

    Thanks in advance...

    B 1 Reply Last reply 10 Apr 2015, 17:07
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Apr 2015, 22:40 last edited by
      #2

      Hi and welcome to devnet,

      1. You can have a look at the qtmacextras module to see how you can use Objective-C++
      2. What symbols are missing ? Are you linking to that library properly ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sachin.srinath
        wrote on 10 Apr 2015, 05:07 last edited by
        #3

        Hi,
        Thanks for the reply.

        1. Ok, I will have a look at qtmacextras
        2. The error I am getting is - "symbol(s) not found for architecture x86_64". I am new to QT and I am not sure if I am linking the library properly. Can you please guide me on this?
          Also, is it better to use QT Creator or XCode if I need to mix QT and Objective-C++ code ?
        S 1 Reply Last reply 10 Apr 2015, 10:23
        0
        • S sachin.srinath
          10 Apr 2015, 05:07

          Hi,
          Thanks for the reply.

          1. Ok, I will have a look at qtmacextras
          2. The error I am getting is - "symbol(s) not found for architecture x86_64". I am new to QT and I am not sure if I am linking the library properly. Can you please guide me on this?
            Also, is it better to use QT Creator or XCode if I need to mix QT and Objective-C++ code ?
          S Offline
          S Offline
          sandy.martel23
          wrote on 10 Apr 2015, 10:23 last edited by
          #4

          You are giving us an incomplete error message.
          Look in the "Compile output" view to see what symbols are not found.

          1 Reply Last reply
          0
          • S sachin.srinath
            9 Apr 2015, 12:23

            Hi All,

            I am having a simple Qt 5.4 widget based application and I am trying to call a native function (member function of an Objective-C class) that I have written. I followed the solution posted on this link : https://forum.qt.io/topic/46793/solved-using-objective-c-class-in-qt-c.
            Unfortunately I am still getting the error mentioned in the above link :

            symbol(s) not found for architecture ...
            linker command failed with exit code 1 ...

            I would like to know

            1. If there is any standard (QT prescribed) way of calling native code from QT application (widget based).
            2. If it is possible to call a native function from an iOS static library (from .a library and not by including the source files in QT project)

            Thanks in advance...

            B Offline
            B Offline
            Ben Lau
            wrote on 10 Apr 2015, 17:07 last edited by
            #5

            @sachin.srinath said:

            1. If there is any standard (QT prescribed) way of calling native code from QT application (widget based).
            2. If it is possible to call a native function from an iOS static library (from .a library and not by including the source files in QT project)

            It may not have a standard way of calling native code. I just made my own solution , and available at :
            https://github.com/benlau/quickios/blob/master/qisystemutils.mm#L362

            The native code is written in .mm file. C++ code won't be able to call them directly. Instead , all the native code registers their exported functions on a messenger class. And C++ code access those functions via the messenger class too. That make the code be able to be compiled on other platform. (e.g having a CI server in Linux , use it to run test case related to data model)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sachin.srinath
              wrote on 13 Apr 2015, 09:18 last edited by
              #6

              @sandy.martel23
              Here is the complete error:

              14:29:15: Running steps for project try1...

              14:29:15: Configuration unchanged, skipping qmake step.

              14:29:15: Starting: "/usr/bin/make"

              /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/Users/BTL/Qt5.4.1_ios/5.4/clang_64/lib -o try1.app/Contents/MacOS/try1 native.o main.o mainwindow.o moc_mainwindow.o -F/Users/BTL/Qt5.4.1_ios/5.4/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL

              Undefined symbols for architecture x86_64:

              "_NSLog", referenced from:

              -[MyClass doSomething] in native.o

              "OBJC_CLASS$_NSObject", referenced from:

              OBJC_CLASS$_MyClass in native.o

              "OBJC_METACLASS$_NSObject", referenced from:

              OBJC_METACLASS$_MyClass in native.o

              "___CFConstantStringClassReference", referenced from:

              CFString in native.o

              "__objc_empty_cache", referenced from:

              OBJC_METACLASS$_MyClass in native.o

              OBJC_CLASS$_MyClass in native.o

              "__objc_empty_vtable", referenced from:

              OBJC_METACLASS$_MyClass in native.o

              OBJC_CLASS$_MyClass in native.o

              ld: symbol(s) not found for architecture x86_64

              clang: error: linker command failed with exit code 1 (use -v to see invocation)

              make: *** [try1.app/Contents/MacOS/try1] Error 1

              14:29:16: The process "/usr/bin/make" exited with code 2.

              Error while building/deploying project try1 (kit: Desktop Qt 5.4.1 clang 64bit)

              When executing step "Make"

              14:29:16: Elapsed time: 00:00.

              S 1 Reply Last reply 13 Apr 2015, 22:04
              0
              • S Offline
                S Offline
                sachin.srinath
                wrote on 13 Apr 2015, 09:23 last edited by
                #7

                @Ben-Lau

                Thanks for sharing the code. I will have a look at it.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 13 Apr 2015, 09:57 last edited by
                  #8

                  Is it me or are you trying to build something for iOS using the OS X Qt version ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S sachin.srinath
                    13 Apr 2015, 09:18

                    @sandy.martel23
                    Here is the complete error:

                    14:29:15: Running steps for project try1...

                    14:29:15: Configuration unchanged, skipping qmake step.

                    14:29:15: Starting: "/usr/bin/make"

                    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/Users/BTL/Qt5.4.1_ios/5.4/clang_64/lib -o try1.app/Contents/MacOS/try1 native.o main.o mainwindow.o moc_mainwindow.o -F/Users/BTL/Qt5.4.1_ios/5.4/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL

                    Undefined symbols for architecture x86_64:

                    "_NSLog", referenced from:

                    -[MyClass doSomething] in native.o

                    "OBJC_CLASS$_NSObject", referenced from:

                    OBJC_CLASS$_MyClass in native.o

                    "OBJC_METACLASS$_NSObject", referenced from:

                    OBJC_METACLASS$_MyClass in native.o

                    "___CFConstantStringClassReference", referenced from:

                    CFString in native.o

                    "__objc_empty_cache", referenced from:

                    OBJC_METACLASS$_MyClass in native.o

                    OBJC_CLASS$_MyClass in native.o

                    "__objc_empty_vtable", referenced from:

                    OBJC_METACLASS$_MyClass in native.o

                    OBJC_CLASS$_MyClass in native.o

                    ld: symbol(s) not found for architecture x86_64

                    clang: error: linker command failed with exit code 1 (use -v to see invocation)

                    make: *** [try1.app/Contents/MacOS/try1] Error 1

                    14:29:16: The process "/usr/bin/make" exited with code 2.

                    Error while building/deploying project try1 (kit: Desktop Qt 5.4.1 clang 64bit)

                    When executing step "Make"

                    14:29:16: Elapsed time: 00:00.

                    S Offline
                    S Offline
                    sandy.martel23
                    wrote on 13 Apr 2015, 22:04 last edited by
                    #9

                    @sachin.srinath

                    Looks like you are not linking with Foundation. Add

                    LIBS += -framework Foundation

                    To your .pro file.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sachin.srinath
                      wrote on 14 Apr 2015, 08:25 last edited by
                      #10

                      @sandy.martel23
                      Thanks very much. Its working fine now.

                      Thanks everyone for helping me.

                      1 Reply Last reply
                      0

                      1/10

                      9 Apr 2015, 12:23

                      • Login

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