Build static library but symbols not found for architecture x86_64 in iOS
-
wrote on 10 Jan 2022, 11:14 last edited by
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:

My code C++:

My error when add the static library in xcode:
Thanks in advance for any help.
-
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:

My code C++:


My error when add the static library in xcode:
Thanks in advance for any help.
This post is deleted! -
Lifetime Qt Championwrote on 10 Jan 2022, 19:27 last edited by SGaist 1 Oct 2022, 19:28
Hi and welcome to devnet,
Can you share the content of your CMakeLists.txt file ?
-
wrote on 10 Jan 2022, 21:21 last edited by hskoglund 1 Oct 2022, 22:45
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, 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
wrote on 11 Jan 2022, 01:54 last edited by@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.
-
wrote on 11 Jan 2022, 08:21 last edited by
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.oIn 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)
6/7