我试图在Ubuntu12.04x64上编译一个应用程序。
它是在带有clang 3.2的osx上构建的,使用了新的c++11标准,并且具有boost和graphicsmagick++的依赖性,运行良好。
使用gcc 4.8.1编译时产生编译器崩溃。不幸的是,我们必须尽快发布软件,不能等待gcc修复错误。
在linux上对clang进行了一些尝试和错误,并阅读了一些邮件列表之后,我根据本文https://plus.google.com/u/0/+DeWittClinton/posts/Vr7y8TPsKgR使用clang 3.3和libc++(以及libc++abi)对其进行了编译。所有与boost(仅头文件和共享对象libs)相关的单元测试都执行得很好。
在我们开始链接到graphicsmagick++之后,它会导致下面未定义的引用错误。
"/usr/bin/ld" -export-dynamic -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o ../test_xxx_import /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/local/lib/ -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. -L/lib -L/usr/lib -lc++ -lc++abi CMakeFiles/test_xxx_import.dir/xxx_http_binding_test.cpp.o CMakeFiles/test_xxx_import.dir/resource_test.cpp.o CMakeFiles/test_xxx_import.dir/slugify_test.cpp.o CMakeFiles/test_xxx_import.dir/product_test.cpp.o CMakeFiles/test_xxx_import.dir/field_semantic_test.cpp.o CMakeFiles/test_xxx_import.dir/files.index-parser_test.cpp.o CMakeFiles/test_xxx_import.dir/thread_pool_test.cpp.o CMakeFiles/test_xxx_import.dir/container_sink_test.cpp.o CMakeFiles/test_xxx_import.dir/factories_test.cpp.o CMakeFiles/test_xxx_import.dir/thread_safe_queue_test.cpp.o CMakeFiles/test_xxx_import.dir/container_device_test.cpp.o CMakeFiles/test_xxx_import.dir/product_catalog_test.cpp.o CMakeFiles/test_xxx_import.dir/config_object_test.cpp.o CMakeFiles/test_xxx_import.dir/sha1_test.cpp.o CMakeFiles/test_xxx_import.dir/resize_test.cpp.o CMakeFiles/test_xxx_import.dir/redis_connection_test.cpp.o CMakeFiles/test_xxx_import.dir/redis_util_test.cpp.o CMakeFiles/test_xxx_import.dir/redis_product_test.cpp.o CMakeFiles/test_xxx_import.dir/redis_string_util_test.cpp.o CMakeFiles/test_xxx_import.dir/redis_task_queue_test.cpp.o CMakeFiles/test_xxx_import.dir/stream_manipulator_test.cpp.o CMakeFiles/test_xxx_import.dir/category_info_test.cpp.o CMakeFiles/test_xxx_import.dir/localized_string_test.cpp.o CMakeFiles/test_xxx_import.dir/product_description_test.cpp.o CMakeFiles/test_xxx_import.dir/product_picture_test.cpp.o CMakeFiles/test_xxx_import.dir/product_relation_test.cpp.o CMakeFiles/test_xxx_import.dir/supplier_test.cpp.o CMakeFiles/test_xxx_import.dir/summary_description_test.cpp.o CMakeFiles/test_xxx_import.dir/summary_descriptions_test.cpp.o CMakeFiles/test_xxx_import.dir/stage_base_test.cpp.o CMakeFiles/test_xxx_import.dir/thread_reclaimer_test.cpp.o CMakeFiles/test_xxx_import.dir/product_sheet_download_test.cpp.o CMakeFiles/test_xxx_import.dir/image_scaling_test.cpp.o CMakeFiles/test_xxx_import.dir/image_download_test.cpp.o CMakeFiles/test_xxx_import.dir/product_data_sheet_parser_test.cpp.o ../libxxx_import.a /usr/local/lib/libboost_unit_test_framework.a /usr/local/lib/libboost_thread.a /usr/local/lib/libboost_date_time.a /usr/local/lib/libGraphicsMagick++.a /usr/local/lib/libboost_filesystem.a /usr/local/lib/libboost_system.a /usr/local/lib/libboost_exception.a /usr/local/lib/libboost_chrono.a /usr/local/lib/libboost_log.a /usr/local/lib/libPocoNet.so /usr/local/lib/libPocoFoundation.so /usr/local/lib/libPocoNetSSL.so /usr/local/lib/libPocoUtil.so -Bstatic -lexpat -lhiredis -Bdynamic /usr/local/lib/libboost_date_time.a /usr/local/lib/libGraphicsMagick++.a -rpath /usr/local/lib -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
/usr/local/lib/libGraphicsMagick++.a(Image.o): In function `Magick::Image::signature(bool) const':
/home/xxx_import/temp/GraphicsMagick-1.3.18/Magick++/lib/Image.cpp:3271: undefined reference to `GetImageAttribute'
/home/xxx_import/temp/GraphicsMagick-1.3.18/Magick++/lib/Image.cpp:3274: undefined reference to `SignatureImage'
/home/xxx_import/temp/GraphicsMagick-1.3.18/Magick++/lib/Image.cpp:3278: undefined reference to `GetImageAttribute'
/usr/local/lib/libGraphicsMagick++.a(Image.o): In function `Magick::Image::read(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)':
GraphicsMagick-1.3.18配置了以下调用:
CC=clang CXX=clang++ ./configure --with-jbig=yes --with-png=yes --with-jpeg=yes --enable-shared=yes CXXFLAGS="-O2 -g -stdlib=libc++ -isystem /usr/local/include/c++/v1/" LDFLAGS="-stdlib=libc++ -L/usr/local/lib/ -R/usr/local/lib/" LIBS="-lc++ -lc++abi"
然后建造和安装。
手动查找符号是未定义的:
nm /usr/local/lib/libGraphicsMagick++.a | grep GetImageAttribute
U GetImageAttribute
属性位于/usr/local/lib/libgraphicsmagick.a中。
我的ldd输出如下:
ldd /usr/local/lib/libGraphicsMagick++.so
linux-vdso.so.1 => (0x00007fff78592000)
libGraphicsMagick.so.3 => /usr/local/lib/libGraphicsMagick.so.3 (0x00007fd0b0309000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007fd0b00b0000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fd0afe87000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007fd0afc77000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fd0afa60000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd0af842000)
libc++abi.so.1 => /usr/local/lib/libc++abi.so.1 (0x00007fd0af5f5000)
libc++.so.1 => /usr/local/lib/libc++.so.1 (0x00007fd0af351000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd0af054000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd0aec95000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd0aea7f000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd0b09c3000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd0ae876000)
它从gcc工具链链接到一些c库。我也应该用叮当来建造它们吗?
任何建议都是非常欢迎的。
最佳答案
您是否还显式地链接到graphicsmagick++的依赖项?我认为,如果您将graphicsmagick++的所有依赖项枚举为生成的可执行文件的依赖项,那么这可能会解决您的问题,因此还可以链接到这些lib:
-lGraphicsMagick -ljpeg -lpng12 -lbz2 -lz
看看你的链接错误是少了还是没有。