I have a basic issue with includes. My project structure looks like this:
myProject.pro
---directoryA
directoryA.pri
---directoryA1
firstHeader.h
secondHeader.h
secondHeader.cpp
main.cpp
This is how myProject.pro looks like (I have ony written lines which I though to be relevant)
myProject.pro:
include(directoryA/directoryA.pri)
SOURCES += main.cpp
directoryA.pri:
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += \
$$PWD/directoryA/firstHeader.h \
$$PWD/directoryA/secondHeader.h
SOURCES+= \
$$PWD/directoryA/secondHeader.cpp
Given this structure, a simple include that I want to do in secondHeader.h from firstHeader.h does not work:
firstHeader.h:
#define firstheaderVar 4
secondHeader.h:
#include "firstheader.h"
int secondHeaderVar = firstheaderVar;
Simply I can not include anything from the first one within second one. It always gives the '...' was not declared in this scope error.
I suspect this to be an error caused by my project directory structure but can not find an elegant way to solve it.
Any help would be appreciated. Thanks!
you forgot: ./
try something like this:
#include "./firstheader.h"
Related
I need to work with OpenMesh on my PC with Qt IDE, the snip of the simple *.pro file looks like:
DEFINES += _USE_MATH_DEFINES
DEFINES += NOMINMAX
#DEFINES += OM_STATIC_BUILD
#OpenMesh
INCLUDEPATH += "D:/Libraries/OpenMesh 6.3/include"
#Debug
LIBS += "D:/Libraries/OpenMesh 6.3/lib/OpenMeshCored.lib"
LIBS += "D:/Libraries/OpenMesh 6.3/lib/OpenMeshToolsd.lib"
# Release
LIBS += "D:/Libraries/OpenMesh 6.3/lib/OpenMeshCore.lib"
LIBS += "D:/Libraries/OpenMesh 6.3/lib/OpenMeshTools.lib"
However, I still got the error message: "C1189: #error: "You have to define _USE_MATH_DEFINES in the compiler settings!"
Can anyone help me?
if you wanna run your application from Qt creator for any reason as using qmake, you just have to add "DEFINES += _USE_MATH_DEFINES" to your *.pro file
The same error occured to me, but with MSVC 2019 16.6.1
Adding the define _USE_MATH_DEFINES in front of my OpenMesh include statement solves the problem for me.
#define _USE_MATH_DEFINES
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
The forum Post How does #define _USE_MATH_DEFINES work? helped me to understand the functionality behind the define.
I have a problem with my one of my projects.
I use QtCreator with MinGW and Qt 5.4.0
When I try to compile, this simple line gets me some errors :
CryptUnprotectData(data.password, NULL, NULL, NULL, NULL, (DWORD) 0, data.uncryptedPassword);
( with DATA_BLOB* data.password and DATA_BLOB* data.uncryptedPassword )
Gets me :
undefined reference to `_imp__CryptUnprotectData#28'
As said on the title, I included the Crypt32.Lib file in my .pro :
QT += core gui
QT += sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ChromePass
LIBS += -L$$PWD/ -lCrypt32
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
chromehandler.cpp \
passdata.cpp
HEADERS += mainwindow.h \
chromehandler.h \
passdata.h
FORMS += mainwindow.ui
And as instructed in the MSDN api, included wincrypt.h :
#include <windows.h>
#include <wincrypt.h>
#include <cstdlib>
#include <fstream>
The error being still there, I checked wincrypt.h to make sure CryptUnprotectData is defined, and it is :
WINIMPM WINBOOL WINAPI CryptUnprotectData(DATA_BLOB *pDataIn,LPWSTR *ppszDataDescr,DATA_BLOB *pOptionalEntropy,PVOID pvReserved,CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,DWORD dwFlags,DATA_BLOB *pDataOut);
I've been trying for the whole day ... does anyone have a clue ?
Thank you very much !
The clue is that crypt32 library is not built with mingw this is why you are getting linking errors.
Bad news is that there is no simple way to resolve that. You can read about some ways to resolve here:
MingW missing some functions from the Win32 Crypto API
Discussion on Qt forum about this question can be found here:
https://forum.qt.io/topic/25527/cannot-find-how-to-link-to-crypt32-dll
Windows 7
Qt 5.4.0
OpenCV 2.4.10
Mingw 4.9.1
I'm trying to create a simple Hello World app, to test if Qt is working with OpenCV. Besides the stuff created by default, the code is
#include <opencv/cv.h>
#include <opencv/highgui.h>
(...)
cv::Mat image= cv::imread("pic.jpg");
cv::namedWindow("Test picture");
cv::imshow("Test picture", image);
cv::waitKey(1000);
(...)
However, I'm having trouble linking libraries. At first I've set the paths to *.dll.a files manually
INCLUDEPATH += C:/opencv/my_build/install/include
INCLUDEPATH += C:/opencv/my_build/install/include/opencv
INCLUDEPATH += C:/opencv/my_build/install/include/opencv2
LIBS += -LC:/opencv/my_build/install/x86/mingw/lib \
-llibopencv_core2410 \
-llibopencv_highgui2410
etc etc
But then I'd get a cannot find -llibopencv_<lib>2410 error. I've even used Qt Creator's "Add library" function (Projects -> rightclick -> add library), the result is the same. That error only goes away if I change -llibopencv_<lib>2410 to -opencv_<lib>2410. Which from my understanding is weird, as the "l" argument is missing.
Even though that error goes away, a bunch of others replace it, as I get undefined reference to cv::EVERYTHING error. I've looked around, found solutions to either problem, but solving one leads to the other and vice versa.
I'm fairly sure the OpenCV build is not at fault - I've already completed a pretty big console-ish app using it with Code::Blocks.
My current *.pro file :
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/opencv/my_build/install/include
win32: LIBS += -L$$PWD/../../../../../../OpenCV/my_build/install/x86/mingw/lib/ -llibopencv_core2410
INCLUDEPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
DEPENDPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
win32: LIBS += -L$$PWD/../../../../../../OpenCV/my_build/install/x86/mingw/lib/ -llibopencv_highgui2410
INCLUDEPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
DEPENDPATH += $$PWD/../../../../../../OpenCV/my_build/install/x86/mingw
How to correctly link the OpenCV libraries to Qt Creator? Am I missing something?
edit: I've rebuilt the whole damn thing and it still doesn't work. God damn it.
When specifying library, you need to exclude the 'lib' part:
LIBS += -LC:/opencv/my_build/install/x86/mingw/lib \
-lopencv_core2410 \
-lopencv_highgui2410
Frankly, I have little idea of what went wrong. I've edited the environment PATH variable, twice, to include the OpenCV build. Maybe I've made a typo the first time. It now looks like this:
C:\MinGW\bin;C:\OpenCV\my_build\install\x86\mingw\bin;C:\Qt\5.4.0\5.4\mingw491_32\bin;
My *.pro file also looks different.
QT += core
QT -= gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += C:/OpenCV/qtbuild//install/include
LIBS += "C:/OpenCV/qtbuild/install/x86\mingw/lib/*.a"
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I've change +=gui to -=gui and added CONFIG -= app_bundle. The INCLUDE and LIBS paths are also different now - I won't be changing them out of an irrational fear something will go horribly wrong again.
And lastly, I've simply removed the previous project and made a new one. Maybe something else got corrupted?
Anyway, it works now, after doing these things.
First off, I alread got the smaller example paex_record.c to work.
I use MinGW on Windows8 and did compile portaudio from source, that's were I got the used libportaudio-2.dll from.
I set up a project in QtCreator (without gui) with following .pro-file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
LIBS += -LC:/Audio/patest/paex_record_file -llibportaudio-2
My folder C:/Audio/patest/paex_record_file looks like:
libportaudio-2.dll
main.cpp
pa_ringbuffer.c
pa_ringbuffer.h
pa_util.h
paex_record_file.pro
paex_record_file.pro.user
portaudio.h
I copied both pa_ringbuffer and pa_util to this folder after they were not found.
Main.cppcontains the whole example file paex_record_file.c from the portaudio source.
There is an error when calling the ringbuffer (line 246 and 271: source):
"min" was not declared in this scope
I thought this example would directly run just like the record.c example.
Do I need to include further packages? I've tried algorithm, math, std and using namespace std, but still the error occurs. But I get the feeling it should work out off box, perhaps my include files or folder setup / linkage is not ok?
EDIT: Ok so I just defined a min-function on my own. Now it throws different error:
undefined reference to "PaUtil_GetRingBufferReadAvailable"
and a couple more of this kind. There is probably a lib missing to be linked, having a look...
I also had this linking error trying to compile paex_record_file.c. Turns out you need to compile pa_ringbuffer.c before compiling the main file. There's also an external dependency on some alloc function, so you need to change 2 lines in the file.
I'm not savvy of qt but you need to do something like:
SOURCES += pa_ringbuffer.c main.cpp
Here's how I compile with MinGW:
Changes inside paex_record_file.c
Line 313 : data.ringBufferData = (SAMPLE *) malloc( numBytes );
Line 443 : free( data.ringBufferData );
Compile with MinGW:
gcc -o p_rec.exe C:\path_to_portaudio\portaudio\common\pa_ringbuffer.c \
paex_record_file.c -lportaudio \
-IC:\path_to_portaudio\portaudio\src\common
I didn't get the min problem, but perhaps you can try to remove the ifdef guard and try to recompile.
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#endif
to
#include <windows.h>
#include <process.h>
I wrote a simple C code with GStreamer libs (gstreamer example code manual ref)
My GStreamer headers are located at /usr/include/gstreamer-0.10/gst.
Thus, I wrote the following line in my C code:
#include "gstreamer-0.10/gst/gst.h"
When I compiled, I have this error:
there are unresolved includes inside
How can I solve this problem?
Thank you...
If you use the standard C compiler flags given by pkg-config gstreamer-0.10 --cflags, you should need only #include <gst/gst.h> in your source code. To help yourself, you can use a simple Makefile (some simple example here)
in my Qt project-file i use following:
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0 \
gstreamer-0.10 \
gstreamer-interfaces-0.10
so i suppose you have to tell your compiler to use these pkg-configs (*.pc): glib-2.0, gstreamer-0.10, gstreamer-interfaces-0.10