Menu

#270 Compile error with g++ -std=c++11

v1.0_(example)
closed-fixed
build (5)
5
2014-06-15
2014-06-15
No

A C++ program that does simply

#include <Magick++.h>

fails to compile with g++ -std=c++11. I'm using GCC 4.9.0 on Linux x86 with GraphicsMagick 1.3.19.

This is because Magick++.h indirectly includes magick/common.h, which has

#if !defined(__attribute__)
#  if (!defined(__GNUC__) || (__GNUC__ < 2 || __STRICT_ANSI__))
#    define __attribute__(x) /*nothing*/
#  endif
#else
  (omitted)
#endif

It looks like the -std=c++11 flag causes GCC to define __STRICT_ANSI__, causing the above code to define __attribute__ as nothing. And this breaks some internal GCC headers (/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/include/x86intrin.h for me).

See also:
* http://sourceforge.net/p/graphicsmagick/mailman/message/31837298/
* http://stackoverflow.com/questions/22795033/linking-graphicsmagick-on-mac-osx-10-8-with-clang-and-libc

Discussion

  • Carlo Teubner

    Carlo Teubner - 2014-06-15

    As a workaround, I'm doing

    #undef __STRICT_ANSI__
    #include <Magick++.h>
    #define __STRICT_ANSI__ 1
    

    which gets around the problem.

     
  • Carlo Teubner

    Carlo Teubner - 2014-06-15

    The actual error is

    In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/include/x86intrin.h:29:0,
                 from /usr/include/c++/4.9.0/x86_64-unknown-linux-gnu/bits/opt_random.h:33,
                 from /usr/include/c++/4.9.0/random:50,
                 from /usr/include/c++/4.9.0/bits/stl_algo.h:66,
                 from /usr/include/c++/4.9.0/algorithm:62,
                 from main.cpp:11:
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/include/mmintrin.h: In function __m64 _mm_cvtsi32_si64(int):
    /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/include/mmintrin.h:64:54: error: cant convert between vector values of different size
       return (__m64) __builtin_ia32_vec_init_v2si (__i, 0);
                                                          ^
    

    and a huge number of similar ones.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-06-15
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-06-15

    Thanks for identifying the source of the problem. Apparently when I decided that defining attribute(x) to nothing was a good idea, I did not consider that it might be used in other header files.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-06-15

    Fixed by Mercurial changeset 14082:f837cdfd1544 and will appear in the next development snapshot.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2014-06-15
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB