我在两台不同的PC上构建我的项目,都使用相同的方法(带有CMake的Visual Studio2017)。它们使用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\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 ==========H中,它特别引用了1349和1351行:

我已经在C/C++ > General中包含了适当的附加Include目录,在VS中的Linker > Input中包含了正确的.lib文件。我的includes也是正确的。任何洞察力都是值得欣赏的。
发布于 2021-09-04 23:41:19
我想通了。
我在ADTF插件所在的目录中遗漏了一些非常重要的Qt .dll文件。一旦我移动了核心.dlls (Qt5Charts.dll、Qt5Core.dll、Qt5Gui.dl等)添加到正确的目录,并添加以下1行代码:
QCoreApplication:addLibraryPath("C:/Users/Path/To/Qt/msvc2017_64/plugins"); // this在我实例化我的QApplication之前,它起作用了!
发布于 2021-09-03 09:41:20
ADTF不部署QtCharts二进制文件,因为许可证不兼容。Qt基本上是LGPL许可的,它与ADTF许可一起工作得很好。但有些组件是按照通用公共许可证授权的,QtCharts就是其中之一。您不允许将QtCharts与ADTF一起使用,因为这样会违反GPL中描述的组合工作规则。GPL不使用商业和封闭源代码许可证,只使用开源GPL兼容许可证,如GPL本身、MPL或其他。无论如何,因为缺少二进制文件,所以您会得到这样的错误:缺少一些依赖项。但是,即使您将二进制文件放在那里,也是不允许的,既不是私有的,也不是商业的。它不兼容,这就是为什么ADTF试图保护客户,只提供LGPL内容的原因。你甚至不允许使用开源Qt与ADTF一起使用商业Qt,因为Qt拒绝将oss与商业许可证混合在一起,即使这是相同的二进制(政治...)。唯一的机会,购买qtcharts独立从qt市场,然后它与LGPL兼容。但是你必须自己把这个二进制文件放进去。或者链接静态,这是由Qt提供的商业/市场许可证允许的。
https://stackoverflow.com/questions/69034254
复制相似问题