Qt && firebase C++ SDK linking issues on iOS - c++

I have following build env:
host: OSX 10.12 Sierra
XCode 9.2
Qt 5.10.1 for iOS
QtCreator 4.7.0
firebase 5.2
and try to build my application from QtCreator for iOS with the firebase support, but it fails with following linking errors:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_FIRMessaging", referenced from:
objc-class-ref in firebase_messaging(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
"_OBJC_CLASS_$_FIRApp", referenced from:
objc-class-ref in firebase(app_ios_814e1620d4f88024cea4bade26623a67.o)
"_OBJC_CLASS_$_FIROptions", referenced from:
objc-class-ref in firebase(app_ios_814e1620d4f88024cea4bade26623a67.o) ld: symbol(s) not
found for architecture arm64 clang: error: linker command failed with
exit code 1 (use -v to see invocation)
I have simplified my project to following code:
== main.cpp ==
#include <QCoreApplication>
#include <firebase/app.h>
#include <firebase/messaging.h>
#include <firebase/util.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
::firebase::App *fapp = ::firebase::App::Create();
Q_UNUSED(fapp);
return a.exec();
}
and a project file is:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# Check for GOOGLE_FIREBASE_SDK environment variable.
ENV_GOOGLE_FIREBASE_SDK = $$(GOOGLE_FIREBASE_SDK)
# Or define GOOGLE_FIREBASE_SDK path here.
GOOGLE_FIREBASE_SDK =
isEmpty(ENV_GOOGLE_FIREBASE_SDK) {
isEmpty(GOOGLE_FIREBASE_SDK) {
message("GOOGLE_FIREBASE_SDK" environment variable not detected!)
}
}
INCLUDEPATH += $$(GOOGLE_FIREBASE_SDK)
INCLUDEPATH += $$(GOOGLE_FIREBASE_SDK)/include
SOURCES += \
main.cpp
FCM_LIBS_PATH = $$(GOOGLE_FIREBASE_SDK)/frameworks/ios/universal
message("FCM_LIBS_PATH = $$FCM_LIBS_PATH")
LIBS += -F$$FCM_LIBS_PATH \
-framework firebase_messaging \
-framework firebase \
-framework Foundation \
-framework UserNotifications \
-framework UIKit \
-framework CoreGraphics
The firebase SDK contains different frameworks directories for different architectures :
~/firebase_cpp_sdk/frameworks/ios/universal
~/firebase_cpp_sdk/frameworks/ios/amd64
~/firebase_cpp_sdk/frameworks/ios/i386
~/firebase_cpp_sdk/frameworks/ios/x86_64
~/firebase_cpp_sdk/frameworks/ios/armv7
As I see that error related to 'arm64' architecture, so, I have changed the project file LIBS to use 'arm64' instead of 'universal', but this does not help.
Also I tried to build the project from the XCode, using qmake's generated xcode.project file, but there are same error.
I looked on stackoverflow a similar issues, but that workarounds does not help:
I tried to remove the /Users/admin/Library/Developer/Xcode/DerivedData directory.
I tried to play with the XCode options "Build Settings -> Build Active Architecture Only -> yes|no"
I looked a code from the following projects:
qtcloudmessaging: https://github.com/qt/qtcloudmessaging
QtFirebase: https://github.com/Larpon/QtFirebase
But I don't understand why this linker error happens.. Maybe is it a qmake bug?

The error means the project lacks Firebase pod.
firebase_cpp_sdk alone is not enough, in addition, it requires Firebase Core library.
In order add Firebase lib, you should migrate to use cocoapods.
In the project's source root, run
pod init
a new file Podfile would be then generated.
Open the file, add the following line to the target
pod 'Firebase/Analytics'
and save the file.
After running
pod update
successfully, open the .xcworkspace and build as usual.

Related

Qt 5.3.2 on Mac Snow Leopard: ld: symbol(s) not found for architecture x86_64 [clang, objective-c and c++]

I read through many questions of the same nature, but didn't find something specific to what I needed.
I am compiling a project on Snow Leopard (10.6.8) and Qt 5.3.2.
In my program's main method I check if it's on mac and bring up a cocoa-based window, otherwise creating the standard QApplication and MainWindow configuration. I have an .mm objective-c class that contains the window code and when include its corresponding header file, it gives me this error:
Undefined symbols for architecture x86_64:
"QMacApplication::QMacApplication()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using modified code from QT's official github repo for qtmacextras, putting the cocoa window code into its own library which I can import and use in other applications. See https://code.qt.io/cgit/qt/qtmacextras.git/tree/examples/macextras/macfunctions?h=5.14, although I'm using the 5.3.2 compatible commit.
Why am I getting this error?
This error can come from a missing framework as other questions have pointed out.
But the reason for this particular error was that I was missing some lines in my project pro file.
I was using OBJECTIVE_SOURCES to include my .mm file, but I was not including OBJECTIVE_HEADERS with my header file -- even though it didn't contain any objective-c code and I already specified it in the HEADERS directive.
Here's a concise version of my .pro file:
TARGET = QMacApplication
TEMPLATE = lib
QT += widgets core macextras
QT_PRIVATE += gui-private core-private
QMAKE_CXXFLAGS_GNUCXX11 = -std=c++98
CONFIG -= c++11
load(qt_build_config)
ios {
LIBS_PRIVATE += -framework UIKit
} else {
LIBS_PRIVATE += -framework AppKit
}
SOURCES += \
window.cpp
HEADERS += qmacapplication.h\
qmacapplication_global.h \
window.h
OBJECTIVE_SOURCES += qmacapplication.mm
OBJECTIVE_HEADERS += qmacapplication.h
It compiles when I remove qmacapplication.h from the HEADERS directive, but it seems safe to leave it in as well.
This is using xcode 4.2 if it matters.

Linker error with GLFW on OS 10.10

I'm trying to compile the following
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
return 0;
}
just to verify that my GLFW installation is working. I use the terminal with
clang++ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -I/opt/local/include/ test.c
but I receive a linker error for the glfwInit function:
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in test-d8c21e.o
ld: symbol(s) not found for architecture x86_64
I have installed glfw with sudo port install glfw and followed every possible tutorial I've found. I can verify that the libglfw.dylib file can be found at /opt/local/lib/ as (I think) it should.
Any suggestions?
You need to link with GLFW[3] as well, e.g., add:
-L/opt/local/lib -lglfw3
If you have the pkgconfig port installed, you can also take advantage of that with:
clang `pkg-config glfw3 --cflags` test.c -o test \
`pkg-config glfw3 --static --libs`
You may not need the --static flag if you have: libglfw3.dylib, as opposed to using: libglfw3.a, but it doesn't hurt.
If you are using Xcode, you must add the libglfw3.a library when linking binaries.
Heres the trick
Show hidden folders. Paste this into terminal: defaults write com.apple.finder AppleShowAllFiles YES
Relaunch a finder window and navigate to Macintosh HD\usr
Drag the usr folder to the "Favorites" side in the terminal
In xcode, click the add "+" to link binaries, then click "Add Other"
navigate to the libglfw3.a and add it!
If it still does not work, here are some instructions that helped me.
https://engineering-game-dev.com/2013/08/14/glfw-compiling-source-and-creating-an-xcode-project/comment-page-1/#comment-1400

QtCreator: symbol(s) not found for architecture x86_64 issue on Mac OS Mavericks

I am trying to compile a C++ program using Qt. When I try to compile I get this output:
symbol(s) not found for architecture x86_64
linker command failed with exit code 1 (use -v to see invocation)
What can I do? Why is this happening? I already tried setting
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
(as suggested in this post OpenCv + mac os x + qt creator = strange linking bug?) in my project file but it did not resolve the issue.
Any ideas?
EDIT:
This is what my project file looks like:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
a.cpp \
b.cpp \
c.cpp
HEADERS += \
a.h \
b.h \
c.h
I get this error when I have prototyped methods in a header file but not defined them in a source file, or if a function is prototyped but not defined. Make sure all the prototyped functions and class methods have definitions.

OpenCv + mac os x + qt creator = strange linking bug?

I'm trying to build simple OpenCV app using qt creator on Mac Os X 10.9. So i've installed OpenCv and Qt4 using brew:
brew install opencv
brew install qt4
and then downloaded qt creator. Than i've made simple project - main.cpp:
#include <QCoreApplication>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat m;
m = Mat(2, 3, 4);
cv::threshold(m, m, 123, 200, 1);
m = cv::imread("asdasd", 1); //problem is here!
return a.exec();
}
and .pro file:
QT += core
QT -= gui
TARGET = opencv_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_objdetect \
-lopencv_calib3d
INCLUDEPATH += /usr/local/include/opencv
DEPENDPATH += /usr/local/include/opencv/include
INCLUDEPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/lib
Now the weird part - if i comment this line: m = cv::imread("asdasd", 1); //problem is here! and build project, everything is fine - it will compile and link without any problem. So it seems that .dylib files are ok, because i can use OpenCV functions - Mat object constructor and threshold function. But! If i don't comment line with imread i get this error: :-1: błąd:symbol(s) not found for architecture x86_64 or to be more precise:
Undefined symbols for architecture x86_64: "cv::imread(std::string
const&, int)", referenced from:
_main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Generally the problem is just a part of bigger problem - i'm trying to build much bigger project using qt creator, but linker can't find some(but not all!) functions. In project which uses lot of OpenCV functions linker has got problems only with:
cv::VideoCapture::VideoCapture(std::string const&)
cv::destroyWindow(std::string const&)
cv::CascadeClassifier::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)
cv::CascadeClassifier::CascadeClassifier(std::string const&)
cv::imshow(std::string const&, cv::_InputArray const&)
In this project i'm using much more functions (mostly basic image processing - threshold, image copying, drawing basic primitives, finding contours) and linker can handle them without any problem.
What i've already tried - building OpenCv and Qt4(only using build brew install qt4 --from-source) from sources. I've builded OpenCv using this tutorial - http://sadeepj.blogspot.com/2012/03/installing-and-configuring-opencv-to.html I've also tried a lot of CMAKE options - -DCMAKE_OSX_ARCHITECTURES=x86_64 or i386 and -DCMAKE_CXX_FLAGS="-stdlib=libc++". I've also tried to build it using gcc(defautt compiler is clang) version 4.2, but it failed(building failed).
i've tried with OpenCV 2.4.8 and 2.4.2.
Also i've tried to set:
CMAKE_CXX_FLAGS += -std=c++11
CMAKE_CXX_FLAGS += -stdlib=stdlibc++
Still no luck.
I've checked whether builded .dylib files are x86_64:
/usr/local/lib[master]$ lipo -info libopencv_core.dylib Non-fat file:
libopencv_core.dylib is architecture: x86_64
and whether highgui file contains any information about imread function(i know that it is not a proof that it export this function):
/usr/local/lib[master]$ nm libopencv_highgui.dylib | grep imread
00000000000069b0 T __ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
0000000000006ac0 t __ZN2cvL7imread_ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEiiPNS_3MatE
Information which might be important: Mac OS X 10.9, 64 bit.
/usr/local/lib[master]$ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
/usr/local/lib[master]$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Btw - isn't it strange that running gcc --version in fact runs clang ?
So the question is - what can i do to compile and build it? Should i try using gcc or maybe something else will solve this problem? Also - if someone could upload his libraries and share a link it, so i could try with them it would be great. Any solution that will solve this problem will be fine for me - i can build everything from source, use any compiler, linker, etc.. - just help me make it working and i will be happy :)
Ok - finally after 4 days of searching i've solved this problem. Generally solution is simple - just add:
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
to you .pro file. If don't want to add it to every .pro file you can set it "globally" - just set it in this file:
Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf
More information about this bug/problem:
Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2, Undefined symbols for architecture x86_64
http://qt-project.org/forums/viewthread/35646/ <-- mostly here
//edit:
This solution only works with CLang, no luck with gcc.

_xnForceShutdown openni symbol not found

I had been trying to get OpenNI work on my Mac OS X 10.7. I installed the latest unstable binaries of OpenNI, NITE and Sensor from openni.org. The (precompiled) sample examples from OpenNI work fine but as soon as I write something of my own, it starts to fail.
For example, see below:
Undefined symbols for architecture x86_64:
"_xnForceShutdown", referenced from:
xn::Context::SetHandle(XnContext*) in sample.o
"_xnContextUnregisterFromShutdown", referenced from:
xn::Context::SetHandle(XnContext*) in sample.o
"_xnContextRelease", referenced from:
xn::Context::SetHandle(XnContext*) in sample.o
"_xnContextAddRef", referenced from:
xn::Context::SetHandle(XnContext*) in sample.o
"_xnContextRegisterForShutdown", referenced from:
xn::Context::SetHandle(XnContext*) in sample.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: * [AsusCamera] Error 1
My code is as follows:
#include "XnOpenNI.h"
#include "XnCppWrapper.h"
using namespace xn;
extern "C" int printf(const char *, ...);
int main() {
Context context;
printf("hello world\n");
context.Release();
return 1;
};
Please help me. I already tried re-installing the libs several times.
I've just compiled your code on OSX (albeit 10.6.8) using Qt Creator and Xcode and it works.
The undefined symbols usually means you haven't linked to the library(dylib) the header files reference, so link libOpenNI.dylib to your project.
In Qt Creator I have this setup:
QT += core
QT -= gui
TARGET = niTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/include/ni/
LIBS += /usr/lib/libOpenNI.dylib
In XCode I've dragged libOpenNI.dylib onto the project and ticked the "Copy items into desintation group's folder (if needed)", had /usr/include/ni/ path added to the header search path. Note that depending on what feature you end up using in OpenNI/NITE, you will need to link to other libraries as well (e.g. libnimCodecs,libXnCore,etc.)