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. Build static library but symbols not found for architecture x86_64 in iOS
Forum Updated to NodeBB v4.3 + New Features

Build static library but symbols not found for architecture x86_64 in iOS

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 4 Posters 2.5k Views 1 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.
  • C Offline
    C Offline
    cadory
    wrote on last edited by
    #1

    Hi,
    I've had trouble using a static library built by qt c++. The error shown in Xcode is:
    " Undefined symbols for architecture x86_64:
    "_add", referenced from:
    -[ViewController viewDidLoad] in ViewController.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation) "

    My config in Qt:
    ![qt config](Screen Shot 2022-01-10 at 18.08.19.png image url)

    My code C++:
    ![file cpp](Screen Shot 2022-01-10 at 18.10.00.png image url)

    ![file header](Screen Shot 2022-01-10 at 18.10.18.png image url)

    My error when add the static library in xcode:
    Screen Shot 2022-01-10 at 09.11.40.png

    Thanks in advance for any help.

    jsulmJ 1 Reply Last reply
    0
    • C cadory

      Hi,
      I've had trouble using a static library built by qt c++. The error shown in Xcode is:
      " Undefined symbols for architecture x86_64:
      "_add", referenced from:
      -[ViewController viewDidLoad] in ViewController.o
      ld: symbol(s) not found for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation) "

      My config in Qt:
      ![qt config](Screen Shot 2022-01-10 at 18.08.19.png image url)

      My code C++:
      ![file cpp](Screen Shot 2022-01-10 at 18.10.00.png image url)

      ![file header](Screen Shot 2022-01-10 at 18.10.18.png image url)

      My error when add the static library in xcode:
      Screen Shot 2022-01-10 at 09.11.40.png

      Thanks in advance for any help.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #3

        Hi and welcome to devnet,

        Can you share the content of your CMakeLists.txt file ?

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

        C 1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by hskoglund
          #4

          Hi, linking with a static c++ library should work fine on the iPhone, but since Objective-C was invented before C++ it has no knowledge of c++ name mangling.

          Either you rewrite your static library in plain C, or a better solution, change all of your Objective-c with extension .m to instead have the extension .mm. Edit: forgot:
          except main.m, that file keeps the .m extension
          . Now the name mangling should work.

          Also check that you have a -L and -l linking directive for Xcode, for example you can put it in the "Other Linker Flags" in Xcode's Linking setting for your project, eg:

          -L /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator
          -l Hello
          

          and verify that you have a static library libHello.a in that folder: /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator

          C 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            Can you share the content of your CMakeLists.txt file ?

            C Offline
            C Offline
            cadory
            wrote on last edited by
            #5

            @SGaist Hi, There is my CMakeLists.txt file:
            ![alt text](Screen Shot 2022-01-11 at 07.57.42.png image url)

            1 Reply Last reply
            0
            • hskoglundH hskoglund

              Hi, linking with a static c++ library should work fine on the iPhone, but since Objective-C was invented before C++ it has no knowledge of c++ name mangling.

              Either you rewrite your static library in plain C, or a better solution, change all of your Objective-c with extension .m to instead have the extension .mm. Edit: forgot:
              except main.m, that file keeps the .m extension
              . Now the name mangling should work.

              Also check that you have a -L and -l linking directive for Xcode, for example you can put it in the "Other Linker Flags" in Xcode's Linking setting for your project, eg:

              -L /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator
              -l Hello
              

              and verify that you have a static library libHello.a in that folder: /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator

              C Offline
              C Offline
              cadory
              wrote on last edited by
              #6

              @hskoglund said in Build static library but symbols not found for architecture x86_64 in iOS:

              Hi, linking with a static c++ library should work fine on the iPhone, but since Objective-C was invented before C++ it has no knowledge of c++ name mangling.

              Either you rewrite your static library in plain C, or a better solution, change all of your Objective-c with extension .m to instead have the extension .mm. Edit: forgot:
              except main.m, that file keeps the .m extension
              . Now the name mangling should work.

              Also check that you have a -L and -l linking directive for Xcode, for example you can put it in the "Other Linker Flags" in Xcode's Linking setting for your project, eg:

              -L /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator
              -l Hello
              

              and verify that you have a static library libHello.a in that folder: /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator

              Hi, thanks for your support. I have tried it but have the same problem.
              Screen Shot 2022-01-11 at 08.24.40.png

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #7

                Hi, check that all Objective-C files using your static library have an extension .mm (not .m) (If ViewController.mm is the only file calling into your static library then it's ok now.)

                Check that you have a valid libHello.a file in your directory /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator, start a Terminal and type:

                ar -t /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator/libHello.a
                

                the output should be:
                __.SYMDEF SORTED
                Hello.o

                In Xcode, check that you have the the linking directive:

                 -L /Users/vietanh/build-Hello-Qt_6_2_2_for_iOS_Simulator/Debug-iphonesimulator -l Hello
                

                (note: -l libHello or -l libHello.a do not work)

                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