QT ffmpeg Setting - qt

I can't use the ffmpeg in QT.
My Steps :
-1. compile the ffmpeg as normal
-2. add lib/include path in QT .pro
LIBS += -L/home/kim/ffmpeg/lib -lavcodec -lavformat
INCLUDEPATH += /home/kim/ffmpeg/include
-3. in code
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
and just call a function named av_register_all();
then I got the following bulid issues< many functions undefined reference >
in function `rl2_read_packet`: undefined reference to `av_free_packet`
in function `av_register_all`: ....
I search a solution of the problem but not work for me.
Any other solution? Thanks.

This is an old post and it is almost solved. By the way, I faced to the problem and I had lots of time struggling with
undefined reference to av_register_all
I am using Qt Creator 5.3.2 and this is my MYPROJECT.pro file
MYPROJECT.pro
QT += core
QT -= gui
TARGET = MYPROJECT
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
QMAKE_CXXFLAGS += -D__STDC_CONSTANT_MACROS
LIBS += -LC:\ffmpeg-20151219-git-2dba040-win32-dev\lib
LIBS += -lavcodec -lavformat -lavutil -lswscale
INCLUDEPATH +=C:\ffmpeg-20151219-git-2dba040-win32-dev\include
Setting up project.pro
It is recommended to build ffmpeg from scratch, but if you are on windows and if you are not willing to compile this masterpiece, then congrats! you are like me! Go for pre-built in zereanoe and download both the latest shared and dev win-32 versions. Extract the latter two packages in a place where there is no spaces in the path, i.e. mine is in: C:\ffmpeg-20151219-git-2dba040-win32-dev
I recommend that don't rename the main folder because it is highly informative. Set the include folder of the [PATH TO ffmpg-YYYYMMDD-git-win32-dev]/include to your project's search space by the following line of code:
INCLUDEPATH +=C:\ffmpeg-20151219-git-2dba040-win32-dev\include
You should also use libraries in [PATH TO ffmpeg-YYYYMMDD-git-win32-dev]/lib to your project as below:
LIBS += -LC:\ffmpeg-20151219-git-2dba040-win32-dev\lib
LIBS += -lavcodec -lavformat -lavutil
You can call libraries other than lavcodec, lavformat and lavutil. In your cpp file you should enclose headers corresponding to ffmpeg in extern "C" block.
DLLs should be added
The final step is to add all the dll files in the shared version of ffmpeg that you have recently downloaded.
Copy *.dll files within
[PATH TO ffmpeg-YYYYMMDD-git-2dba040-win32-shared]/bin
and paste them wherever your executable exists. Fo instance, my project is located on C:/QtProjects/MYPROJECT, then my binaries are located on:
C:/QtProjects/build-MYPROJECT-Desktop_Qt_5_3_MinGW_32bit-Debug
Now, copy all the dlls to your project's debug or release folder.
My main.cpp
This is my main.cpp :
main.cpp
#include <iostream>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
using namespace std;
int main(int argc, char *argv[])
{
cout<<"I have included FFMPEG in my project"<<endl;
av_register_all();
cout<<"If everything goes well you will see ME"<<endl;
return 0;
}

I had the same problems, it worked using the following trick.
In code cpp source:
#define __STDC_CONSTANT_MACROS
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
}
And in your .pro file:
LIBS += -LC:/Users/tom/bla/ffmpeg/lib/ -lavcodec -lavformat -lavutil
I think in your case, you need the -lavutil lib parameter.

Related

Qt linker errors Qmake + Makefile

I want to build a Qt project outside Qt Creator, so I'm using qmake to generate a Makefile on the following project file:
TEMPLATE = app
TARGET = test
INCLUDEPATH += . \
/usr/include/qt5/QtWidgets/
QMAKE_CXXFLAGS += --std=c++11
# Input
SOURCES += test.cc
Which was generated also by qmake, bar the c++11 flag and the second include path. The Makefile contains link paths to the Qt library
LIBS = $(SUBLIBS) -L/usr/X11R6/lib64 -lQt5Gui -L/usr/lib/x86_64-linux-gnu -lQt5Core -lG L -lpthread
What's weird in the above is that I don't have a /usr/X11R6 folder. Instead, libQt5Gui.so is located in /usr/lib/x86_64-linux-gnu, so I'm a little puzzled where the X11R6 comes from.
Anyway, this is my linker output:
test.cc:(.text.startup+0x20): undefined reference to `QApplication::QApplication(int&, char**, int)'
test.cc:(.text.startup+0x25): undefined reference to `QApplication::exec()'
test.cc:(.text.startup+0x2f): undefined reference to `QApplication::~QApplication()'
test.cc:(.text.startup+0x43): undefined reference to `QApplication::~QApplication()'
The above is the result of building the following source:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
When I try to build the project file in Qt Creator, the same error appears. Am I missing libraries? Or is something configured erroneously?
(I'm on Ubuntu 14.04, and I just installed the qtcreator package from the repo's, assuming that all development libraries would be installed along with it.)
As stated in the docs, you need to include the widget library to use QApplication.
Add this to your project file:
QT += widgets
If you're not going to build a GUI app, use QCoreApplication instead. It doesn't have that dependency.

Qt 5.3.1: Why do I need to set include path and libs for widgets

I'm on Windows 8.1. I want to build Qt apps from the command line like the Unix trooper I usually am. Well, actually, I want things to be a little more automated! After wondering why qmake would not generate the proper Makefiles and hand-editing them, I finally realized I could just add on to the Qt variable in the Qt .pro file. (Been since about Qt 3-something that I've Qt'ed, so finally the light-bulb went on :)
This is the simplest of applications to help refresh the dead brain cells.
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
The .pro file:
######################################################################
# Automatically generated by qmake (3.0) Sat Aug 23 16:38:04 2014
######################################################################
TEMPLATE = app
TARGET = HelloQt
INCLUDEPATH += .
#why do I need these
INCLUDEPATH += "C:\Qt\Qt5.3.1\5.3\msvc2013_64\include\qtwidgets"
LIBS += "C:\Qt\Qt5.3.1\5.3\msvc2013_64\lib\Qt5widgets.lib"
#why does the following line do nothing
qmake: Qt += widgets
CONFIG -= X86
# Input
SOURCES += hello.cpp
Why do I need to specify the widgets INCLUDEPATH and LIBS to get a successful build?
As far as I can tell, Qt += widgets is not a valid addition to the Qt variable.
Why not? If I don't specify the Qt5Widgets include and libs, and I run nmake, I get errors related to not finding the include for QApplication and/or linker errors.
With those two lines in the .pro file everything works fine. Has anybody run into this sort of thing, am I missing something?
The line should look more like QT += core gui widgets. This will set the INCLUDEPATH and LIBS.

INCLUDEPATH in qmake project file doesn't work

I've got a problem with include in a qmake project. In my .pro file I've got:
INCLUDEPATH += "C:\OpenCV\build\include"
and in my cpp :
#include <opencv\cv.h>
The compiler indicates an error:
Cannot open include file: 'opencv\cv.h': No such file or directory
but if I write this in my cpp:
#include "C:\OpenCV\build\include\opencv\cv.h"
it works!
I build the project from within Qt Creator. What am I doing wrong?
You have to run qmake(build->run qmake) to validate changes in the pro file.
Qt creator Adding external library (still: Cannot open include file: 'GL/glew.h')
Your problem may be related to the fact that having backslashes in naked #include directives is undefined behavior.
Do the following.
Replace your include with
#include <opencv/cv.h>
Note the forward slash!
Remove the shadow build directory that Qt Creator has made for you. You will find it above the project directory, its name begins with build-.
Rebuild the project.
Note that this takes care of rerunning qmake.
here's one of my pro files:
# Blah Application
TEMPLATE = app
CONFIG += qt console staticlib debug_and_release
QT -= gui
QT += network sql xml
TARGET = blah
CONFIG(debug, debug|release){
DESTDIR = debug
LIBS += -L../../../lib/core/debug -lcore
} else {
DESTDIR = release
LIBS += -L../../../lib/core/release -lcore
}
DEPENDPATH += . ../../lib ../../../lib/core
INCLUDEPATH += . ../../lib ../../../lib/core
# Library files
HEADERS += mtBlahRTP.h
SOURCES += mtBlahRTP.cpp
# Input
HEADERS +=
SOURCES += main.cpp
The include path points to the RELATIVE directory of my lib files. mtBlahRTP.h and mtBlahRTP.cpp are in ../../lib
I have the same question, before building or running, you should qmake(Build=>qmake) it.
My configurations for INCLUDEPATH:
INCLUDEPATH+=D:\opencv\opencv\build\include
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv2
I ran into a similar issue and what I found is that the QtCreator IDE is not re-reading the results of qmake and updating the "Cannot open" message. You need to close the offending file and re-open it - then you'll see that it no longer displays the error.
I had to do two steps: (re-)run qmake and rebuild the whole project - only then the INCLUDEPATH setting was considered correctly. (With QtCreator 3.5 and 3.6 (Qt 5.5 and Qt 5.6) on Windows.)
The only problem you are making is incorrectly linking the OpenCV library. The other answers given here may or may not work, but I have posted on another thread a surefire way to solve this problem using the "Add Library" wizard inside Qt Creator: https://stackoverflow.com/a/51914928/10245006
I was getting the error:
canserialcomm.o: In function `CanSerialComm::CanSerialComm()':
canserialcomm.cpp:(.text+0xc1): undefined reference to `vtable for CanSerialComm'
It turns out that the cause was it wasn't able to find canserialcomm.h where that constructor is declared. This was despite me having INCLUDEPATH in the project file point to the directory containing that header file:
INCLUDEPATH += . \
..
What I had to do to fix this is explicitely specify the header file; I added:
HEADER += ../canserialcomm.h
You should use double backslashes when in windows for qt creator with msvc. like this:
INCLUDEPATH += C:\\libcurl\\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\\include
this will fix the problem.
Under windows you have to eliminate the -I before each directory that is added into the INCLUDEPATH variable.
For example:
Under windows:
INCLUDEPATH += "C:\lib\boost_1_61_0" (back-slash)
Under linux & mac:
INCLUDEPATH += -I"$$(HOME)/lib/boost_1_61_0" (note the -I and forward-slash)
I'm not sure whether it depends on different qmake version or not. But after finishing qmake command, I check the Makefile and the double -I is the issue.
You need to do several things. Fist, in the .pro file, you need quotation marks two backslashes at a time, like this:
INCLUDEPATH += "C:\\OpenCV\\build\\include\\opencv\\cv.h"
You alse need a frontslash in the #include in your .cpp file like this:
#include <opencv/cv.h>
When you've done this, delete the build folder. This is the folder with a very complicated name of the type build-untitled-Desktop_Qt_5_7_0_MSVC2015_32bit-Release. Then, in the Build menu, press "Run qmake". When you've done all this, it should compile fine.
Somehow it did not work for when I had several INCLUDEPATH +=.
When I combined the stuff into a single on it suddenly worked.

include compiled through command prompt static library in qt project

I’m trying to make a simple static library, like:
my.h
void My();
my.cpp
#include "my.h"
#include "stdio.h"
void My()
{
printf("Hello, world");
}
If I made it in qtcreator, I can call My() function in other project like:
.pro
INCLUDEPATH += c:/Users/PC/my
LIBS += -Lc:/Users/PC/my/debug -lmy
.cpp
#include <my.h>
....
My();
When compiling the library, the makefile is created by qmake. If I try to compile as stated in makefile through command prompt, I get some other object and library files. Then if I include them into my project, I obtain error:
undefined reference to `My()'.
How to link static library through command prompt and then include it into project?

Compiling C++ AMP using qmake fails

I have the following main.cpp file:
#include <amp.h>
using namespace concurrency;
int main()
{
int arr[] = {42};
array_view<int, 1> v(1, arr);
return 0;
}
and a .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
QMAKE_CXXFLAGS += -EHsc
SOURCES += main.cpp
If I compile main.cpp from the Visual Studio 2012 command line (just using cl /EHsc main.cpp), everything works fine. But if I use qmake and nmake there is alway a link error, that there are unresolved external symbols (coming from amp). Does anybody know how to resolve this problem?
I figured out, what the problem is: In the mkspec file qmake.conf the compiler flag Zc:wchar_t- causes the compiler to translate some types relatet to wchar_t incorrectly and hence the resulting symbols could not be resolved.
To solve this problem, change the above .pro file to
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
QMAKE_CXXFLAGS += -EHsc -Zc:wchar_t
SOURCES += main.cpp
(add -Zc:wchar_t to QMAKE_CXXFLAGS).
You forget to add
LIBS += -lname_of_the_amp_lib
Sorry but I don't know the name of the lib...

Resources