1

我正在尝试在 Ubuntu 12.04 x64 上编译一个应用程序。它是在 osx 上使用 clang 3.2 构建的,使用新的 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 相关的单元测试(仅标头和共享对象库)都运行良好。在我们开始链接到 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 库。我也应该用clang构建它们吗?任何建议都非常受欢迎。

4

1 回答 1

0

您是否还明确链接到 GraphicsMagick++ 的依赖项?我认为如果您将 GraphicsMagick++ 的所有依赖项枚举为生成的可执行文件的依赖项,这可能会解决您的问题,因此也可以链接这些库:

-lGraphicsMagick -ljpeg -lpng12 -lbz2 -lz

看看你是否有更少的链接错误或没有。

于 2013-07-10T15:44:07.640 回答