编译CPP应用程序时出错。 “错误:'posix_memalign'未在此范围内声明”

时间:2023-01-03 06:57:54

I'm trying to compile a CPP application (an open source project) in the latest cygwin64 environment using g++ 6.4.0 and I get the following error:

我正在尝试使用g ++ 6.4.0在最新的cygwin64环境中编译CPP应用程序(一个开源项目),我收到以下错误:

error: 'posix_memalign' was not declared in this scope

错误:未在此范围内声明'posix_memalign'

now posix_memlign can be found in stdlib.h if you compile the most simple CPP "hello world" application there wouldn't be a problem calling posix_memlign.

现在posix_memlign可以在stdlib.h中找到,如果编译最简单的CPP“hello world”应用程序,调用posix_memlign就不会有问题。

The make file of the project report the following setup for the compilation

项目的make文件报告以下编译设置

g++ -DHAVE_CONFIG_H -I. -Wall -Wnon-virtual-dtor -I. -I./include -g -O3 -std=c++0x -g -O3 -std=c++0x -MT lib/rectangular_binary_matrix.lo -MD -MP -MF lib/.deps/rectangular_binary_matrix.Tpo -c lib/rectangular_binary_matrix.cc -DDLL_EXPORT -DPIC -o lib/.libs/rectangular_binary_matrix.o

g ++ -DHAVE_CONFIG_H -I。 -Wall -Wnon-virtual-dtor -I。 -I./include -g -O3 -std = c ++ 0x -g -O3 -std = c ++ 0x -MT lib / rectangular_binary_matrix.lo -MD -MP -MF lib / .deps / rectangular_binary_matrix.Tpo -c lib / rectangular_binary_matrix.cc -DDLL_EXPORT -DPIC -o lib / .libs / rectangular_binary_matrix.o

so it doesn't look like it override the default include path. Any ideas?

所以看起来它不会覆盖默认的包含路径。有任何想法吗?

p.s. I was able to build the code on Linux (Redhat) without a problem.

附:我能够在Linux(Redhat)上构建代码没有问题。

1 个解决方案

#1


0  

posix_memalign is not part of the C Standard Library or the C++ Standard library and the cygwin GCC compilers do not provide it, although other compilers may do so, including GCC compilers from other builders.

posix_memalign不是C标准库或C ++标准库的一部分,并且cygwin GCC编译器不提供它,尽管其他编译器可能会这样做,包括来自其他构建器的GCC编译器。

You might consider using instead the C Standard function aligned_alloc, if you feel comfortable to edit your project source. It is provided in <cstdlib> for C++ compilation in cygwin g++ 6.4.0

如果您觉得编辑项目源感觉很舒服,可以考虑使用C标准函数aligned_alloc。它在 中提供,用于cygwin g ++ 6.4.0中的C ++编译

Later

I do see the function in C:\cygwin64\usr\include\stdlib.h...

我确实在C:\ cygwin64 \ usr \ include \ stdlib.h中看到了这个函数...

The fact that you can find the function declaration in the header file does not mean that the compiler can see it after preprocessing. The same source header may be used by many builders, exposing different declarations to the compiler depending on the builder's settings of implementor macros. In this case, the declaration is concealed from your compiler by the fact that __POSIX_VISIBLE >= 200112 is false. Identifiers beginning __ are reserved for implementors. See the explanation of this macro and note the comment:

您可以在头文件中找到函数声明这一事实并不意味着编译器可以在预处理后看到它。许多构建器可以使用相同的源头,根据构建器宏的构建器设置向编译器公开不同的声明。在这种情况下,__POSIX_VISIBLE> = 200112为false时,声明会从编译器中隐藏。以__开头的标识符保留给实现者。请参阅此宏的说明并注意注释:

 * The following private macros are used throughout the headers to control
 * which symbols should be exposed.  They are for internal use only, as
 * indicated by the leading double underscore, and must never be used outside
 * of these headers.

#1


0  

posix_memalign is not part of the C Standard Library or the C++ Standard library and the cygwin GCC compilers do not provide it, although other compilers may do so, including GCC compilers from other builders.

posix_memalign不是C标准库或C ++标准库的一部分,并且cygwin GCC编译器不提供它,尽管其他编译器可能会这样做,包括来自其他构建器的GCC编译器。

You might consider using instead the C Standard function aligned_alloc, if you feel comfortable to edit your project source. It is provided in <cstdlib> for C++ compilation in cygwin g++ 6.4.0

如果您觉得编辑项目源感觉很舒服,可以考虑使用C标准函数aligned_alloc。它在 中提供,用于cygwin g ++ 6.4.0中的C ++编译

Later

I do see the function in C:\cygwin64\usr\include\stdlib.h...

我确实在C:\ cygwin64 \ usr \ include \ stdlib.h中看到了这个函数...

The fact that you can find the function declaration in the header file does not mean that the compiler can see it after preprocessing. The same source header may be used by many builders, exposing different declarations to the compiler depending on the builder's settings of implementor macros. In this case, the declaration is concealed from your compiler by the fact that __POSIX_VISIBLE >= 200112 is false. Identifiers beginning __ are reserved for implementors. See the explanation of this macro and note the comment:

您可以在头文件中找到函数声明这一事实并不意味着编译器可以在预处理后看到它。许多构建器可以使用相同的源头,根据构建器宏的构建器设置向编译器公开不同的声明。在这种情况下,__POSIX_VISIBLE> = 200112为false时,声明会从编译器中隐藏。以__开头的标识符保留给实现者。请参阅此宏的说明并注意注释:

 * The following private macros are used throughout the headers to control
 * which symbols should be exposed.  They are for internal use only, as
 * indicated by the leading double underscore, and must never be used outside
 * of these headers.