Build static library but symbols not found for architecture x86_64 in iOS
-
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]( image url)My code C++:
![file cpp]( image url)![file header]( image url)
My error when add the static library in xcode:
Thanks in advance for any help.
-
Hi and welcome to devnet,
Can you share the content of your CMakeLists.txt file ?
-
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
-
@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.
-
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)