【发布时间】:2019-02-17 00:56:31
【问题描述】:
背景
我正在尝试为在 Raspberry 3 上运行的 Rasbian 构建一个示例 REST api 应用程序。我使用了cpprestsdk。
示例包含以下头文件:
#include <condition_variable>
#include <mutex>
#include <iostream>
static std::condition_variable _condition;
static std::mutex _mutex;
namespace cfx {
class InterruptHandler {
public:
static void hookSIGINT() {
signal(SIGINT, handleUserInterrupt);
}
static void handleUserInterrupt(int signal){
if (signal == SIGINT) {
std::cout << "SIGINT trapped ..." << '\n';
_condition.notify_one();
}
}
static void waitForUserInterrupt() {
std::unique_lock<std::mutex> lock { _mutex };
_condition.wait(lock);
std::cout << "user has signaled to interrup program..." << '\n';
lock.unlock();
}
};
}
问题
在 MacOS 上编译时没有问题。
但是,在 rasbian 中编译时,我收到 error: 'SIGINT' was not declared in this scope 错误。
很明显,SIGINT 定义 - #define SIGINT 2 或类似的 - 在 rasbian 上编译时无法访问。
问题
为什么我在 rasbian 上收到此错误,但在 macOS 上却没有?是不是因为编译器找不到signal.h?
我确保 CMakeLists.txt 中的 include_directories 包含必需的包含路径。
更新
当我手动添加 #include <csignal> 时错误已解决。
【问题讨论】:
-
signal.h丢失
标签: c++11 makefile cmake raspbian cpprest-sdk