Bonjour,

J'ai développé un programme quelconque (pour l'instant...) qui fait appel à Qt, juste un simple affichage de courbes.
Sous système Unix, avec Qt Creator, j'ai eu aucun souci pour le compiler, ni pour le lancer. Que ce soit directement par ligne de commande ou bien via Qt Creator.

Sous Windows, c'est beaucoup plus compliqué.
J'utilise MSVC 2019/64-bit et Qt-Creator (qui lui peut choisir son compilateur), à partir de CMakeFiles.
Voilà les soucis que je rencontre :
  • Sous MSVC, j'ai une erreur d'édition de lien
  • Sous QtCreator avec MSVC comme compilateur, j'ai plusieurs erreur d'éditions de lien
  • Avec CMake-gui et mingw32-make, j'ai des erreurs de compilation au niveau des .h d'une bibliothèque (que je n'ai pas ailleurs)

Il n'y qu'avec QtCreator avec son MinGW-64bit que ça marche, et encore...seulement quand je lance le programme dans l'environnement. En dehors il ne trouve pas les .dll (certes je peux les ajouter au %PATH).

Dès lors je ne sais pas trop comment m'en tirer sans trop bricoler de choses. Je voudrais que malgré les quelques bibliothèques présentes et nécessaires, un utilisateur puisse facilement à partir de mon code source et mon CMakeList (ci-dessous) compiler et lancer le programme. D'autant que les erreurs que je liste, je ne sais pas comment les résoudre, chaque environnement ayant sa logique.
Le CMakeList.txt
Code CMakeLists : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
cmake_minimum_required(VERSION 3.10)
 
project(testQCustomPlot LANGUAGES CXX)
 
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
# Find the QtWidgets library
find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
 
add_compile_definitions(QCUSTOMPLOT_USE_LIBRARY)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(${CMAKE_BUILD_TYPE})
    if (UNIX)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/libqcustomplotd.so")
    elseif(WIN32)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/libqcustomplotd2.a")
    endif()
else()
    if (UNIX)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/libqcustomplot.so")
    elseif(WIN32)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/libqcustomplot2.a")
    endif()
endif()
 
add_executable(testQCustomPlot main.cpp qcustomplot.h)
 
#find_package(Armadillo REQUIRED PATHS "C:/Project/armadillo-9.900.2")
message(status "${PROJECT_SOURCE_DIR}")
set (ARMADILLO_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include_arma")
set (ARMADILLO_LIBRARIES "${PROJECT_SOURCE_DIR}/ext_lib/libarmadillo.a")
include_directories(${ARMADILLO_INCLUDE_DIRS})
target_link_libraries(testQCustomPlot Qt5::Widgets Qt5::PrintSupport ${LINK_LIB_PLOT} ${ARMADILLO_LIBRARIES})

Et le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <memory>
#include <QApplication>
#include <QDialog>
#include "qcustomplot.h"
#include <armadillo>
 
using namespace std;
 
void convertToVectorDouble(const arma::vec Avec, std::vector<double> &Aout);
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QDialog window;
    QCustomPlot customPlot;
    QVBoxLayout *mainLayout = new QVBoxLayout();
    QPushButton *buttonQuit = new QPushButton("Quit");
    mainLayout->addWidget(buttonQuit);
    mainLayout->addWidget(&customPlot);
    window.setLayout(mainLayout);
    // setup customPlot as central widget of window:
    arma::arma_rng::set_seed_random();
    // generate data
    arma::mat Tvalrand = arma::randn(1000,1);
    arma::vec Tsamples(Tvalrand.n_rows);
    Tsamples = Tvalrand.col(0);
    arma::uvec histVal(50);
    arma::vec histValD(50);
    std::vector<double> histValVec(50);
    std::vector<double> abcissesVec(50);
 
    double xmin = Tsamples.min();
    double xmax = Tsamples.max();
    double step = (xmax - xmin)/50;
    histVal = arma::hist(Tsamples, 50);
    histValD = arma::conv_to<arma::vec>::from(histVal);
    histValD /= step*1000;
 
    convertToVectorDouble(histValD, histValVec);
 
    int l = 0;
    double step_2 = (xmax - xmin)/(50-1);
    std::generate(abcissesVec.begin(), abcissesVec.end(), [&] () -> double {return xmin+(l++)*step_2;} );
    abcissesVec.back() = xmax;
 
    // create plot (from quadratic plot example):
    QVector<double> x(50), y(50);
    x = QVector<double>::fromStdVector(abcissesVec);
    y = QVector<double>::fromStdVector(histValVec);
 
    // layouts
    customPlot.plotLayout()->clear();
    QCPLayoutGrid *subLayout = new QCPLayoutGrid;
    QCPAxisRect *leftAxis = new QCPAxisRect(&customPlot);
    QCPAxisRect *rightAxis = new QCPAxisRect(&customPlot);
    customPlot.plotLayout()->addElement(0,0,subLayout);
    subLayout->addElement(0, 0, leftAxis);
    subLayout->addElement(0, 1, rightAxis);
 
    QCPGraph *leftGraph = customPlot.addGraph(leftAxis->axis(QCPAxis::atBottom),leftAxis->axis(QCPAxis::atLeft));
 
    leftGraph->setData(x, y);
    leftGraph->keyAxis()->setLabel("x");
    leftGraph->valueAxis()->setLabel("y");
    leftGraph->rescaleAxes();
 
    QCPGraph *rightGraph = customPlot.addGraph(rightAxis->axis(QCPAxis::atBottom),rightAxis->axis(QCPAxis::atLeft));
 
    rightGraph->setData(x, y);
    rightGraph->keyAxis()->setLabel("x");
    rightGraph->valueAxis()->setLabel("y");
    rightGraph->rescaleAxes();
 
    /*arma::mat valRandImage = arma::randn<arma::mat>(10*10,1);
    arma::vec meanA(10*10);
    std::vector<double> im2show(10*10);
    meanA = valRandImage.col(0);
    /*convertToVectorDouble(meanA, im2show);*/
    /*QCPColorMap *colorMap = new QCPColorMap(customPlot.xAxis, customPlot.yAxis);
    colorMap->data()->setSize(10, 10);
    colorMap->data()->setRange(QCPRange(0, 10), QCPRange(0, 10));
    for (int i =0; i < 10; ++i)
    {
        for (int j = 0; j < 10; ++j)
        {
            cout << 255*meanA(j+i*10) << endl;
            colorMap->data()->setCell(i,j,255*meanA(j+i*10));//(unsigned char) 255*meanA(j+i*10));
        }
    }
    colorMap->setGradient(QCPColorGradient::gpGrayscale);
    colorMap->setInterpolate(false);
    colorMap->setTightBoundary(false);
    colorMap->rescaleDataRange(true);
    customPlot.rescaleAxes();
    customPlot.replot();*/
 
    window.setGeometry(100, 100, 500, 400);
    window.show();
 
    return a.exec();
}
 
void convertToVectorDouble(const arma::vec Avec, std::vector<double> &Aout)
{
    unsigned int nElem = Avec.n_elem;
    for (unsigned int i = 0; i < nElem; ++i)
    {
        Aout.at(i) = Avec(i);
    }
}