我需要將C庫的頭文件包含到我的C++ 11代碼中。現在,標題提供了例程和數據結構,涉及大量的double complex
。例如,在C++中使用C鏈接的複雜類型11
#include <complex.h>
//..
typedef struct parameters
{
// ...
double complex Vud;
} parameters;
// ...
double complex polylog(int n, int m, double x);
我把這個文件到我的包在extern "C" { #include "include.h" }
C++ 11源(這是實際的文件名,信不信由你)。如果我添加了-std = C++ 11,g ++(嘗試4.7.3和4.8.2)和clang(3.3)會變得很糟糕。
數以百萬計的g ++錯誤的行包括大量的:
include/g++-v4/cmath:98:3: error: template with C linkage
而且鐺給出:
cmath:84:3: error: declaration conflicts with target of using declaration already in scope
abs(double __x)
^
/usr/include/stdlib.h:773:12: note: target of using declaration
extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/cstdlib:245:14: note: using declaration
using std::abs;
^
我不知道如何來解決這個問題。什麼是正確的方法來做到這一點?顯然這些必須是可互操作的,但我不知道這個竅門。
聽起來像是在全局命名空間級別使用名稱空間標準或使用std :: complex,可能首先包含頭文件。嘗試在一個**最小程序**中包含C標頭。 –
↑哦,我測試了它,編譯器真的讓一些名爲'complex'的模板(可擴展爲'_Complex')混淆宏'complex',推測是'std :: complex'模板。奇怪的。無論如何,我認爲沒有辦法在C++中使用C語法,然後**預處理**頭部,可能需要手動。 –
@Alf,這裏是hello-world,它只是在「C」鏈接中包含頭文件(帶有一些clang錯誤輸出):http://ideone.com/tkZb4d – sujeet