YAML-CPP with QTcreator - c++

i try to use yaml-cpp in cmake with windows 7
I followed the tutorial and build the cmake and get yaml-cpp.dll , yaml-cpp.lib , yaml-cpp.exp
i saved them inside the libs directory in my project.
with
LIBS += -L$$PWD/libs -lyaml-cpp
i add in in my pro file. The include files are added with
INCLUDEPATH +=$$PWD\includes
inside this is my yaml-cpp directory with all include files.
On my program I use
#include <yaml-cpp/yaml.h>
This all is compiling without an error. But when I add
YAML::Node doc;
i get the undefiened reference to Yaml::Node ERROR
i dont know what i have forgot to link.
Do you have an idea? thank you for help

Related

How do I go about adding a third party library to QtCreator?

I'm trying to add OpenXLSX to my QtCreator project but following this guide I can't seem to get QtCreator to find the header file.
The QtCreator manual mentions .lib files which this library doesn't use so I'm kinda lost with that guide. I googled around and tried adding all the headers and sources from OpenXLSX/#library/#openxlsx/interfaces/c++/ to my headers and sources directories in the project tree. Yet I still get
exceltest.cpp:3: error: 'OpenXLSX.h' file not found
Line 3 is
#include "OpenXLSX.h"
I've also tried
#include "3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/OpenXLSX.h"
The 3rdparty directory being in the same location as exceltest.pro
I've also tried both with angle brackets.
I don't need any advanced functionality from OpenXLSX, just reading and writing values to cells I specify to either .xlsx or .xls.
I'm also not married to the idea of using OpenXLSX so if anyone knows excel any libraries that would work better I'm open to the idea.
EDIT: So after I added my headers and sources to the project tree, my exceltest.pro looks like this.
I tried putting this line
#include "3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/OpenXLSX.h"
into exceltest.h instead of exceltest.cpp and I'm getting different errors. QtCreator seems to find the library files but is something wrong with the library? These are the errors:
In file included from J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLCell.h:49:0,
from ..\exceltest\3rdparty\OpenXLSX\#library\#openxlsx\interfaces\c++\sources\XLCell.cpp:5:
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLDefinitions.h:57:35: warning: multi-character character constant [-Wmultichar]
constexpr uint32_t maxRows = 1'048'576;
^~~~~
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: warning: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: error: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^~~~~
..\exceltest\3rdparty\OpenXLSX\#library\#openxlsx\interfaces\c++\sources\XLCellRange.cpp:5:10: fatal error: XLCellRange.h: No such file or directory
#include <XLCellRange.h>
^~~~~~~~~~~~~~~
compilation terminated.
..\exceltest\3rdparty\OpenXLSX\#library\#openxlsx\interfaces\c++\sources\XLCellReference.cpp:5:10: fatal error: XLCellReference.h: No such file or directory
#include <XLCellReference.h>
^~~~~~~~~~~~~~~~~~~
First, you have to build the OpenXLSX project to get the library. The project uses cmake for generation. You need to generate the worksapce, first:
List all the available generators with
cmake --help
Chose the one you want to use, then:
cmake . -G "Your generator"
Build your project according to your generator. The libraries and headers will be copied in the install directory.
In your .pro file, add the following lines:
INCLUDEPATH += /path/to/OpenXLSX/include
LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.lib
The first one allows you to include the OpenXLXS headers. The second line will be used by the linker to link the library to your app.
You may need to use a different version of your library if you want to build your project on Windows or Linux. You can use this syntax:
# On Windows in release mode
win32:CONFIG(release, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.dll
#On Windows debug mode
else:win32:CONFIG(debug, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx_debug.dll
#On Linux debug and release
else:unix: LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.so
In Qt Creator, if you right-click on your project, you can use the dedicated wizard to add a library (Add Library option in the context menu). It will add everything you need in your *.pro

Qt include Class of another Project (Cannot open include file: 'foo.h')

I just started with Qt and some issues came up. I'm sure it must be a simple solution but I just can't find it.
I have two Projects, ProjectOne and ProjectTwo. I'd like you use the class foo from ProjectOne in main.cpp from ProjectTwo. When I run my Programm The Files are copied/referenced into ProjectTwo, but when i try to include foo in my main.cpp (#include "foo.h") i recieve the following error:
> main.cpp:3: error: C1083: Cannot open include file: 'foo.h':
> No such file or directory
Here's my Structure:
-ProjectOne
-ProjectOne.pro
-Headers
-foo.h
-Source
-foo.cpp
-Other files
-ProjectOne.pri
-ProjectTwo
-ProjectTwo.pro
-ProjectOne
-ProjectOne.pri
-Headers
-foo.h
-Sources
-foo.cpp
-Sources
main.cpp
Here's what i edited on my .pro and .pri files
**ProjectOne.pri**
INCLUDEPATH += $$PWD
SOURCES += $$PWD/foo.cpp
HEADERS += $$PWD/foo.h
**ProjectTwo.pro:**
include(../ProjectOne/ProjectOne.pri)
QT += core
SOURCES += foo.cpp
HEADERS += foo.h
I'm using Qt Creator 3.1.2 on Windows 7. My Programming Language is C++ and I'm compiling with VisualStudio 10 Express.
Any help is greatly appreciated!
When including a file that isn't directly in you project folder you need to include it with full or relative path.
i.e.
#include "bar/foo.h"
or
#include "../../bar/foo.h"

Qt5: Poppler weird linker error

I downloaded pre-built win32 poppler binaries from this page. Added the path for the include folder and lib folder in the .pro file:
INCLUDEPATH += "C:\\test_folder\\poppler-0.24.5-win32\\include\\poppler-qt5"
LIBS += -L/"C:\\test_folder\\poppler-0.24.5-win32\\lib"
In main.cpp i include "poppler-qt5.h" without errors, so I would think that poppler was added correctly. However when testing it by opening a pdf file, as described here,
QString path = "C:\\Windows\\System32\\spool\\PRINTERS\\test_file.pdf";
Poppler::Document *doc = Poppler::Document::load(path);
I receive a linker error:
Can someone help me out here?
I am missing the -l in yout LIBS line
LIBS += -L/"C:\\test_folder\\poppler-0.24.5-win32\\lib" -lpoppler-qt5
Eventually rename the lib since .dll.a is not a standard extension in windows.
Edit: Works without renaming the library:
.pro File:
INCLUDEPATH += $$quote(D:\Users\username\Downloads\poppler-0.24.5-win32\poppler-0.24.5-win32\include\poppler-qt5)
LIBS += -L$$quote(D:\Users\username\Downloads\poppler-0.24.5-win32\poppler-0.24.5-win32\lib) -lpoppler-qt5
.cpp File:
#include <QApplication>
#include <mycpp.h>
#include <poppler-qt5.h>
/* Some Code here */
QString path = "D:\\SomePDF.pdf";
Poppler::Document *doc = Poppler::Document::load(path);
/* More Code here */
I had the same problem and I resolved it with this method:
Copy dll file if you find in folder \poppler-0.24.5-win32\bin\ to folder where Qt generate executable file. Then download zlib1.dll and insert this dll to folder where Qt generate executable file. Try now.
This works for me. I compiled with qt 5.3 in Windows XP SP3.

qt windows include boost thread header failed

I want to include boost in my qt application in windows, So:
In my .pro file, I add:
INCLUDEPATH += D:/library/boost_1_55_0
In main.cpp
#include <boost/thread/mutex.hpp>
When build, cause this error:
Cannot open include file: 'boost/thread/mutex.hpp'
I am sure the path is correct. And it is very strange.
The issue is that you have to re-run qmake explicitly. Here you can find the corresponding long-standing issue:
Creator should know when to rerun qmake

Qt - Glut32 Lib

I'm trying to create an Glut window with Qt creator. All my code has been done on another computer. Now, I want to compile it on my own.
I've added the Glut32 library files in the following folders:
glut32.lib into a lib/ foler in my project directory
glut32.dll into my project directory
glut.h into a GL/ folder in my project directory
In my pro files, I've added the following lines:
LIBS += -L$$PWD/lib/glut32.lib
LIBS += Opengl32.lib
And in my code, I've the following includes:
#include <gl/GL.h>
#include "GL/glut.h"
Qt does not report any error with the last include!
So, when I try to compile my code, I've many errors which say:
error LNK2019: unresolved external symbol
All those errors belongs to glut functions which cannot be found. So, did I do something wrong when I included the glut32 library?
Thanks.
Maybe it helps you to know, that you can output messages in your pro file, eg: message("Location of glut32.lib" + $$PWD/lib/glut32.lib). So you could check, whether your path is ok. Also note, that you add libraries with -l<LibName> and library paths with -L<LibPath>, so you should try to replace -L$$PWD/lib/glut32.lib by -l$$PWD/lib/glut32.lib
For further options refer to the qmake variable reference