在过去的几天里,我一直试图将GraphicsMagick纳入我的项目但是没有运气,希望这里的某些人能够帮助我(最后看看TL / DR是否也是如此)长)。
由于我需要JPEG,PNG和lcms支持,我以前使用configure和make工具下载并构建它们:
./configure CC=clang
make
sudo make install
所有这些似乎都运行正常,所以在下载GraphicsMagick后,我再次运行configure:
CC=clang CXX="clang++ -stdlib=libc++" CXXFLAGS="-stdlib=libc++" LDFLAGS="-stdlib=libc++" ./configure --enable-shared --disable-static --disable-openmp --without-xml --without-zlib --without-bzlib
然后make
创建了我的动态库:libGraphicsMagick.3.dylib
和libGraphicsMagick++.3.dylib
。当我使用MacDependency或otool
检查libGraphicsMagick ++时,我发现它链接到/usr/lib/libc++.1.dylib(而不是libstdc ++)
现在,如果我使用GraphicsMagick创建一个新项目,添加#include <Magick++.h>
(由/ usr / local / include / GraphicsMagick中的上一步安装),就是这样,实际上并没有使用任何功能我收到链接错误:
clang++ -headerpad_max_install_names -stdlib=libc++ -arch x86_64 -o TestMagickApp.app/Contents/MacOS/TestMagickApp main.o widget.o moc_widget.o -F/Library/Frameworks -L/Library/Frameworks -framework QtGui -framework QtCore
Undefined symbols for architecture x86_64:
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::gptr() const", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::underflow() in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::pbackfail(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::pptr() const", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::underflow() in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::pbackfail(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::eback() const", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::underflow() in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::pbackfail(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::egptr() const", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::underflow() in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::epptr() const", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::pbase() const", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
"std::__1::basic_iostream<char, std::__1::char_traits<char> >::basic_iostream(std::__1::basic_streambuf<char, std::__1::char_traits<char> >*)", referenced from:
std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_stringstream(unsigned int) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::setg(char*, char*, char*)", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::underflow() in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::pbackfail(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::setp(char*, char*)", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::pbump(int)", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in widget.o
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::sputc(char)", referenced from:
std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::overflow(int) in widget.o
"std::__1::basic_ios<char, std::__1::char_traits<char> >::basic_ios()", referenced from:
std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_stringstream(unsigned int) in widget.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [TestMagickApp.app/Contents/MacOS/TestMagickApp] Error 1
19:43:22: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project TestMagickApp (kit: 4.8.5)
When executing step 'Make'
但是只有当我尝试使用libc ++时才会发生这种情况,如果我尝试使用libstdc ++,它会毫无问题地链接(但是如果我仍然在考虑直接思考,那么只要我尝试使用任何功能就会出错)。
我尝试只包含某些文件来缩小问题范围,而且似乎是由/usr/local/include/GraphicsMagick/magick/common.h
内的这段代码引起的:
/*
Support for __attribute__ was added in GCC 2.0. It is not supported
in strict ANSI mode which is indicated by __STRICT_ANSI__ being
defined.
http://www.ohse.de/uwe/articles/gcc-attributes.html
Note that GCC 3.2 on MinGW does not define __GNUC__ or __GNUC_MINOR__.
*/
#if !defined(__attribute__)
# if (!defined(__GNUC__) || (__GNUC__ < 2 || __STRICT_ANSI__))
# define __attribute__(x) /*nothing*/
# else
# if (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) /* 3.1+ */
# define MAGICK_FUNC_DEPRECATED __attribute__((__deprecated__))
# endif
# if (__GNUC__ >= 3) /* 3.0+ */
# define MAGICK_FUNC_MALLOC __attribute__((__malloc__))
# endif
# if (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))) /* 3.3+ */
/* Supports argument syntax like __attribute__((nonnull (1, 2))) but
don't know how to support non-GCC fallback. */
# define MAGICK_FUNC_NONNULL __attribute__((__nonnull__))
# endif
# if (((__GNUC__) > 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5))) /* 2.5+ */
# define MAGICK_FUNC_NORETURN __attribute__((__noreturn__))
# endif
# if ((__GNUC__) >= 3) /* 2.96+ */
# define MAGICK_FUNC_PURE __attribute__((__pure__))
# endif
# if (((__GNUC__) > 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7))) /* 2.7+ */
# define MAGICK_FUNC_UNUSED __attribute__((__unused__))
# endif
# if (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))) /* 3.3+ */
# define MAGICK_FUNC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
# endif
# if (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))) /* 4.3+ */
# define MAGICK_FUNC_ALLOC_SIZE_1ARG(arg_num) __attribute__((__alloc_size__(arg_num)))
# define MAGICK_FUNC_ALLOC_SIZE_2ARG(arg_num1,arg_num2) __attribute__((__alloc_size__(arg_num1,arg_num2)))
# define MAGICK_FUNC_HOT __attribute__((__hot__))
# define MAGICK_FUNC_COLD __attribute__((__cold__))
# define MAGICK_OPTIMIZE_FUNC(opt) __attribute__((__optimize__ (opt)))
# endif
# if (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) /* 4.7+ */
# define MAGICK_ASSUME_ALIGNED(exp,align) __builtin_assume_aligned(exp,align)
# define MAGICK_ASSUME_ALIGNED_OFFSET(exp,align,offset) __builtin_assume_aligned(exp,align,offset)
# endif
# endif
#endif
现在我不太了解这段代码,但它似乎支持真正的旧编译器(GCC版本&lt; 2 !!)。如果我对整个部分进行评论,它似乎编译得很好,但由于我不知道它在做什么,评论它感觉有点风险/怪异,因为它是一个只读文件,它有点像无论如何,我想我不应该把它弄得一团糟。
对于它的价值,使用GraphicsMagick的应用程序也使用Qt 4.8.5,我使用QtCreator和QMake,但我不认为它是相关的这里。我也尝试过Qt 5.1和5.2,但没有运气。
clang++ --version
返回Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
(我知道它不是最新版本,但我不想改变它。)
TL / DR:
有没有人对使用libc ++编译GraphicsMagick有任何经验/反馈?
有人可以向我解释上面的最后一段代码是做什么的吗?当我评论它时,为什么它会起作用呢?
你能发现我做过的任何错事吗?我做了几次整个过程,但也许我忘记了一些明显的事情......
非常欢迎任何帮助。