#1374: C++ complex implementation fails to compile ----------------------+----------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: new Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: development version Keywords: | ----------------------+----------------------------------------------------- When compiling I get: {{{ COMPILING /home/knarf/Cactus/arrangements/CactusCoastal/Funwave/src/declare.cc In file included from /usr/include/c++/4.7/complex:46:0, from /home/knarf/Cactus/src/include/cctk_Types.h:40, from /home/knarf/Cactus/src/include/cctk_Groups.h:34, from /home/knarf/Cactus/arrangements/CactusCoastal/Funwave/src/cctk_declare.h:9, from /home/knarf/Cactus/configs/sim/build/Funwave/declare.cc:1: /usr/include/c++/4.7/cmath: In function ‘constexpr float std::abs(float)’: /usr/include/c++/4.7/cmath:90:16: error: declaration of C function ‘constexpr float std::abs(float)’ conflicts with /usr/include/c++/4.7/cmath:84:3: error: previous declaration ‘constexpr double std::abs(double)’ here /usr/include/c++/4.7/cmath: In function ‘constexpr long double std::abs(long double)’: /usr/include/c++/4.7/cmath:94:22: error: declaration of C function ‘constexpr long double std::abs(long double)’ conflicts with /usr/include/c++/4.7/cmath:90:3: error: previous declaration ‘constexpr float std::abs(float)’ here /usr/include/c++/4.7/cmath:94:22: error: declaration of C function ‘constexpr long double std::abs(long double)’ conflicts with /usr/include/c++/4.7/cmath:84:3: error: previous declaration ‘constexpr double std::abs(double)’ here /usr/include/c++/4.7/cmath: At global scope: /usr/include/c++/4.7/cmath:98:3: error: template with C linkage }}}
This seems to be caused by cctk_Groups.h going into "C" linkage, then including cctk_Types.h which includes <complex> when compiled with C++. The system complex implementation however (at least in CXX0X mode) uses templates, which aren't allowed with "C" linkage.
I use gnu g++ version 4.7 with -std=gnu++0x.
Applying the following patch to src/include/cctk_Types.h solves the problem for me: {{{ Index: cctk_Types.h =================================================================== --- cctk_Types.h (revision 5021) +++ cctk_Types.h (working copy) @@ -37,7 +37,9 @@ /* Declarations for complex types */
#ifdef __cplusplus +extern "C++" { # include <complex> +} #endif
#ifdef HAVE_CCTK_REAL16 }}}
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: review Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: development version Resolution: | Keywords: -----------------------+---------------------------------------------------- Changes (by knarf):
* status: new => review
Comment:
We might want to apply this as well to the release, thus using ET_2013_05 milestone.
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: review Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: development version Resolution: | Keywords: -----------------------+----------------------------------------------------
Comment (by eschnett):
It is considered bad style to #include another file with anything but default linkage. The #include statement in cctk_Groups.h should be moved outside the extern "C" block.
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: review Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: development version Resolution: | Keywords: -----------------------+----------------------------------------------------
Comment (by knarf):
That would correspond to the following, which also works for me: {{{ Index: cctk_Groups.h =================================================================== --- cctk_Groups.h (revision 5021) +++ cctk_Groups.h (working copy) @@ -26,13 +26,13 @@
/* Prototypes */
+#include "cctk_Types.h" + #ifdef __cplusplus extern "C" { #endif
-#include "cctk_Types.h" - int CCTK_DecomposeName(const char *fullname, char **implementation, char **name); }}}
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: reviewed_ok Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: development version Resolution: | Keywords: -----------------------+---------------------------------------------------- Changes (by eschnett):
* status: review => reviewed_ok
Comment:
Approved.
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: reviewed_ok Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: development version Resolution: | Keywords: -----------------------+----------------------------------------------------
Comment (by knarf):
Committed to the development version in r5022. Will be committed to the release branch in a little while (thus, leaving ticket open).
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: reviewed_ok Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: ET_2013_05 Resolution: | Keywords: -----------------------+---------------------------------------------------- Changes (by knarf):
* version: development version => ET_2013_05
#1374: C++ complex implementation fails to compile -----------------------+---------------------------------------------------- Reporter: knarf | Owner: Type: defect | Status: closed Priority: critical | Milestone: ET_2013_05 Component: Cactus | Version: ET_2013_05 Resolution: fixed | Keywords: -----------------------+---------------------------------------------------- Changes (by knarf):
* status: reviewed_ok => closed * resolution: => fixed
Comment:
Also committed to ET_2013_05, r5032.
trac@lists.einsteintoolkit.org