Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.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++ 标识符";creal";未定义-在Mac上看到,但在Linux上看不到 问题:_C++_Linux_Macos_Complextype - Fatal编程技术网

C++ 标识符";creal";未定义-在Mac上看到,但在Linux上看不到 问题:

C++ 标识符";creal";未定义-在Mac上看到,但在Linux上看不到 问题:,c++,linux,macos,complextype,C++,Linux,Macos,Complextype,下面的代码是错误的还是Mac上的头有问题?这个错误没有出现在Linux上,这让我得出结论,它不是错误的代码,尽管在Linux上成功编译并不是对ISO合规性的特别严格的测试 源代码(MCVE) 英特尔编译器 LLVM编译器 Linux 系统信息 GNU编译器 $g++-v 使用内置规格。 收集\u GCC=g++ COLLECT_LTO_WRAPPER=/opt/gcc/5.3.0/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/LTO-WRAPPER 目标:

下面的代码是错误的还是Mac上的头有问题?这个错误没有出现在Linux上,这让我得出结论,它不是错误的代码,尽管在Linux上成功编译并不是对ISO合规性的特别严格的测试

源代码(MCVE) 英特尔编译器 LLVM编译器 Linux 系统信息 GNU编译器
$g++-v
使用内置规格。
收集\u GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc/5.3.0/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/LTO-WRAPPER
目标:x86_64-unknown-linux-gnu
配置为//HOME/Realths/Works/Gcc/GCC-5.3.0/Opto--前缀=/opt/gcc/5.3.0-启用线程= POSIX启用启动检查=释放-使用系统ZLIB启用-AyxCxAyAutExt-使能语言= C,C++,fortran--使用tune=native--启用引导--启用lto--使用mpfr--使用isl--使用gmp--使用mpc--使用cloog--启用黄金--启用ld--禁用多库
线程模型:posix
gcc版本5.3.0(gcc)
$g++-c ttc-creal.cpp
英特尔编译器
$icpc-v
icpc版本17.0.0测试版(gcc版本5.3.0兼容性)
$icpc-c ttc-creal.cpp
LLVM编译器
$clang++-v
clang版本3.4.2(标签/发布号34/dot2最终版)
目标:x86_64-redhat-linux-gnu
线程模型:posix
找到候选GCC安装:/usr/bin/。/lib/GCC/x86_64-redhat-linux/4.4.4
找到候选GCC安装:/usr/bin/。/lib/GCC/x86_64-redhat-linux/4.4.7
找到候选GCC安装:/usr/lib/GCC/x86_64-redhat-linux/4.4.4
找到候选GCC安装:/usr/lib/GCC/x86_64-redhat-linux/4.4.7
所选GCC安装:/usr/bin/。/lib/GCC/x86_64-redhat-linux/4.4.7
$clang++-c ttc-creal.cpp
调查
<>我已经阅读了所有相关的<代码>复杂的.H./C>, CFielux/Cuff>和复合体我的Mac上的标题,但是不能看到这个问题的明显原因。

< P>这只是Clang对C++标准的阅读-看哪一个对我来说似乎是正确的。基本上,你不应该使用C++中的C99复杂类型和相关函数,而应该使用<代码> STD::两种复杂类型都应该是布局兼容的,并且应该能够在C和C++代码之间传递复杂数据。
g++
complex.h
包括
(在C++11模式下)和C
,因此代码使用GCC编译(在我的例子中是从自制)。我没有针对OS X的英特尔编译器,但您可以检查它对
icpc-E ttc-creal.cpp | grep complex的作用,并观察include文件扩展的顺序

叮当声:

$clang++-E ttc-creal.cpp|grep“^ 1|grep复合体
#1“/Applications/Xcode.app/Contents/Developer/toolschains/xcodefault.xctoolschain/usr/bin/。/include/c++/v1/complex.h”1 3
#1“/Applications/Xcode.app/Contents/Developer/toolschains/xcodefault.xctoolschain/usr/bin/。/include/c++/v1/ccomplex”1 3
#1“/Applications/Xcode.app/Contents/Developer/toolschains/xcodefault.xctoolschain/usr/bin/。/include/c++/v1/complex”1 3
通用条款:

$g++-5-E ttc-creal.cpp|grep“^ 1|grep复合体
#1“/usr/local/ceral/gcc/5.3.0/include/c++/5.3.0/complex.h”1 3
#1“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/complex.h”1 3 4
$g++-5-std=c++11-E ttc-creal.cpp|grep“^ 1|grep复合体
#1“/usr/local/ceral/gcc/5.3.0/include/c++/5.3.0/complex.h”1 3
#1“/usr/local/Cell/gcc/5.3.0/include/c++/5.3.0/ccomplex”1 3
#1“/usr/local/ceral/gcc/5.3.0/include/c++/5.3.0/complex”1 3
#1“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/complex.h”1 3 4
您可以通过以下方式强制Clang包含
/usr/include/complex.h

#include“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/complex.h”
您的MCVE将编译,但这样做可能是一个非常糟糕的想法(tm)

顺便说一句,FreeBSD 10.2-RELEASE与Clang 3.4.1(错误)和GCC 4.8.5(成功)的行为相同


所有的功劳都归于Potatoswatter——答案的作者,在顶部引用。

你们的MCVE甚至可以是最小的。在2#include之后,只需要一个main()和一行:
printf(“%lf”,creal(3.5))。除此之外,我还试过一些在线编译器。据了解,它是从GCC4.8.1开始工作的,但没有任何版本的Clang编译它。甚至MSVC也会给出一个错误(在和处尝试)。但我认为问题在于库,而不是编译器本身。不知道这能帮多少忙,对不起,谢谢。将此添加到我讨厌C++的原因列表中,但不幸的是,我没有编写代码,因此我无法控制它。
#include <stdio.h>
#include <complex.h>

void foo(const double *A, int *size){
   for(int i=0;i < size[0]; ++i){
      for(int j=0;j < size[1]; ++j){
         printf("(%.2e,%.2e) ", creal(A[i + j * size[0]]), cimag(A[i + j * size[0]]));
      }
   }
}
$ uname -a
Darwin redacted 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
$ icpc -v
icpc version 16.0.2 (gcc version 4.9.0 compatibility)
$ icpc -c ttc-creal.cpp 
ttc-creal.cpp(7): error: identifier "creal" is undefined
           printf("(%.2e,%.2e) ", creal(A[i + j * size[0]]), cimag(A[i + j * size[0]]));
                                  ^

ttc-creal.cpp(7): error: identifier "cimag" is undefined
           printf("(%.2e,%.2e) ", creal(A[i + j * size[0]]), cimag(A[i + j * size[0]]));
                                                             ^

compilation aborted for ttc-creal.cpp (code 2)
$ clang++ -v
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ clang++ -c ttc-creal.cpp 
ttc-creal.cpp:7:33: error: use of undeclared identifier 'creal'
         printf("(%.2e,%.2e) ", creal(A[i + j * size[0]]), cimag(A[i + j * size[0]]));
                                ^
ttc-creal.cpp:7:60: error: use of undeclared identifier 'cimag'
         printf("(%.2e,%.2e) ", creal(A[i + j * size[0]]), cimag(A[i + j * size[0]]));
                                                           ^
2 errors generated.
$ uname -a
Linux redacted 2.6.32-573.18.1.el6.centos.plus.x86_64 #1 SMP Wed Feb 10 18:09:24 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc/5.3.0/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/redacted/Work/GCC/gcc-5.3.0/configure --prefix=/opt/gcc/5.3.0 --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --enable-languages=c,c++,fortran --with-tune=native --enable-bootstrap --enable-lto --with-mpfr --with-isl --with-gmp --with-mpc --with-cloog --enable-gold --enable-ld --disable-multilib
Thread model: posix
gcc version 5.3.0 (GCC) 
$ g++ -c ttc-creal.cpp
<no error>
$ icpc -v
icpc version 17.0.0 Beta (gcc version 5.3.0 compatibility)
$ icpc -c ttc-creal.cpp
<no error>
$ clang++ -v
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.4.7
$ clang++ -c ttc-creal.cpp 
<no error>