【发布时间】:2021-11-25 20:39:09
【问题描述】:
我正在尝试将 dbus-cxx 用于我正在处理的 C++ 项目。我的项目需要 IPC,我正在尝试使用 dbus-cxx 来完成它。我克隆了存储库,并使用 cmake 为 VS 2019 生成文件。我试图在 VS 2019 上构建 signal_emitter.cpp 和 signal_receiver.cpp,但它不起作用。
我已在 Additional Include Directories 中为我的项目添加了必要的目录,因此头文件包含工作。
错误是dbus-cxx需要C++17。
当我尝试构建我的两个 cpps 时出现错误消息:
1>------ Rebuild All started: Project: ZERO_CHECK, Configuration: Release x64 ------
1>Checking Build System
2>------ Rebuild All started: Project: signal-emitter, Configuration: Release x64 ------
3>------ Rebuild All started: Project: signal-receiver, Configuration: Release x64 ------
2>Building Custom Rule C:/Users/wangjes/Documents/GitHub/dbus-cxx/examples/basics/signals/src/CMakeLists.txt
2>signal_emitter.cpp
2>C:\Users\wangjes\Documents\GitHub\dbus-cxx\dbus-cxx.h(23,1): fatal error C1189: #error: "dbus-cxx requires at least C++17."
3>Building Custom Rule C:/Users/wangjes/Documents/GitHub/dbus-cxx/examples/basics/signals/src/CMakeLists.txt
2>Done building project "signal-emitter.vcxproj" -- FAILED.
3>signal_receiver.cpp
3>C:\Users\wangjes\Documents\GitHub\dbus-cxx\dbus-cxx.h(23,1): fatal error C1189: #error: "dbus-cxx requires at least C++17."
3>Done building project "signal-receiver.vcxproj" -- FAILED.
4>------ Skipped Rebuild All: Project: ALL_BUILD, Configuration: Release x64 ------
4>Project not selected to build for this solution configuration
========== Rebuild All: 1 succeeded, 2 failed, 1 skipped ==========
我右键单击我的项目 > 属性 > 配置属性 > 常规,然后选择 C++ 语言标准旁边的 ISO C++17 标准 (std::c++17)。所以,我知道它确实在使用 C++17。
以前有没有人有任何见解或看到过这个错误?我使用的是 C++17,所以我不确定实际问题是什么。
编辑:我看到这个suggested post 与我的问题相似。但是,这个问题没有回答我的问题,这就是为什么当我需要的 VS 版本符合要求时 dbus-cxx 仍然给我一个错误。
但是,我用这个问题来帮助我准确确定我在 VS 2019 中使用的 __cplusplus 版本。我的 __cplusplus 值为 199711L。我找到了触发这个错误出现的那一行,在dbus-cxx.h。
/***************************************************************************
* Copyright (C) 2007,2009,2010 by Rick L. Vinyard, Jr. *
* rvinyard@cs.nmsu.edu *
* *
* This file is part of the dbus-cxx library. *
* *
* The dbus-cxx library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* version 3 as published by the Free Software Foundation. *
* *
* The dbus-cxx library is distributed in the hope that it will be *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this software. If not see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#define STRING2(x) #x
#define STRING(x) STRING2(x)
#pragma message(STRING(__cplusplus))
#ifndef DBUSCXX_DBUS_H
#define DBUSCXX_DBUS_H
#if !(__cplusplus >= 201703L)
#error "dbus-cxx requires at least C++17."
#endif
#include <dbus-cxx/dbus-cxx-config.h>
#include <dbus-cxx/callmessage.h>
#include <dbus-cxx/connection.h>
#include <dbus-cxx/signal.h>
#include <dbus-cxx/dispatcher.h>
#include <dbus-cxx/enums.h>
#include <dbus-cxx/error.h>
#include <dbus-cxx/errormessage.h>
#include <dbus-cxx/interface.h>
#include <dbus-cxx/interfaceproxy.h>
#include <dbus-cxx/messageappenditerator.h>
#include <dbus-cxx/message.h>
#include <dbus-cxx/messageiterator.h>
#include <dbus-cxx/methodbase.h>
#include <dbus-cxx/methodproxybase.h>
#include <dbus-cxx/object.h>
#include <dbus-cxx/objectproxy.h>
#include <dbus-cxx/pendingcall.h>
#include <dbus-cxx/returnmessage.h>
#include <dbus-cxx/signalbase.h>
#include <dbus-cxx/signalmessage.h>
#include <dbus-cxx/signalproxy.h>
#include <dbus-cxx/signature.h>
#include <dbus-cxx/signatureiterator.h>
#include <dbus-cxx/utility.h>
#include <dbus-cxx/variant.h>
#include <dbus-cxx/filedescriptor.h>
#include <dbus-cxx/simplelogger_defs.h>
#include <dbus-cxx/standalonedispatcher.h>
#include <dbus-cxx/propertyproxy.h>
#include <dbus-cxx/property.h>
#endif
我在顶部添加了三行代码,以找出我正在运行的 __cplusplus 版本。
【问题讨论】:
-
我不确定这些数字是否可移植,因此使用 MSC 而不是 GCC 可能是原因。在任何情况下,如果还不支持,请检查上游 bugtracker 并提交使用 MSC 编译的功能请求!