2017-05-26 86 views
0

我正在擴展一個項目,它用c99編譯一些庫,用C++ 11編譯一個庫,並在c99庫中使用complex.h複數。如何用C++編譯c複數11

我知道這可能是一個愚蠢的想法,但它不是我的,我需要使它以某種方式工作。

該代碼不能用gcc4.9和-std = C++ 11進行編譯,而且我完全不知道該怎麼做。我如何編寫此代碼段?

#include <complex.h> 
#include <cstdio> 

int main(int argc, char * argv[]) { 
    double _Complex a = 3.0 + 0.0 * _Complex_I; 
    //printf("%lf\n", creal(a)); 
    return 0; 
} 

給出了錯誤

In file included from /usr/local/include/c++/7.1.0/complex.h:36:0, 
       from main.cpp:1: 
main.cpp: In function 'int main(int, char**)': 
main.cpp:5:33: error: unable to find numeric literal operator 'operator""iF' 
    double _Complex a = 3.0 + 0.0 _Complex_I; 
           ^
main.cpp:5:33: note: use -std=gnu++11 or -fext-numeric-literals to enable more built-in suffixes 
main.cpp:5:33: error: expression cannot be used as a function 
    double _Complex a = 3.0 + 0.0 _Complex_I; 
           ^
main.cpp:5:19: warning: unused variable 'a' [-Wunused-variable] 
    double _Complex a = 3.0 + 0.0 _Complex_I; 

g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out 

-std = GNU ++ 11件作品看起來,但有沒有辦法讓它與-std = C工作++ 11?

+0

不應該是'雙複雜a = 3.0 + 0.0 * _Complex_I;'? (注意'*') –

+0

沒錯。我糾正了它 – Philipp

回答

1

如何編譯C複數用C++ 11

你不知道。標準C++不支持<complex.h> C庫標頭。

或者:

  • 使用GCC語言擴展。
  • 爲處理C複數的任何事物實現一個包裝函數,該函數提供的接口不使用C複數。在C中實現包裝器並使用C++中的包裝器。請使用std::complex代替。
+0

這真的很傷心。 -std = gnu ++ 11會在Windows上編譯嗎?感謝您的選擇! – Philipp

+0

@Philipp你可以試試Windows的Minimalist GNU。 – user2079303

+0

謝謝,mingw似乎支持-std = gnu ++ 11 – Philipp