Qt C++ ffmpeg cannot find library - c++

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

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

compilation error of OpenCV cpp code using Qt

I am using a very basic OpenCV code to compile using Qt but every time the following errors are coming.
OpenCV version
OpenCV version : 3.4.3
Major version : 3
Minor version : 4
Subminor version : 3
My code
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat I = imread("path/filename.ppm", 1);
imshow("conv_image",I);
waitKey();
return 0;
}
.pro file
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you
use
# any feature of Qt which as been marked deprecated (the exact
warnings
# depend on your compiler). Please consult the documentation of
the
# deprecated API in order to know how to port your code away from
it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use
deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a
certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables
all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Given Error
:-1: warning: libopencv_core.so.3.4, needed by /usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
:-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
/usr/local/lib/libopencv_core.so.3.4:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status
In my .pro file, I have used the following line(from the different link I have found 3 ways, I have tried all but failed)
First
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Second
INCLUDEPATH +=/usr/local/include/opencv
LIBS +=`pkg-config --libs opencv`
Third
I have used information from here
Please give me suggestion to solve the issue.

Library Version Mismatch (C++ HDF5 Windows)

When trying to run a simple program using the hdf5-file format i get these messages and the program crashes:
I found posts to other problems like this, but most of them refer to linux and python. I use C++ (Qt Creator) and Windows (Windows 7 64bit) with the MSVC17 64bit Compiler, so these solutions dont work for me.
I don't understand why this occurs, because i simply donwloaded the HDF5 version 1.10.2 and installed it, i don't know why it says something about the version 1.8.15. Where could this come from?
I guess "library version" (1.8.15) is the version of my hdf5.lib file, right?
What does "header version" (1.10.2) mean? I simply #include <hdf5.h> and #include <H5Cpp.h> in the main.cpp and added paths in the hdf5_test_2.pro (my project) file.
Here is my code:
hdf5_test.pro:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5 -lhdf5_cpp -lhdf5_hl_cpp
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/libhdf5.lib'
else:win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/liblibhdf5.a'
main.cpp:
#include <iostream>
#include <hdf5.h>
#include <H5Cpp.h>
using namespace std;
using namespace H5;
int main()
{
hid_t file_id;
herr_t status;
file_id = H5Fcreate("file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
status = H5Fclose(file_id);
cout << "Hello World!" << endl;
return 0;
}
The code example i tried to use comes from High Level Introduction to HDF5 (Pages 16/17).
Solved (meaning next error)
I think i solved the problem: There was another Version of HDF5 installed (1.8.15) on the system (the one who used this PC before me installed it).
I told my programm to link my lib (1.10.2) and passed the path, but somehow he found the 1.8.15 version previously installed. I now told my program to link the old version and it worked.
My hdf5_test_2.pro (my project) looks now like this:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
win32: LIBS += -LC:/Anaconda2/Library/lib/ -lhdf5 -lhdf5_cpp
INCLUDEPATH += C:/Anaconda2/Library/include
DEPENDPATH += C:/Anaconda2/Library/include
Nice so far, but i get these two warnings now:
Any ideas, what that means?

Configure Qt Creator to use TBB on Windows [duplicate]

I have compiled TBB from source using Mingw following the comment #5 in this post: http://software.intel.com/en-us/forums/topic/291331. That went ok.
When I try to use the new TBB library in a QtCreator project, I end with this errors (ignore the warning messages): http://postimage.org/image/yrrecugix/
Here's the sample code I tried (I omit the non-tbb code):
#include "tbb/task_scheduler_init.h"
int main()
{
tbb::task_scheduler_init init;
/// more things.
}
And here's the .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
#QMAKE_CXXFLAGS += -fopenmp
#QMAKE_LFLAGS += -fopenmp
INCLUDEPATH += "E:\TRABAJO\LIBRERIAS\tbb-4.1_src\include"
LIBS += -L"E:\TRABAJO\LIBRERIAS\tbb-4.1_src\build\windows_intel64_gcc_mingw4.5.4_debug\" \
-ltbb_debug
Any idea?.
Thanks!.
When built with MinGW on Windows, TBB binaries are tbb.dll and tbb_debug.dll. The option -ltbb_debug in your configuration files probably causes the linker to look for libtbb_debug.<something>. It can't find such a binary and reports about unresolved symbols.

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
}