I am building my project on 2 different PCs, both using the same methods (Visual Studio 2017 with CMake). They both configure and generate fine using CMake. The issue is when I try to build them, one builds fine and the other has errors.
I have isolated the cause of this error and it seems to be whenever I try to instantiate either QLineSeries or QChart. There are NO red squiggles underneath my code. It all looks fine, until I try to instantiate either and then those errors appear.
I use QLineSeries a lot (I have 3 series), and I slowly commented out code until I found the culprit. The first line, me trying to create lineRedSeries = new QLineSeries;
results in the errors below. Also, even if I comment out everything and try to create QChart *chart = new QChart();
, it also causes the same errors.
Curiously enough, just declaring QLineSeries and QChartView in my h file doesn't cause this issue (so if I comment out the code in my cpp file). It's only when I try to create a QLineSeries or QChart that the errors occur.
I have removed a lot of unnecessary functions that are not pertinent for this question as my cpp file is quite long.
In my main.h
:
#include <QtCharts> // for QLineSeries, QChartView, Chart
#include <QChartView>
class ExampleProject
{
public:
ExampleProject();
~ExampleProject();
private:
int OpenGraphic();
private:
QLineSeries *lineRedSeries, *lineGreenSeries, *lineBlueSeries;
QChartView *chartView;
};
In my main.cpp
:
#include "main.h"
#include <QApplication>
#include <QMainWindow>
#include <iostream>
int ExampleProject::OpenGraphic()
{
char *myargv[1];
int myargc = 1;
myargv[0] = strdup("");
// First, create QApplication
QApplication a(myargc, myargv);
// Create our lineChart Series
lineRedSeries = new QLineSeries; // The most FIRST line and causes errors!
lineRedSeries->setName("RedSeries");
lineRedSeries->setColor(Qt::red);
lineRedSeries->append(1, 20);
lineRedSeries->append(2, 30);
lineRedSeries->append(3, 44);
lineGreenSeries = new QLineSeries;
lineGreenSeries->setName("GreenSeries");
lineGreenSeries->setColor(Qt::green);
lineGreenSeries->append(1, 10);
lineGreenSeries->append(2, -9);
lineGreenSeries->append(3, 20);
lineGreenSeries->append(10, -40);
lineBlueSeries = new QLineSeries;
lineBlueSeries->setName("BlueSeries");
lineBlueSeries->setColor(Qt::blue);
lineBlueSeries->append(1, -20);
lineBlueSeries->append(2, -10);
lineBlueSeries->append(3, 0);
QChart *chart = new QChart();
chart->setTitle("Acceleration Graph");
chart->setAcceptHoverEvents(true);
// Add series to chart
chart->addSeries(lineRedSeries);
chart->addSeries(lineGreenSeries);
chart->addSeries(lineBlueSeries);
// Customize axes for chart
chart->createDefaultAxes();
chart->axes(Qt::Horizontal).back()->setRange(0, 131);
chart->axes(Qt::Vertical).back()->setRange(-50, 50);
chart->axes(Qt::Horizontal).back()->setTitleText("Time [s]");
chart->axes(Qt::Vertical).back()->setTitleText("Acceleration [m/s]");
// Create chartView
chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
// Render everything within our Window
QMainWindow mainWindow;
mainWindow.setCentralWidget(chartView);
mainWindow.resize(400, 300);
mainWindow.show();
return a.exec();
}
The code will result in these errors:
the argument to a feature-test macro must be a simple identifier, qcompilerdetection.h, Line 1349
the argument to a feature-test macro must be a simple identifier, qcompilerdetection.h, Line 1351
"cmd.exe" exited with code -20, Microsoft.CppCommon.targets, Line 209
Complete build output:
1>------ Rebuild All started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>Checking Build System
2>------ Rebuild All started: Project: main, Configuration: Debug x64 ------
2>Automatic MOC and UIC for target main
2>Building Custom Rule C:/Path/To/Drive/src/main/CMakeLists.txt
2>mocs_compilation.cpp
2>main.cpp
2>C:\Path\To\Drive\src\main\main.cpp(132): warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details.
2>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\string.h(536): note: see declaration of 'strdup'
2> Creating library C:/Path/To/Drive/build/src/main/Debug/main.lib and object C:/Path/To/Drive/build/src/main/Debug/main.exp
2>easy_profilerd.lib(block.obj) : warning LNK4099: PDB 'easy_profiler.pdb' was not found with 'easy_profilerd.lib(block.obj)' or at 'C:\Path\To\Drive\build\src\main\Debug\easy_profiler.pdb'; linking object as if no debug info
2>easy_profilerd.lib(easy_socket.obj) : warning LNK4099: PDB 'easy_profiler.pdb' was not found with 'easy_profilerd.lib(easy_socket.obj)' or at 'C:\Path\To\Drive\build\src\main\Debug\easy_profiler.pdb'; linking object as if no debug info
2>easy_profilerd.lib(event_trace_win.obj) : warning LNK4099: PDB 'easy_profiler.pdb' was not found with 'easy_profilerd.lib(event_trace_win.obj)' or at 'C:\Path\To\Drive\build\src\main\Debug\easy_profiler.pdb'; linking object as if no debug info
2>easy_profilerd.lib(nonscoped_block.obj) : warning LNK4099: PDB 'easy_profiler.pdb' was not found with 'easy_profilerd.lib(nonscoped_block.obj)' or at 'C:\Path\To\Drive\build\src\main\Debug\easy_profiler.pdb'; linking object as if no debug info
2>easy_profilerd.lib(profile_manager.obj) : warning LNK4099: PDB 'easy_profiler.pdb' was not found with 'easy_profilerd.lib(profile_manager.obj)' or at 'C:\Path\To\Drive\build\src\main\Debug\easy_profiler.pdb'; linking object as if no debug info
2>easy_profilerd.lib(thread_storage.obj) : warning LNK4099: PDB 'easy_profiler.pdb' was not found with 'easy_profilerd.lib(thread_storage.obj)' or at 'C:\Path\To\Drive\build\src\main\Debug\easy_profiler.pdb'; linking object as if no debug info
2>main.vcxproj -> C:\Path\To\Drive\build\src\main\Debug\main.adtfplugin
2>-- Installing: C:/Path/To/Drive/base/tools/adtf/addons/Training/bin/debug/main.adtfplugin
2>-- Installing: C:/Path/To/Drive/base/tools/adtf/addons/Training/bin/debug/main.pdb
2>Done building project "main.vcxproj".
3>------ Rebuild All started: Project: main_pdgen, Configuration: Debug x64 ------
3>Generating Debug/main.plugindescription
3>2021-09-02 12:44:12 [INFO]: Try to load "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_core.adtfplugin" [runtime.cpp(1788)]
3>2021-09-02 12:44:12 [INFO]: Loaded plugin: "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_core.adtfplugin" (Build Type: Debug) [runtime.cpp(1895)]
3>2021-09-02 12:44:12 [INFO]: Registered class "session_manager.service.adtf.cid". ( 1 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "rpc_object_registry.service.adtf.cid". ( 2 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "core_sample_stream_tracer.service.adtf.cid". ( 3 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [DUMP]: Registered plugin "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_core.adtfplugin", plugins in registry: 2 [runtime.cpp(1422)]
3>2021-09-02 12:44:12 [INFO]: Try to load "C:\Path\To\Drive\base\tools\adtf\bin\debug\default_core_objects.adtfplugin" [runtime.cpp(1788)]
3>2021-09-02 12:44:12 [INFO]: Loaded plugin: "C:\Path\To\Drive\base\tools\adtf\bin\debug\default_core_objects.adtfplugin" (Build Type: Debug) [runtime.cpp(1895)]
3>2021-09-02 12:44:12 [INFO]: Registered class "default_sample_stream.streaming.adtf.cid". ( 4 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "default_thread_runner.streaming.adtf.cid". ( 5 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "default_timer_runner.streaming.adtf.cid". ( 6 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "default_binding_proxy.streaming.adtf.cid". ( 7 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "sample_stream_merger.streaming.adtf.cid". ( 8 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "substream_selector.streaming.adtf.cid". ( 9 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "substream_assembler.streaming.adtf.cid". ( 10 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "substream_merger.streaming.adtf.cid". ( 11 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "substream_dissector.streaming.adtf.cid". ( 12 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "thread_mapper.streaming.adtf.cid". ( 13 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "thread_invoker.streaming.adtf.cid". ( 14 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [INFO]: Registered class "thread_reducer.streaming.adtf.cid". ( 15 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [DUMP]: Registered plugin "C:\Path\To\Drive\base\tools\adtf\bin\debug\default_core_objects.adtfplugin", plugins in registry: 3 [runtime.cpp(1422)]
3>2021-09-02 12:44:12 [INFO]: Try to load "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_media_description.adtfplugin" [runtime.cpp(1788)]
3>2021-09-02 12:44:12 [INFO]: Loaded plugin: "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_media_description.adtfplugin" (Build Type: Debug) [runtime.cpp(1895)]
3>2021-09-02 12:44:12 [INFO]: Registered class "media_description.service.adtf.cid". ( 16 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [DUMP]: Registered plugin "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_media_description.adtfplugin", plugins in registry: 4 [runtime.cpp(1422)]
3>2021-09-02 12:44:12 [INFO]: Try to load "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_kernel.adtfplugin" [runtime.cpp(1788)]
3>2021-09-02 12:44:12 [INFO]: Loaded plugin: "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_kernel.adtfplugin" (Build Type: Debug) [runtime.cpp(1895)]
3>2021-09-02 12:44:17 [ERROR]: Could not register plugin in runtime Result code '-20 '(ERR_NOT_FOUND) - Could not load plugin "C:\Path\To\Drive\base\tools\adtf\addons\addons-toolbox\bin\debug\main.adtfplugin": file or dependencies not found [File: c:\j\workspace\dtf-builder_release_3.11.1_lucky\repo\src\libraries\ucom3\src\runtime.cpp] [Line: 1825] [Func: adtf::ucom::ant::detail::cRuntime::cRuntimePrivate::LoadPluginImpl]
3> [File: c:\j\workspace\dtf-builder_release_3.11.1_lucky\repo\src\libraries\ucom3\src\runtime.cpp] [Line: 1359] [Func: adtf::ucom::ant::detail::cRuntime::cRuntimePrivate::RegisterPlugin] [main.cpp(161)]
3>2021-09-02 12:44:17 [ERROR]: Result code '-20 '(ERR_NOT_FOUND) - Could not load plugin "C:\Path\To\Drive\base\tools\adtf\addons\addons-toolbox\bin\debug\main.adtfplugin": file or dependencies not found [File: c:\j\workspace\dtf-builder_release_3.11.1_lucky\repo\src\libraries\ucom3\src\runtime.cpp] [Line: 1825] [Func: adtf::ucom::ant::detail::cRuntime::cRuntimePrivate::LoadPluginImpl]
3> [File: c:\j\workspace\dtf-builder_release_3.11.1_lucky\repo\src\libraries\ucom3\src\runtime.cpp] [Line: 1359] [Func: adtf::ucom::ant::detail::cRuntime::cRuntimePrivate::RegisterPlugin] [main.cpp(703)]
3>2021-09-02 12:44:12 [INFO]: Registered class "kernel.service.adtf.cid". ( 17 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [DUMP]: Registered plugin "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_kernel.adtfplugin", plugins in registry: 5 [runtime.cpp(1422)]
3>2021-09-02 12:44:12 [INFO]: Try to load "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_clock.adtfplugin" [runtime.cpp(1788)]
3>2021-09-02 12:44:12 [INFO]: Loaded plugin: "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_clock.adtfplugin" (Build Type: Debug) [runtime.cpp(1895)]
3>2021-09-02 12:44:12 [INFO]: Registered class "reference_clock.service.adtf.cid". ( 18 ) [runtime.cpp(2182)]
3>2021-09-02 12:44:12 [DUMP]: Registered plugin "C:\Path\To\Drive\base\tools\adtf\bin\debug\adtf_clock.adtfplugin", plugins in registry: 6 [runtime.cpp(1422)]
3>2021-09-02 12:44:12 [INFO]: Using settings from:C:/Path/To/Drive/AppData\Local\Digitalwerk\ADTF-Configuration-Editor_3.11.1\adtf_configuration_editor.cesettings [main.cpp(601)]
3>2021-09-02 12:44:17 [DUMP]: Will increase runlevel to "RL_System" [runtime.cpp(715)]
3>2021-09-02 12:44:17 [INFO]: Started UCOM runtime [runtime.cpp(1063)]
3>2021-09-02 12:44:17 [INFO]: Switched main clock to 'adtf'. [clock_srv.cpp(353)]
3>2021-09-02 12:44:17 [INFO]: Switched stream clock to 'adtf_stream'. [clock_srv.cpp(392)]
3>2021-09-02 12:44:17 [INFO]: Initializing service "reference_clock.services.adtf" [runtime.cpp(765)]
3>2021-09-02 12:44:17 [INFO]: No RPC Object Registry available to register clock for RPC calls [clock_srv.cpp(173)]
3>2021-09-02 12:44:17 [INFO]: Initialized service "reference_clock.services.adtf" [runtime.cpp(796)]
3>2021-09-02 12:44:17 [INFO]: Initializing service "kernel.services.adtf" [runtime.cpp(765)]
3>2021-09-02 12:44:17 [INFO]: Initialized service "kernel.services.adtf" [runtime.cpp(796)]
3>2021-09-02 12:44:17 [INFO]: Initializing service "media_description.services.adtf" [runtime.cpp(765)]
3>2021-09-02 12:44:17 [INFO]: Initialized service "media_description.services.adtf" [runtime.cpp(796)]
3>2021-09-02 12:44:17 [INFO]: Try to load "C:\Path\To\Drive\base\tools\adtf\addons\addons-toolbox\bin\debug\main.adtfplugin" [runtime.cpp(1788)]
3>2021-09-02 12:44:17 [INFO]: Deinit all services, filter, streamingservices [main.cpp(325)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "reference_clock.service.adtf.cid". ( 17 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "kernel.service.adtf.cid". ( 16 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "media_description.service.adtf.cid". ( 15 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "thread_reducer.streaming.adtf.cid". ( 14 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "thread_invoker.streaming.adtf.cid". ( 13 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "thread_mapper.streaming.adtf.cid". ( 12 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "substream_dissector.streaming.adtf.cid". ( 11 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "substream_merger.streaming.adtf.cid". ( 10 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "substream_assembler.streaming.adtf.cid". ( 9 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "substream_selector.streaming.adtf.cid". ( 8 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "sample_stream_merger.streaming.adtf.cid". ( 7 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "default_binding_proxy.streaming.adtf.cid". ( 6 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "default_timer_runner.streaming.adtf.cid". ( 5 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "default_thread_runner.streaming.adtf.cid". ( 4 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "default_sample_stream.streaming.adtf.cid". ( 3 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "core_sample_stream_tracer.service.adtf.cid". ( 2 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "rpc_object_registry.service.adtf.cid". ( 1 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unregistered class "session_manager.service.adtf.cid". ( 0 ) [runtime.cpp(2226)]
3>2021-09-02 12:44:17 [INFO]: Unloading plugin: "ADTF Clock Service Plugin" [runtime.cpp(1904)]
3>2021-09-02 12:44:17 [INFO]: Unloading plugin: "ADTF Kernel Service Plugin" [runtime.cpp(1904)]
3>2021-09-02 12:44:17 [INFO]: Unloading plugin: "ADTF Media Description Service Plugin" [runtime.cpp(1904)]
3>2021-09-02 12:44:17 [INFO]: Unloading plugin: "ADTF Default Core Objects Plugin" [runtime.cpp(1904)]
3>2021-09-02 12:44:17 [INFO]: Unloading plugin: "ADTF Session Manager Plugin" [runtime.cpp(1904)]
3>2021-09-02 12:44:17 [INFO]: Stopped UCOM runtime [runtime.cpp(1093)]
3>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5): error MSB6006: "cmd.exe" exited with code -20.
3>Done building project "main_pdgen.vcxproj" -- FAILED.
========== Rebuild All: 2 succeeded, 1 failed, 0 skipped ==========
In qcompilerdetection.h, it refers to lines 1349 and 1351 specifically:
I have included the proper Additional Include Directories within C/C++ > General and the correct .lib files in Linker > Input in VS. My includes are also correct. Any insight is appreciated.
I figured it out.
I was missing some very important Qt .dll files in the directory where my ADTF plugins resided. Once I moved the core .dlls (Qt5Charts.dll, Qt5Core.dll, Qt5Gui.dl, etc.) to the right directory as well as adding this 1-liner:
QCoreApplication:addLibraryPath("C:/Users/Path/To/Qt/msvc2017_64/plugins"); // this
to right before I instantiate my QApplication, it worked!