Link dylib in macOs QT project - c++

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

Related

Failed to link openssl to Qt

I have started a project with Qtcreator on linux. This project uses the Openssl library to work.
So In my .pro file I have added theses lines :
LIBS += -lssl
LIBS += -lcrypto
So on linux it works perfectly.
But, I have to continue my project on windows. I had to install Openssl with cygwin, I have chosen this package : "cygwin32-openssl-1.0.1e-1.tar.bz2" because I compile in 32bits.
I have created a sub-repertory, named libs, in my program folder and I put the three openssl folders (bin, include and lib) in my "libs" repertory.
The content of the lib directory is :
libcrypto.a
libcrypto.dll.a
libssl.a
libssl.dll.a
pkgconfig/libcrypto.pc
pkgconfig/libssl.pc
pkgconfig/openssl.pc
In the bin directory I have 2 .dll, cygcrypto-1.0.0.dll and cygssl-1.0.0.dll
I added in my .pro file these lines :
LIBS += -lssl
LIBS += -lcrypto
LIBS += -L"$$PWD/libs/openssl/lib/"
INCLUDEPATH += $$PWD/libs/openssl/include/
If I change -L"$$PWD/libs/openssl/lib/" by -L"$$PWD/libs/openssl/bin/", the compilator don't recognized the -lssl and -lcrypto options.
QtCreator recognized the headers files (for example ) and when I compile, no error occurred.
But when I launch my program, it doesn't work and no error appears.
So I put a breaking point at the begining of my main function, and I re-launch the program. After that a little window indicates to me this error :
Executable failed: During startup program exited with code 0xc0000135
I use Qt 5.4.0 and Mingw 32bits
I don't undertsand why it doesn't work. Can you help me please ?
Thank you.
The entirety of your project needs to use cygwin, or none of it. Since I assume you're compiling using a Visual Studio compiler, you'll need to use an OpenSSL build that isn't cygwin-dependent. For example, the one from Shining Light Productions, the de-fact OpenSSL binary purveyor for Windows.

Include System Library with qmake on osx

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.

Qt C++ ffmpeg cannot find library

I use Qt 5.0.2 with Mingw 4.7 on windows.
I'm working on a c++ program and i'm trying to get the duration of video files. I found ffmpeg. Now i tried to compile a simple program but I think it fails with the libraries. I've tried to include both the shared and dev but they both will fail. ( Zeranoe FFmpeg builds)
This is my pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-shared\bin
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-shared\bin -lavcodec-55.dll - lavformat-55.dll -lavutil-52.dll
i get errors like:
":-1: error: cannot find -lavcodec-55.dll"
":-1: error: cannot find -lavformat-55.dll"
I've also tried:
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-dev\include
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-dev\lib
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-dev\lib -lavcodec -lavformat -lavutil
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-dev\lib -llibavcodec.dll.a -llibavformat.dll.a -llibavutil.dll.a
Here it gives a error "During startup program exited with code 0x0000135'
I even tried to include each library individually. But no results..
This is my main file:
#include <iostream>
using namespace std;
extern "C" {
#include <libavcodec/avcodec.h> // required headers
#include <libavformat/avformat.h>
}
int main(int argc, char**argv) {
av_register_all(); // offending library call
return 0;
}
A program simple as this will have 2 outcomes:
the program runs but crashes if i call 'av_register_all()'
It just tells me he cannot find the libraries.
Can someone tell me what it is i'm doing wrong? Or even give me a hint? I can't really find a lot of good documentation on this one.
Thanks in advance!
Configure PRO-file as shown below:
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-dev\include
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-dev\lib
LIBS += -lavcodec -lavformat -lavutil
Then, build the project, copy the all dll libraries from C:\programming\ffmpeg-20130606-git--win32-shared\bin to exe output path and run application.
UPD
Maybe you need to copy some of the following libraries from Qt\5.0.2\mingw47_32\bin\:
libgcc_s_sjlj-1.dll
libstdc++-6.dll
libwinpthread-1.dll

Linking freeglut with Qt Creator in Linux

I currently run Arch Linux on my laptop and was hoping to know why Qt Creator isn't finding my glut library (which exists on my system).
My setup qmake file looks as follows:
...
/*sources and headers above*/
QT += opengl
LIBS += -lfreeglut
INCLUDEPATH += -L/usr/lib/
And when I run a locate glut, I get the following:
/usr/include/kwinglutils.h
/usr/include/kwinglutils_funcs.h
/usr/include/GL/freeglut.h
/usr/include/GL/freeglut_ext.h
/usr/include/GL/freeglut_std.h
/usr/include/GL/glut.h
/usr/lib/libglut.a
/usr/lib/libglut.so
/usr/lib/libglut.so.3
/usr/lib/libglut.so.3.9.0
/usr/share/avogadro/fragments/amino_acids/D-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/D-glutamine.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamine.cml
/usr/share/licenses/freeglut
/usr/share/licenses/freeglut/LICENSE
/var/lib/pacman/local/freeglut-2.6.0-1
/var/lib/pacman/local/freeglut-2.6.0-1/changelog
/var/lib/pacman/local/freeglut-2.6.0-1/desc
/var/lib/pacman/local/freeglut-2.6.0-1/files
Note that I have tried -lglut32 in my qmake file as well.
What could I be missing here?
When you specify -lfoobar in your .pro file (or with gcc in general), you're directing the compiler to search for the library libfoobar.a. Judging from your locate output it looks like you want:
LIBS += -lglut
Oh, silly me. I just realized that the correct lib to add was just -lglut and not -lglut32. This is because there exists libglut.so, and not libglut32.so.

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.