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...
Related
I recently tried to write a unit test (with googletest) for a class including a Q_OBJECT macro and a self-defined signal. The test subproject won't compile (even after rebuilding/deleting everything) with the following linker errors:
"error: undefined reference to `vtable for Class'"
and
"error: undefined reference to `vtable for Class::signal()'"
My src subproject compiles just fine. After researching the issue I guess the problem is that the compiler doesn't generate moc files for the test subproject. Also I've not been successful to include the src subproject's moc files in test. How can I fix this?
Here are my .pro files:
Project .pro file
TEMPLATE = subdirs
CONFIG(debug, debug|release) {
SUBDIRS += \
src \
test
test.depends = src
} else {
SUBDIRS += \
src
QMAKE_CXXFLAGS += -O2
}
src.pro
QT += core gui charts widgets
TARGET = Project name
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
HEADERS += \
...
SOURCES += \
...
test.pro
include(gtest_dependency.pri)
QT += core
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG += thread
CONFIG += qt
INCLUDEPATH += $$PWD/../src
DEPENDPATH += $$PWD/../src
HEADERS += \
... (only test headers)
SOURCES += \
... (test and src source files)
I had the same problem. Making sure Qt mocs the src headers also for the test project seem to require to mention them in the test projects .pro file too. Thus adding something like:
HEADERS += ( dependent src headers )
If the tests need all the src headers they could be extracted into a common .pri file.
I am using Qt Creator 2.4.1(Based on Qt 4.7.4) ..
Now I want to open the .mat file which I got from Matlab.
I am using the basic function matOpen
Initially, I knew the headers required. They are mat.h, matrix.h and tmw.h.
Now, before running the code, I need to link the libraries. The required libraries as far as I know are libmat.dll and libmw.dll . I added them to the .pro file as follows.
QT += core
QT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
HEADERS += \
mat.h \
matrix.h \
tmwtypes.h
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop- Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmat.dll"
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmx.dll"
Still I get error as : undefined reference to matOpen.. m sure the problem is with the linking.. But I dunno how to solve it. and the compiler Qt is using is MinGw .
You are specifying library path only, not the libraries itself. Try
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug"
LIBS += -llibmx
LIBS += -llibmat
Specs: Qt Creator 2.5.1, Qt 4.7.4(32bit)
It is my understanding from the Qt documentation that including a resource (.qrc) in the .pro file of Qt is all that is required to get qmake to generate the correct qrc_*.cpp files. That doesn't seem to be the case for my project. When running qmake the makes files are created and there are references to the qrc_ file I'm looking for under compiler_rcc_clean, just not in the build chain.
[Update]
At a suggestion from comments below the makefile generated by qmake was tested directly w/ NMAKE. The correct qrc_filter_ao.cpp file was created. However the IDE still fails to properly generate this file when I build from Qt Creator.
.pro:
include (../../shared.pri)
TARGET = filter_ao
QT += opengl
HEADERS += ./filter_ao.h
SOURCES += ./filter_ao.cpp
RESOURCES += \
filter_ao.qrc
shared.pri
include (./general.pri)
VCGDIR = ../$$VCGDIR
TEMPLATE = lib
CONFIG += plugin
CONFIG += resources
QT += opengl
QT += xml
QT += xmlpatterns
QT += script
win32-msvc2008: LIBS += ../../distrib/common.lib
win32-msvc2008:DEFINES += GLEW_STATIC _USE_MATH_DEFINES
INCLUDEPATH *= ../.. $$VCGDIR ../$$GLEWDIR/include
DEPENDPATH += ../.. $$VCGDIR
win32-msvc2008:DEFINES += _CRT_SECURE_NO_DEPRECATE
CONFIG(release,debug | release){
# Uncomment the following line to disable assert in mingw
#DEFINES += NDEBUG
}
DESTDIR = ../../distrib/plugins
contains(TEMPLATE,lib) {
CONFIG(debug, debug|release) {
unix:TARGET = $$member(TARGET, 0)_debug
else:TARGET = $$member(TARGET, 0)d
}
}
win32-msvc2008: RCC_DIR = $(ConfigurationName)
general.pri
VCGDIR = ../../../vcglib
GLEWDIR = ../external/glew-1.7.0
win32:DEFINES += NOMINMAX
I think #Pie_Jesu is correct. I have set up a directory structure with the files from the OP, and imported the .pro file into QtCreator. I have removed the "win32-msvc2008: " prefix from the line which sets RCC_DIR since I am using VS Express 2010.
Result was that I get a message like "Unable to open \qrc_filter_ao.cpp for writing: Access denied" and no qrc_file is being created.
I then set the line to /TEMP:
RCC_DIR = /TEMP
Result is that I find the qrc_ file below \TEMP.
Did you try with a simpler .pro file? For instance, the following works for me (On Linux, no MSVC env available currently):
TEMPLATE = lib
CONFIG += plugin
CONFIG += resources
QT += opengl
QT += xml
QT += xmlpatterns
QT += script
TARGET = filter_ao
QT += opengl
RESOURCES += \
filter_ao.qrc
Make sure that the output of from the build contain a call to $QTDIR/rcc, like
/usr/bin/rcc -name filter_ao filter_ao.qrc -o qrc_filter_ao.cpp
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.
I want to use the QCA Library with QT4.7 and QTCreator as IDE.
I downloaded the "qca-2.0.2-mingw" Version and try to link them in my ".Pro"-file:
QT += core
QT -= gui
LIBS += -L"\qca-2.0.2-mingw\lib\"
LIBS += -lqca2
CONFIG *= qt
CONFIG += console
CONFIG -= app_bundle
INCLUDEPATH += "\qca-2.0.2-mingw\include\QtCrypto"
INCLUDEPATH += "\qca-2.0.2-mingw\bin"
TARGET = untitled1
TEMPLATE = app
LINKAGE = -lqca
CONFIG(debug, debug|release) {
windows:LINKAGE = -lqcad
mac:LINKAGE = -lqca_debug
}
LIBS += $$LINKAGE
SOURCES += main.cpp
it compiles but when I run a HMAC sample, copied from this location, http://delta.affinix.com/docs/qca/mactest_8cpp-example.html#_a6
the application stuck with the following error:
Starting C:\Qt\2010.04\qt\untitled1\release\untitled1.exe...
C:\Qt\2010.04\qt\untitled1\release\untitled1.exe exited with code -1073741515
Commenting out some lines doesn't bring the effect. Even the first line of the HMAX Example, will lead to the results described above "QCA::Initializer init;"
I've tried the "qca-2.0.0-mingw" also, but the same effect occurres.
Greets and Thanks first,
Marco
If it builds, that's already good. If it doesn't start, usually DLLs are not found, at runtime. Try adding the path to the qca DLLs to your PATH. In creator you can configure that in the Run Environment section of your Run configuration (Project/Run Settings).