Qt line causes strange error: Cmd.exe exited with code -20

Qt line causes strange error: Cmd.exe exited with code -20

我正在两台不同的 PC 上构建我的项目,它们都使用相同的方法(Visual Studio 2017 年使用 CMake)。他们都使用 CMake 进行配置和生成。问题是当我尝试构建它们时,一个构建正常而另一个有错误。

我已经找出了这个错误的原因,似乎是每当我尝试实例化 QLineSeries 或 QChart 时。我的代码下方没有红色波浪线。一切看起来都很好,直到我尝试实例化其中一个然后出现这些错误。

我经常使用 QLineSeries(我有 3 个系列),我慢慢地注释掉代码,直到找到罪魁祸首。第一行,我试图创建 lineRedSeries = new QLineSeries; 导致以下错误。此外,即使我注释掉所有内容并尝试创建 QChart *chart = new QChart();,它也会导致相同的错误。

奇怪的是,只是在我的 h 文件中声明 QLineSeries 和 QChartView 不会导致这个问题(所以如果我注释掉我的 cpp 文件中的代码)。只有当我尝试创建 QLineSeries 或 QChart 时才会出现错误。

由于我的 cpp 文件很长,我已经删除了很多与这个问题无关的不必要的功能。

在我的 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;
};

在我的 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 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

完整的构建输出:

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\Include.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 Studio17\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 ==========

在qcompilerdetection.h中,具体指1349行和1351行:

我在 C/C++ > General 中包含了正确的附加包含目录,在 VS 中的 Linker > Input 中包含了正确的 .lib 文件。我的包括也是正确的。任何见解表示赞赏。

ADTF 不部署 QtCharts 二进制文件,因为许可证不兼容。 Qt 基本上是 LGPL 许可的,它可以在 ADTF 许可下正常工作。但是有些组件是在 GPL 下授权的,QtCharts 就是其中之一。您不能将 QtCharts 与 ADTF 一起使用,因为那样您就违反了 GPL 中描述的组合工作规则。 GPL 不适用于商业和闭源许可证,仅适用于开源 GPL 兼容许可证,如 GPL 本身、MPL 或其他许可证。无论如何,因为缺少二进制文件,您会收到错误消息,即缺少某些依赖项。但是即使你把二进制文件放在那里,也是不允许的,无论是私人的还是商业的。它不兼容,这就是 ADTF 试图保护客户并仅提供 LGPL 内容的原因。您甚至不允许使用开源 Qt 将商业 Qt 与 ADTF 一起使用,因为 Qt 拒绝将 oss 与商业许可混合使用,即使那是相同的二进制文件(政治......)。只有机会,从 qt 市场购买独立的 qtcharts,然后它与 LGPL 兼容。但是你必须自己把二进制文件。或者你 link 静态的,这是 Qt 的 commercial/marketplace 许可证允许的。

我想通了。

我在我的 ADTF 插件所在的目录中丢失了一些非常重要的 Qt .dll 文件。一旦我将核心 .dll(Qt5Charts.dll、Qt5Core.dll、Qt5Gui.dl 等)移动到正确的目录并添加此 1-liner:

QCoreApplication:addLibraryPath("C:/Users/Path/To/Qt/msvc2017_64/plugins"); // this

就在我实例化我的 QApplication 之前,它成功了!