C ++编译遇到了boost interprocess lib'错误:`:: ftruncate'尚未声明'

时间:2017-12-28 13:07:15

标签: 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::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_NT-6.1-WOW abcd 2.9.0(0.318/5/3) 2017-09-12 10:41 i686 Cygwin

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

欢迎任何想法/建议。

TIA

更新#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

更新#2:(使用新的CPPFLAG - &gt; -D_XOPEN_SOURCE=500

In file included from /usr/include/boost/assert.hpp:58:0,
                 from /usr/include/boost/range/size.hpp:23,
                 from /usr/include/boost/range/functions.hpp:20,
                 from /usr/include/boost/range/iterator_range_core.hpp:38,
                 from /usr/include/boost/range/iterator_range.hpp:13,
                 from /usr/include/boost/range/as_literal.hpp:22,
                 from /usr/include/boost/algorithm/string/case_conv.hpp:19,
                 from netbase.cpp:25:
netbase.cpp: In function `bool LookupIntern(const char*, std::vector<CNetAddr>&, unsigned int, bool)':
netbase.cpp:95:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in));
                    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
netbase.cpp:101:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in6));
                    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
netbase.cpp: In function `std::string NetworkErrorString(int)':
netbase.cpp:720:41: error: `strerror_r' was not declared in this scope
     if (strerror_r(err, buf, sizeof(buf)))
                                         ^

2 个答案:

答案 0 :(得分:0)

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

#include <unistd.h>
#include <sys/types.h>

在包含boost进程头之前尝试包含这些内容。如果它仍然无法识别这些功能,显然Cygwin不支持这些功能。

授予POSIX standard文档

答案 1 :(得分:0)

在我的情况下,我在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回退到较低的标准(您可能不需要),第三行启用特定于编译器的扩展,例如gcc使用-std=gnu++11代替-std=c++11。默认情况下,该变量为ON,但我认为露骨是无害的。