Include System Library with qmake on osx - c++

i have a working cmake project that i need to move to qmake.
Everything is working but the include of a library called octomap.
I installed ( sudo make install ) octomap in system
/usr/local/lib/liboctomap.a
/usr/local/lib/liboctomap.dylib
and the headers in
/usr/local/lib/include/octomap/
Lets say project is so composed:
foo.h
...
#include <octomap/OcTree.h>
octomap::OcTree tree(0.1);
...
foo.cpp
...
#include <octomap/OcTree.h>
using namespace octree;
tree.doSomething();
...
foo.pro
...
unix|win32: LIBS += -loctomap
INCLUDEPATH += /usr/local/include/
...
Compiling results in a error: symbol(s) not found for architecture x86_64 due to
Undefined symbols for architecture x86_64:
"octomap::OcTreeNode::createChild(unsigned int)", referenced from:
octomap::OccupancyOcTreeBase<octomap::OcTreeNode>::updateNodeRe...[a very long stack]
That should means that octomap library has not be linked, and i tried also adding it in the project, using pkgconfig and using an absolute path. They all result in same error, while if i use it in a cmake project it works fine.

It was just a missing library, i also had to include the octomath lib
unix|win32: LIBS += -L/usr/local/lib/ -loctomap
unix|win32: LIBS += -L/usr/local/lib/ -loctomath
hope can be useful to someone.

Related

Link dylib in macOs QT project

I tried a simple dylib in macOS and compiled with g++. I made a small sample to test the lib, it works perfect.
Now I made a simple QT app, linked the lib and added the header to the mainwindow.cpp and I always got a fail message Reason: image not found
I read the web and also some other cases here but all is basing on paths.I think it is is not a path problem. Because I made all changes I read in all the cases and also copied the lib in all needed folders, like project folder, build folder. Nothing helps.
I think that QT cannot work with the library and I missed some needed code, like for initialize or export. So that the problem is more inside the dylib and not in QT or Paths values.
Maybe someone can help me here out?
I have tried:
INCLUDEPATH += $$PWD/mylib
DEPENDPATH += $$PWD/mylib
macx: LIBS += -L$$PWD/mylib/ -lmylib
I tried to copy the lib to the build folder and also to the executable folder.
Also edited:
/⁨Users⁩/⁨ingoforster⁩/Documents⁩/Development⁩/Playground⁩/TestGround⁩/mylib:/Users/ingoforster/Qt/5.9.1/clang_64/lib
in Project settings DYLD_LIBRARY_PATH
Set also to DYLD_FRAMEWORK_PATH
Cpp
#include "mylib.hpp"
char *mMessage(void) {
return "Ein sonniger Tag";
}
header
#include <stdio.h>
#include <iostream>
using namespace std;
char *mMessage(void);
compiled with
g++ -std=c++0x --verbose -dynamiclib -o libmylib.dylib mylib.cpp
Sample
#include "mylib.hpp"
int main(void){
char* Ingo = mMessage();
std::cout << mMessage();
}
compiled with
g++ -std=c++0x test.cpp -L./ -lmylib
Actual result is that the sample runs perfect.
But in QT I got:
dyld: Library not loaded: libmylib.dylib
Referenced from: /Users/ingoforster/Documents/Development/Playground/build-TestGround-Desktop_Qt_5_9_1_clang_64bit-Debug/TestGround.app/Contents/MacOS/TestGround
Reason: image not found
10:09:05: The program has unexpectedly finished.
10:09:05: The process was ended forcefully.
/Users/ingoforster/Documents/Development/Playground/build-TestGround-Desktop_Qt_5_9_1_clang_64bit-Debug/TestGround.app/Contents/MacOS/TestGround appears to be compile-linked to your library code but perhaps has not been formally installed to the executable. macdeployqt usually deals with this issue.
You may also do this manually with otool and install_name_tool:
otool -L /path/to/executable
This will list the installed paths to the dylibs in use. You will see your dylib, that is the "/old/path/to/libmylib.dylib"
install_name_tool -change /old/path/to/libmylib.dylib /new/path/to/libmylib.dylib /path/to/executable
Usually, in an .app, the dylib is installed to a subdirectory within the .app folder.
Application.app/
Contents/
MacOS/
executable
Frameworks/
libmylib.dylib
With install_name_tool you can point to the dylib relative to the executable path to make the app portable.
install_name_tool -change /old/path/to/libmylib.dylib #executable_path/../Frameworks/libmylib.dylib /path/to/executable
After some hard investigation and running into the wrong direction with the given answers here I found out, that QTCreator will do all its own:
QTCreator Pro file have to contain:
macx: LIBS += -L$$PWD/mylib/ -lmylib
INCLUDEPATH += $$PWD/mylib
DEPENDPATH += $$PWD/mylib
MediaFiles.files += mylib/libmylib.dylib
MediaFiles.path = Contents/MacOS
QMAKE_BUNDLE_DATA += MediaFiles

_Unwind_Resume not found when linking to boost statically but not dynamically on osx

I am working on a shell script to run qmake commands to build a project on OSX.
I was getting this error after updated to Xcode 7.1.2 (which I had to do because nothing would build at all after upgrading to yosemite before I updated XCode):
Undefined symbols for architecture x86_64:
"__Unwind_Resume", referenced from:
It turns out that qmake was generating a makefile with the flag -mmacosx-version-min=10.5 and changing that with sed to 10.9 did the trick.
But, now I have a problem caused by linking to 4 or 5 boost libraries (got with homebrew) and another dynamic library (libbar64.dylib) that I wrote. Here is the stripped down version of the build script:
#!/bin/bash
PROJECT="foo"
# to find the dylib
install_name_tool -id "#executable_path/../Resources/libbar64.dylib"
# moc and uic
$QMAKEPATH/uic mainwindow.ui -o ui_mainwindow.h
$QMAKEPATH/moc mainwindow.h -o moc_mainwindow.cpp
# library paths and libs
libpath="-L/usr/local/Cellar/boost/1.59.0/lib/ -L/usr/local/lib -L./"
libs="-lbar64 -lboost_thread-mt -lboost_system-mt -lboost_chrono-mt -lboost_iostreams-mt -lboost_exception-mt -lboost_filesystem-mt"
# make pro file
$QMAKEPATH/qmake -project
echo 'LIBS +=' $libpath $libs >> $PROJECT.pro
# generate the makefile
$QMAKEPATH/qmake -spec macx-g++ $PROJECT.pro
# kludge
sed -i -e 's/min=10.5/min=10.9/g' Makefile
# make it
make
# put libbar into the resources folder
cp ./libbarl64.dylib $PROJECT.app/Contents/Resources/
The problem arises because the shared boost libraries aren't known to foo after its built. I could set DYLD_LIBRARY_PATH to the boost directory /usr/local/Cellar/boost/1.59.0/lib/ but I don't want to do that (because of this).
I tried to change my libs variable to:
libs="-shared -lbar64 -static -lboost_thread-mt -lboost_system-mt -lboost_chrono-mt -lboost_iostreams-mt -lboost_exception-mt -lboost_filesystem-mt"
But now I get the
Undefined symbols for architecture x86_64:
"__Unwind_Resume", referenced from:
error again. Does anyone know how to get around this without swapping environment variables? I never had problems of this kind until the latest OSX updates. I want to link to boost statically, but it seems be in opposition with libgcc_eh.a libarary for some reason. I hate it when Apple updates break my build scripts.

cv::VideoCapture from string gives linker error in Qt5 on Mac

Problem
I am trying to get the OpenCV VideoCapture class running in a Qt project.
When I call it with an int (0 for the video camera on my mac), it works fine:
#include "opencv2/opencv.hpp"
#include <opencv2/highgui/highgui.hpp>
...
cv::VideoCapture cap(0);
The project compiles and when I run it, the light on my camera goes on.
BUT: when I try to compile it with a std::string as argument, I get a linker error:
#include "opencv2/opencv.hpp"
#include <opencv2/highgui/highgui.hpp>
...
cv::VideoCapture cap("/Users/xxxxx/small.mp4");
results in:
Undefined symbols for architecture x86_64:
"cv::VideoCapture::VideoCapture(std::string const&)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
althought the constructor from std::string should actually exist:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-videocapture
Settings
My specifications:
Qt 5.4.0 (Clang 6.0 (Apple), 64 bit)
Mac OSX 10.10.1
OpenCV 2.4.9 installed from homebrew
My .pro file:
QT += core gui widgets
TARGET = VideoCaptureTest
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_videostab
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
What I tried
1.
I found this question on SO, which seems to be the exact same problem as mine:
Linking error: undefined reference to `cv::VideoCapture::open(std::string const&)`
It seem my problem could have something to do with clashing versions of OpenCV. But I checked my include directories and my lib directories and I seem to only have 2.4.9 installed. Is there maybe a different version that comes with Qt?
I tried including version 2.4.9 directly in my .pro file with
LIBS += -lopencv_core2.4.9
...
But how can I make sure I include this version as well in my source file?
2.
I though it might have something to do with Mac and x86_64 stuff. I included the following lines, which I found somewhere online, in my .pro file:
CONFIG += x86 ppc x86_64 ppc64
CONFIG += MAC_CONFIG
MAC_CONFIG {
QMAKE_CXXFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7
QMAKE_LFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7
}
But this also showed no effect.
3.
Here (http://answers.opencv.org/question/14772/solved-linking-error-undefined-reference-to-cvvideocaptureopenstdstring-const/) it is suggested to try cv::String instead of std::string. I also tried this:
#include "opencv2/opencv.hpp"
...
cv::String s("/Users/xxxxx/small.mp4");
cv::VideoCapture cap(s);
and strangely I still get the exact same error:
Undefined symbols for architecture x86_64:
"cv::VideoCapture::VideoCapture(std::string const&)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
which seems like the cv::String is actually converted to std::string, I guess because the compiler somewhere finds the definition of the constructor with std::string, but the linker does not?
4.
Apparently there was a similar problem with OSX 10.9, not with cv::VideoCapture, but in general resulting also in linking error for x86_64. The solution was to include
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
in the .pro file. I tried this as well with 10.9 and 10.10 (which I am actually using). Still the same error. Could this be a problem with my version of OSX?
Help
I found no other suggestions on how to solve the problem. Does somebody have an idea what I am doing wrong? Any help appreciated!
Patrick
The answer has been given in the discussion(#wezside) of the link (item 1 of your description).
for OpenCV 3.0 (also 2.4.9 ?)
you need to add
LIBS += -lopencv_videoio
to the .pro, which is missing in yours.
After researching for several hours, I found that adding QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11 to your .pro file and removing the previous .pro.user file and build directory can solve the problem. The second step is required.
I'm on El Capitan.

How do I use the Boost libraries in a qmake project?

Some days ago I compiled Boost ver. 1.53.0 for VS2012. It works fine, compiles fine. Now I want to use Boost with Qt Creator. In the .pro file I've included
INCLUDEPATH += C:\boost\boost_1_53_0\ -lboost_filesystem
LIBS += C:/boost/boost_1_53_0/stage/lib/
But when I compile I get 2 errors:
:-1: error: cannot find C:/boost/boost_1_53_0/stage/lib/: Permission denied
collect2.exe:-1: error: error: ld returned 1 exit status
What should I do? I've googled but seems I'm the first with this error.
INCLUDEPATH += C:\boost\boost_1_53_0\ -lboost_filesystem
LIBS += C:/boost/boost_1_53_0/stage/lib/
Wrong.
Read this.
Solution:
INCLUDEPATH += C:/boost/boost_1_53_0/
LIBS += "-LC:/boost/boost_1_53_0/stage/lib/"
Boost has complicated library names ("libboost_filesystem-vc90-mt-1_53.lib") and in case of msvc it links them automatically.)
If you want to link additional lib, you do it like this:
LIBS += "-LMyLibraryPath" -lmylib
Where MyLibraryPath is library path, and mylib is library you want to link with.
i'm the first with this error.
The error most likely occurs because compiler tries to open directory as if it were a file or something like that.
win32 {
INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0
LIBS += "-LC:/dev/Boost/lib/" \
"-Llibboost_filesystem-mgw53-mt-d-1_61.a", "-Llibboost_system-mgw53-mt-d-1_61.a", "-Llibboost_serialization-mgw53-mt-d-1_61.a" -LLIBS
}

QMake and wxWidgets (External Libraries)

I'm trying to compile a GUI program based on the wxWidgets libraries. I get a lot of undefined references to "something". I tried to add a few libraries manually on the LIBS variable of QMake without success. How can i add all the wxWidgets libraries to QMake without hard coding each library? Below is my .pro file.
# simple.pro
TARGET = sample
HEADERS += main.h simple.h
SOURCES += main.cpp simple.cpp
LIBS += -LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_core_gcc.dll \
-LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_gcc.dll \
-LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_aui_gcc.dll
INCLUDEPATH += C:/SourceCode/Libraries/wxWidgets2.8/include
CONFIG += release
The errors are of the form:
release/simple.o:simple.cpp:(.rdata$_ZTV6Simple[vtable for
Simple]+0x320): undefined reference to
`wxFrameBase::SetStatusBar(wxStatusBar*)'
First, you need to use the .a files to add to the linker.
Then you need to define WXUSINGDLL if you link against the shared libraries.
Additionally, you forgot
wxbase29u.a
Hope that helps.