Question

I'm trying to use GraphicsMagick and got odd build errors, so I added #include <magick/magick.h> to

#include <stdio.h>
int main(int argc, char *argv[]){
    printf("hello magick");
    return 0;
}

just to see WTF was going on. Obviously hello_world compiles fine. Simply adding the magick header causes tons of errors compiling with any of the following:

  • clang or gcc -o test.o $(pkg-config --cflags --libs GraphicsMagick) test.c
  • clang or gcc -o test.o $(GraphicsMagick-config --cflags --libs) test.c

From clang:

zsh/2 1791 % clang -o test.o $(pkg-config --cflags --libs GraphicsMagick) test.c
In file included from test.c:2:
/usr/include/GraphicsMagick/magick/magick.h:19:9: error: unknown type name 'Image'
typedef Image
        ^
/usr/include/GraphicsMagick/magick/magick.h:20:28: error: unknown type name 'ImageInfo'
  *(*DecoderHandler)(const ImageInfo *,ExceptionInfo *);

The solution suggested by Mr. Hale (#1) works perfectly for the test. Trying in the real project; gcc spits thousands of line of errors like:

/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include/f16cintrin.h: In function ‘__m128i mm256_cvtps_ph(__m256, int)’: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include/f16cintrin.h:73:66: error: cannot convert ‘__m256 {aka float}’ to ‘__vector(8) float’ for argument ‘1’ to ‘__vector(8) short int __builtin_ia32_vcvtps2ph256(__vector(8) float, int)’ return (__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf) __A, __I);

Since the only change from having the project build successfully and the above was uncommenting either one or both of the following:

#include <magick/api.h>
#include <magick/magick.h>

I'm quite sure I've got something wrong with the build settings. I'm not having success finding documentation on what particular restrictions GraphicsMagick places on compiler/linker options. Finding that might well solve the problem.

Était-ce utile?

La solution 2

Changing from using std=c++0x to std=gnu++11 in the project-wide CXXFLAGS seems to have resolved the issue. For whatever reason, it seems that graphicsmagick 1.3.18-3 is not usable from the c/c++ APIs with std=c++0x. I know this is not a complete explanation or answer, but it makes things build.

Autres conseils

Use the <magick/api.h> header; this ensures types and forward declarations appear in the correct order.

This has been fixed in GraphicsMagick 1.3.20.

I have found this in the ChangeLog:

2014-06-15 Bob Friesenhahn

wand/magick_compat.h: Use MAGICK_ATTRIBUTE definition from magick/common.h. magick/common.h (MAGICK_ATTRIBUTE): Don't undefine __attribute__ since this may be used >by system or compiler headers. Define private macro instead. Resolves SourceForge bug #270 "Compile error with g++ -std=c++11".

RHEL/Fedora/CentOS users, check GraphicsMagick update request for EPEL7 in RedHat Bugzilla, Bug ID 1131926

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top