Calling native function of an iOS static library (Objective-C code) from a QT widget based application
-
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
- If there is any standard (QT prescribed) way of calling native code from QT application (widget based).
- 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...
-
Hi and welcome to devnet,
- You can have a look at the qtmacextras module to see how you can use Objective-C++
- What symbols are missing ? Are you linking to that library properly ?
-
Hi,
Thanks for the reply.- Ok, I will have a look at qtmacextras
- 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 ?
-
You are giving us an incomplete error message.
Look in the "Compile output" view to see what symbols are not found. -
@sachin.srinath said:
- If there is any standard (QT prescribed) way of calling native code from QT application (widget based).
- 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#L362The 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)
-
@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.
-
Thanks for sharing the code. I will have a look at it.
-
Is it me or are you trying to build something for iOS using the OS X Qt version ?
-
Looks like you are not linking with Foundation. Add
LIBS += -framework Foundation
To your .pro file.
-
@sandy.martel23
Thanks very much. Its working fine now.Thanks everyone for helping me.