Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;编译使用boost进程间库';错误:`::ftruncate';尚未声明';_C++_Boost_Cygwin - Fatal编程技术网

C++ C++;编译使用boost进程间库';错误:`::ftruncate';尚未声明';

C++ C++;编译使用boost进程间库';错误:`::ftruncate';尚未声明';,c++,boost,cygwin,C++,Boost,Cygwin,这是我运行make时得到的结果: In file included from /usr/include/boost/interprocess/sync/file_lock.hpp:25:0, from init.cpp:61: /usr/include/boost/interprocess/detail/os_file_functions.hpp: In function `bool boost::interprocess::ipcdetail::truncat

这是我运行
make
时得到的结果:

In file included from /usr/include/boost/interprocess/sync/file_lock.hpp:25:0,
                 from init.cpp:61:
/usr/include/boost/interprocess/detail/os_file_functions.hpp: In function `bool boost::interprocess::ipcdetail::truncate_file
(boost::interprocess::file_handle_t, std::size_t)':
/usr/include/boost/interprocess/detail/os_file_functions.hpp:489:16: error: `::ftruncate' has not been declared
    return 0 == ::ftruncate(hnd, off_t(size));
                ^~
init.cpp: In function `void registerSignalHandler(int, void (*)(int))':
init.cpp:302:22: error: aggregate `registerSignalHandler(int, void (*)(int))::sigaction sa' has incomplete type and cannot be
 defined
     struct sigaction sa;
                      ^~
init.cpp:304:28: error: `sigemptyset' was not declared in this scope
     sigemptyset(&sa.sa_mask);
                            ^
init.cpp:306:35: error: invalid use of incomplete type `struct registerSignalHandler(int, void (*)(int))::sigaction'
     sigaction(signal, &sa, nullptr);
                                   ^
init.cpp:302:12: note: forward declaration of `struct registerSignalHandler(int, void (*)(int))::sigaction'
     struct sigaction sa;
            ^~~~~~~~~
我在cygwin上

$uname-a
CYGWIN\u NT-6.1-WOW abcd 2.9.0(0.318/5/3)2017-09-12 10:41 i686 CYGWIN

我不确定是否所有的构建错误都与缺少的::ftruncate有关,但我想从这里开始

欢迎提出任何想法/建议

短暂性脑缺血发作

更新#1: /usr/include/boost/interprocess/detail/os_file_functions.hpp确实包含所需的标题:

#if defined (BOOST_INTERPROCESS_WINDOWS)
#  include <boost/interprocess/detail/win32_api.hpp>
#else
#  ifdef BOOST_HAS_UNISTD_H
#     include <fcntl.h>
#     include <unistd.h>
#     include <sys/types.h>
#     include <sys/stat.h>
#     include <errno.h>
#     include <cstdio>
#     include <dirent.h>
#     if 0
#        include <sys/file.h>
#     endif
#  else
#    error Unknown platform
#  endif
#endif

显然,标题缺少一些必需的包含项
man-ftruncate
告诉我您需要

#include <unistd.h>
#include <sys/types.h>
#包括
#包括
在包含boost进程间头文件之前,请尝试包含这些文件。如果它仍然无法识别这些功能,那么Cygwin显然不支持这些功能


在我的例子中,我在cygwin下用自己的CMake项目得到了这些错误,因为我试图用
-std=c++11
构建,而在cygwin下这意味着g++将是严格的,不包括ftruncate或strdup。解决方案是添加
-std=gnu++11
或设置:

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

第一行设置CXX标准(gcc的
-std
选项),第二行防止CMake回落到较低的标准(您可能不需要),第三行启用编译器特定的扩展,如
-std=gnu++11
,而不是
-std=c++11
。默认情况下,该变量是
开的
,但我认为明确无误。

您是否检查过在前面添加include是否有帮助?我意识到这可能是一个库头缺陷。我刚刚输入了我的响应,但我想我会继续更新OP:)。请参阅更新1。我的问题是正确的。这是值得的。您真的想知道Cygwin的POSIX功能是否有问题,或者与boost相关的问题。不同的问题我要试试这个,看看它是怎么回事。。。。。。我想我可能需要
newlib
,因为
glibc
在cygwin中不可用。我假设“error:`strerror\u r'未在此范围内声明”与此相关。想法/建议?只是遇到了同样的问题,因为我不小心用C++11编译。谢谢你的解决方案。
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)