Qt + Ogre3D. I cannot build a very simple example - c++

I use:
Qt 5.15.2 MinGW 32-bit Dynamic for Debug build
Ogre 13.1.1 MinGW Static build
There is a class called ApplicationContextQt that can help to use Qt with Ogre3D but I have errors:
This example is very simple:
main.cpp
#include "Ogre.h"
#include "OgreApplicationContextQt.h"
#include <QGuiApplication>
class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener
{
public:
MyTestApp();
void setup();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
};
MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp")
{
}
bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
return true;
}
void MyTestApp::setup(void)
{
// do not forget to call the base first
OgreBites::ApplicationContextQt::setup();
}
int main(int argc, char *argv[])
{
QGuiApplication qapp(argc, argv);
MyTestApp app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
return qapp.exec();
}
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"
LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib"
LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE"
LIBS += -lOgreBitesQtStatic
LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic
LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml
LIBS += -lopengl32 -lgdi32

You can try this one ?
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"
LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic" -lOgreBitesQtStatic
LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OGRE" -lOgreBitesStatic
// OR ...
LIBS += "E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic/OgreBitesQtStatic.a"
LIBS += "E:/ProgramFiles/ogre-13.1.1/lib/OGRE/OgreBitesStatic.a"
// It just depends on the actual names of your libraries
// Same for the others unless their file location is decleared under system path.
// If so, you can add that libraries like how you did with opengl
And it is nice to add PRE_TARGETDEPS macros too if you make changes on those libraries so often:
PRE_TARGETDEPS += "E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic.a"
You can replace "/"s with "" too.
And the problem with your pro file was: You added library paths as libraries. And then tried to add that libraries from system environment.

Related

Linking graphviz libraries to C++ correctly

I am developping a program with QtCreator in which I use graphviz2.38.
I have done a minimale example to explain. Just consider this small code which transform a dot file in svg file:
#include <QCoreApplication>
#include <graphviz/gvc.h>
#include <graphviz/gvplugin.h>
#include <graphviz/cgraph.h>
#include <graphviz/cdt.h>
#include<iostream>
using namespace std;
void saveImageGV(){
GVC_t *gvc= gvContext();
extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
gvAddLibrary(gvc, &gvplugin_dot_layout_LTX_library);
FILE *fp = fopen(("ancestry.dot"), "r");
Agraph_t *g = agread(fp,0);
gvLayout(gvc, g, "dot");
gvRender(gvc, g, "svg", fopen(("ancestry.svg"), "w"));
gvFreeLayout(gvc, g);
agclose(g);
(gvFreeContext(gvc));
return exit(0);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
saveImageGV();
return a.exec();
}
The compilation options are the following:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
SOURCES += \
main.cpp
QMAKE_LFLAGS += "-Wl,--rpath=lib/ "
QMAKE_LFLAGS += "-Wl,--dynamic-linker=lib/ld-linux-x86-64.so.2"
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
INCLUDEPATH += /usr/local/include/graphviz/
unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lcdt
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib
unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lcgraph
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib
unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lgvc
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib
unix:!macx: LIBS += -L$$PWD/../../../usr/lib/graphviz/ -lgvplugin_dot_layout
INCLUDEPATH += $$PWD/../../../usr/lib/graphviz
DEPENDPATH += $$PWD/../../../usr/lib/graphviz
unix:!macx: LIBS += -L$$PWD/../../../usr/lib/graphviz/ -lgvplugin_core
INCLUDEPATH += $$PWD/../../../usr/lib/graphviz
DEPENDPATH += $$PWD/../../../usr/lib/graphviz
unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lpathplan
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib
unix:!macx: LIBS += -L$$PWD/../../../../usr/lib/ -lxdot
INCLUDEPATH += $$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib
I also provide you an example of graphviz dot code if needed for ancestry.dot:
graph {
a -- b;
b -- c;
a -- c;
d -- c;
e -- c;
e -- a;
}
In my lib folder, I have the following libraries:
ld-linux-x86-64.so.2 libc.so.6 libgvplugin_dot_layout.so.6 libxdot.so.4
libcdt.so.5 libgvc.so.6 libgvplugin_gd.so.6
libcgraph.so.6 libgvplugin_core.so.6 libpathplan.so.4
To load these libraries at execution time, I use the following script:
#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`
dirname=`pwd`
lib=/lib/
chmod +x $dirname/$appname
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$dirname$lib
echo $LD_LIBRARY_PATH
./$appname "$#"
When I execute my code, I get a segmentation fault ... Any idea of what is happening?

Qt and Matlab Mixed Programming

I have a problem when I use Qt with MATLAB mixed programming. I tested an example but it failed. Here is my code.
First is my pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = paintertest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
test1.cpp
HEADERS += mainwindow.h \
test1.h \
mat.h \
matrix.h \
mclbase.h \
mclcppclass.h \
mclmcr.h \
mclmcrrt.h \
tmwtypes.h \
MyAdde.h \
engine.h
FORMS += mainwindow.ui
INCLUDEPATH += D:/program/engineering/armadillo-8.200.2/include
INCLUDEPATH += D:/program/engineering/sigpack
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lblas_win32_MT
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lblas_win32_MTd
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lblas_win32_MT
INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llapack_win32_MT
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llapack_win32_MTd
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llapack_win32_MT
INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32
unix|win32: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lliblapacke
INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32
INCLUDEPATH += D:/program/engineering/matlabR2014a/extern/include
INCLUDEPATH += D:/program/engineering/matlabR2014a/extern/include/win32
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibmx
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibmat
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibmex
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -lmclmcr
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -lmclmcrrt
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibeng
#INCLUDEPATH += C:/Users/Administrator/Desktop/Qt/paintertest
#LIBS += -LC:/Users/Administrator/Desktop/Qt/paintertest -lMyAdde
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:unix: LIBS += -L$$PWD/./ -lMyAdde
INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/.
And next is my mainwindow.h:
#include <QMainWindow>
#include <QPainter>
#include "test1.h"
#include <QVariant>
#include <armadillo>
#include <iostream>
#include "sigpack.h"
#include "MyAdde.h"
#include "mat.h"
#include "matrix.h"
#include "mclbase.h"
#include "mclcppclass.h"
#include "mclmcr.h"
#include "mclmcrrt.h"
#include "tmwtypes.h"
#include "engine.h"
And next is my mainwindow.cpp:
double a=6;
double b = 9;
double c;
if(MyAddeInitialize()){
qDebug()<<"ok";
}
mwArray mwA(1, 1, mxDOUBLE_CLASS);
mwArray mwB(1, 1, mxDOUBLE_CLASS);
mwArray mwC(1, 1, mxDOUBLE_CLASS);
mwA.SetData(&a, 1);
mwB.SetData(&b, 1);
MyAdde(1, mwC, mwA, mwB);
c = mwC.Get(1, 1);
cout<<"c"<<c;
MyAddeTerminate();
mclTerminateApplication();
The MyAdde.h/MyAdde.dll/MyAdde.lib is my Matlab code. Here is my Matlab code:
function [ c ] = MyAdde( a, b )
c = a+b;
end
I use MATLAB to generate MyAdde.h/MyAdde.dll/MyAdde.lib and I add this file to my Qt pro file.But some error happened.This is my Qt error:
C:\Users\Administrator\Desktop\Qt\paintertest\mainwindow.cpp:23: error: undefined reference to `MyAdde(int, mwArray&, mwArray const&, mwArray const&)'
I checked the MyAdde.h and I found this code:
extern LIB_MyAdde_CPP_API void MW_CALL_CONV MyAdde(int nargout, mwArray& c, const mwArray& a, const mwArray& b);
I thinked of that the question is caused by const mwArray& and mwArray const&. I can't understand the reason. I need your help!
It's a linker error , so it has compiled fine but the link failed
It's probably this stuff that is wrong
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:unix: LIBS += -L$$PWD/./ -lMyAdde
What are you trying to achieve ? first and second lines should normally not be the same if you have a debug and release version of you MyAdde dll

'_nextafter' not declared : CGAL in Qt Creator with Windows 8.1

I've build CGAL like explained here.
Everything went well.
But now, I'm using Qt Creator with CGAL.
I've included the libraries in the .pro file :
QT += core
QT -= gui
TARGET = TestCCGALAppliConsole
CONFIG += console
CONFIG -= app_bundle
CONFIG += c++11
TEMPLATE = app
INCLUDEPATH += /usr/local/include
DEPENDPATH += /usr/local/include
LIBS += -L/usr/local/include
macx: LIBS += -L/usr/local/lib/ -lgmp
macx: LIBS += -L/usr/local/lib/ -lmpfr
macx: LIBS += -L/usr/local/lib/ -lCGAL
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/CGAL-4.6/build/lib/release/ -lCGAL-vc100-mt-gd-4.6
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/CGAL-4.6/build/lib/debug/ -lCGAL-vc100-mt-4.6
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/build/lib/Debug
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/build/lib/Debug
INCLUDEPATH += C:\local\CGAL-4.6\include
win32: LIBS += -L$$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/lib/ -llibgmp-10
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
win32: LIBS += -L$$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/lib/ -llibmpfr-4
INCLUDEPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
DEPENDPATH += $$PWD/../../../../local/CGAL-4.6/auxiliary/gmp/include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_system-vc100-mt-1_57
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_system-vc100-mt-gd-1_57
INCLUDEPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
DEPENDPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_thread-vc100-mt-1_57
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0/ -lboost_thread-vc100-mt-gd-1_57
INCLUDEPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
DEPENDPATH += $$PWD/../../../../local/boost_1_57_0/lib64-msvc-10.0
INCLUDEPATH += C:\local\boost_1_57_0
and in my main.cpp I have :
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K, CGAL::Polyhedron_items_with_id_3> Polyhedron;
typedef Polyhedron::Vertex_iterator Vertex_iterator;
int main() {
Polyhedron mesh;
std::ifstream input("inner.off");
if ( !input || !(input >> mesh) || mesh.empty() )
{
//Debug
std::cerr << "Not a valid off file." << std::endl;
return 0;
}
for (Vertex_iterator v = mesh.vertices_begin() ; v!= mesh.vertices_end() ; ++v )
{
std::cout << v->point() << std::endl;
}
std::cout << "Hello You" << std::endl;
return 0;
}
when I compile (with MinGW 4.9.1 32 bit with Qt 5.4.1) I'm having this error :
C:\local\CGAL-4.6\include\CGAL\double.h:191: erreur : '_nextafter' was
not declared in this scope return _nextafter(d1, d2); // works at
least for VC++-7.1
I can't figure out what's wrong...
Can you help me ?
EDIT
It seems that CGAL being compiled with Visual Studio C++ Compiler 10 involves that I have to compile with this compiler and not MinGW.
So I changed compile, I'm now using Microsoft Visual C++ Compiler 10 (amd64) in Qt Creator, but it still don't work. I have an error :
impossible to open 'CGAL-vc100-mt-4.6.lib' file
Here's the complete error (sorry, french version...) :
17:42:15: Exécution des étapes pour le projet TestCCGALAppliConsole...
17:42:15: Configuration inchangée, étape qmake sautée.
17:42:15: Débute : "C:\Qt\Tools\QtCreator\bin\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
cl -c -nologo -Zm200 -Zc:wchar_t -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\TestCCGALAppliConsole.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_CORE_LIB -I"..\TestCCGALAppliConsole" -I"." -I"\usr\local\include" -I"..\..\..\..\local\CGAL-4.6\build\lib\Debug" -I"..\..\..\..\local\CGAL-4.6\include" -I"..\..\..\..\local\CGAL-4.6\auxiliary\gmp\include" -I"..\..\..\..\local\CGAL-4.6\auxiliary\gmp\include" -I"..\..\..\..\local\boost_1_57_0\lib64-msvc-10.0" -I"..\..\..\..\local\boost_1_57_0\lib64-msvc-10.0" -I"..\..\..\..\local\boost_1_57_0" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\include" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\include\QtCore" -I"debug" -I"..\..\..\..\Qt\qt-5.4.1-x64-msvc2010-rev1\qt-5.4.1-x64-msvc2010-rev1\mkspecs\win32-msvc2010" -Fodebug\ #C:\Users\Raphael\AppData\Local\Temp\main.obj.1988.32.jom
main.cpp
echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\TestCCGALAppliConsole.exe.embed.manifest">debug\TestCCGALAppliConsole.exe_manifest.rc
if not exist debug\TestCCGALAppliConsole.exe if exist debug\TestCCGALAppliConsole.exe.embed.manifest del debug\TestCCGALAppliConsole.exe.embed.manifest
if exist debug\TestCCGALAppliConsole.exe.embed.manifest copy /Y debug\TestCCGALAppliConsole.exe.embed.manifest debug\TestCCGALAppliConsole.exe_manifest.bak
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\TestCCGALAppliConsole.exe.embed.manifest /OUT:debug\TestCCGALAppliConsole.exe #C:\Users\Raphael\AppData\Local\Temp\TestCCGALAppliConsole.exe.1988.5000.jom
LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'CGAL-vc100-mt-4.6.lib'
jom: C:\Users\Raphael\Desktop\build-TestCCGALAppliConsole-Desktop_Qt_5_4_1_MSVC2010_x64-Debug\Makefile.Debug [debug\TestCCGALAppliConsole.exe] Error 1104
jom: C:\Users\Raphael\Desktop\build-TestCCGALAppliConsole-Desktop_Qt_5_4_1_MSVC2010_x64-Debug\Makefile [debug] Error 2
17:42:21: Le processus "C:\Qt\Tools\QtCreator\bin\jom.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet TestCCGALAppliConsole (kit : Desktop Qt 5.4.1 MSVC2010 x64)
When executing step "Make"
17:42:21: Temps écoulé : 00:05.
Well, it's right there in your message:
when I compile (with MinGW
versus
works at least for VC++-7.1
_nextafter is a Microsoft extension used by CGAL. MinGW doesn't appear to support it.

Qt Creator on Mac and boost libraries

I am running QtCreator on Mac... I want to start working on boost libraries ... So, I installed boost libraries using
brew install boost
After that I created a small boost hallo world program and made the changes in .pro file as follows
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
unix:INCLUDEPATH += "/usr/local/Cellar/boost/1.55.0_1/include/"
unix:LIBPATH += "-L/usr/local/Cellar/boost/1.55.0_1/lib/"
SOURCES += main.cpp
LIBS += \
-lboost_date_time \
-lboost_filesystem \
-lboost_program_options \
-lboost_regex \
-lboost_signals \
-lboost_system
I am still unable to build... What could be the reason? Please suggest me what could be the possible mistake...
The errors are
library not found for -lboost_data_time
linker command failed with exit code 1 (use -v to see invocation)
This is taking a bit from Uflex's answer, as he missed something.
So keep the same code:
//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>
int main()
{
auto start = boost::chrono::system_clock::now();
for ( long i = 0; i < 10000000; ++i )
std::sqrt( 123.456L ); // burn some time
auto sec = boost::chrono::system_clock::now() - start;
std::cout << "took " << sec.count() << " seconds" << std::endl;
return 0;
}
But lets change his .pro a bit:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt -lboost_system # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}
The only thing I have added to this was the boost system( -lboost_system )
That should solve the issue with his original version causing the undefined symbols, and allow you to add your other libraries.
Such as -lboost_date_time, which for me worked perfectly with the brew install.
Granted, my path is actually: /usr/local/Cellar/boost/1.55.0_2
Boost libraries are modularized, you just need to link against the libraries that you are using. Some libraries are header only, so you don't need to do anything, having boost reachable in your path is enough.
You can try to compile this:
//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>
int main()
{
auto start = boost::chrono::system_clock::now();
for ( long i = 0; i < 10000000; ++i )
std::sqrt( 123.456L ); // burn some time
auto sec = boost::chrono::system_clock::now() - start;
std::cout << "took " << sec.count() << " seconds" << std::endl;
return 0;
}
And in the .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}

C++ - Poco library in Qt Creator

I am trying to use the poco library in Qt Creator with one of the samples that came with poco, I have gotten this to work in Visual Studio 2012 but I keep getting build errors in Qt Creator.
I have both .dll and .lib in my lib path.
here is my .pro file
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += C:\Users\justin\Downloads\poco-1.4.6\Net\include
INCLUDEPATH += C:\Users\justin\Downloads\poco-1.4.6\Foundation\include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lPocoFoundation
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lPocoFoundationd
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoFoundation.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoFoundationd.lib
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lPocoNet
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lPocoNetd
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoNet.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoNetd.lib
and here is the .cpp file
#include "Poco/URIStreamOpener.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include "Poco/Net/FTPStreamFactory.h"
#include <memory>
#include <iostream>
using Poco::URIStreamOpener;
using Poco::StreamCopier;
using Poco::Path;
using Poco::URI;
using Poco::Exception;
using Poco::Net::HTTPStreamFactory;
using Poco::Net::FTPStreamFactory;
int main(int argc, char** argv)
{
HTTPStreamFactory::registerFactory();
FTPStreamFactory::registerFactory();
try
{
URI uri("http://example.com");
std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri));
StreamCopier::copyStream(*pStr.get(), std::cout);
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
and these are the build errors:
undefined reference to `Poco::Net::HTTPStreamFactory::registerFactory()'
undefined reference to `Poco::Net::FTPStreamFactory::registerFactory()'
undefined reference to `Poco::URI::URI(char const*)'
undefined reference to `Poco::URIStreamOpener::defaultOpener()'
undefined reference to `Poco::URIStreamOpener::open(Poco::URI const&) const'
undefined reference to `Poco::StreamCopier::copyStream(std::istream&, std::ostream&, unsigned int)'
undefined reference to `Poco::URI::~URI()'
undefined reference to `Poco::URI::~URI()'
The same compiler must be used to compile all three of the below:
Poco library
Qt library
Your application
My hunch is that you use MSVC2012 for #3, you correctly downloaded #2 for MSVC2012, but you did not compile #1 with MSVC2012.