【问题标题】:Solaris ld: fatal: unrecognized option '--'Solaris ld:致命:无法识别的选项“--”
【发布时间】:2015-10-09 22:17:31
【问题描述】:

我正在尝试在 Solaris 机器上编译 Apache Qpid,但在链接过程中失败:

Scanning dependencies of target qpidtypes
[  0%] Building CXX object src/CMakeFiles/qpidtypes.dir/qpid/types/Exception.cpp.o
[  0%] Building CXX object src/CMakeFiles/qpidtypes.dir/qpid/types/Uuid.cpp.o
[  0%] Building CXX object src/CMakeFiles/qpidtypes.dir/qpid/types/Variant.cpp.o
Linking CXX shared library libqpidtypes.so
ld: fatal: unrecognized option '--'
ld: fatal: use the -z help option for usage information
*** Error code 1
The following command caused the error:
cd /export/home/user/qpid-cpp-0.34/build/src && /opt/csw/bin/cmake -E cmake_link_script CMakeFiles/qpidtypes.dir/link.txt --verbose=
make: Fatal error: Command failed for target `src/libqpidtypes.so.1.0.0'
Current working directory /export/home/user/qpid-cpp-0.34/build
*** Error code 1

-E 选项调用的命令文件是 CMakeFiles/qpidtypes.dir/link.txt,它包含:

/usr/bin/gcc  -fPIC -fno-visibility-inlines-hidden -fvisibility=hidden -Wl,--version-script=/export/home/user/qpid-cpp-0.34/src/qpid.linkmap  -m64  -pthread -shared  -Wl,-hlibqpidtypes.so.1 -o libqpidtypes.so.1.0.0 CMakeFiles/qpidtypes.dir/qpid/types/Exception.cpp.o CMakeFiles/qpidtypes.dir/qpid/types/Uuid.cpp.o CMakeFiles/qpidtypes.dir/qpid/types/Variant.cpp.o  -L/usr/local/lib  -L/usr/lib/mps -luuid -Wl,-R/usr/local/lib:/usr/lib/mps: 

问题似乎是 -Wl,--version-script=/export/home/user/qpid-cpp-0.34/src/qpid.linkmap

This question 使用带有两个破折号的选项,但我不知道我该怎么做。

问题:如何让 ld 接受 --version-script 信息?


关于 ld 版本的一些信息:

$ gcc -print-prog-name=ld
/usr/ccs/bin/ld

$ /usr/ccs/bin/ld -V
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.1514

gcc 版本的一些信息:

Target: sparc-sun-solaris2.10
Configured with: /home/dam/mgar/pkg/gcc4/trunk/work/solaris10-sparc/build-isa-sparcv8plus/gcc-4.9.2/configure --prefix=/opt/csw --exec_prefix=/opt/csw --bindir=/opt/csw/bin --sbindir=/opt/csw/sbin --libexecdir=/opt/csw/libexec --datadir=/opt/csw/share --sysconfdir=/etc/opt/csw --sharedstatedir=/opt/csw/share --localstatedir=/var/opt/csw --libdir=/opt/csw/lib --infodir=/opt/csw/share/info --includedir=/opt/csw/include --mandir=/opt/csw/share/man --enable-cloog-backend=isl --enable-java-awt=xlib --enable-languages=ada,c,c++,fortran,go,java,objc --enable-libada --enable-libssp --enable-nls --enable-objc-gc --enable-threads=posix --program-suffix=-4.9 --with-cloog=/opt/csw --with-gmp=/opt/csw --with-included-gettext --with-ld=/usr/ccs/bin/ld --without-gnu-ld --with-libiconv-prefix=/opt/csw --with-mpfr=/opt/csw --with-ppl=/opt/csw --with-system-zlib=/opt/csw --with-as=/usr/ccs/bin/as --without-gnu-as
Thread model: posix
gcc version 4.9.2 (GCC)

【问题讨论】:

  • Solaris 链接器不知道--version-script-information 标志。尝试改用-M

标签: gcc linker cmake solaris ld


【解决方案1】:

在 solaris 10 上构建 openldap 版本 2.4.39 时出现相同的错误消息。

确实,solaris 提供的链接器不支持双破折号“--”,如上一个答案中所述。但是您必须找到与两个破折号一起使用而错误消息中未明确提及的选项参数。

要找到相应的选项,您必须查看控制台中显示的链接命令,并查看配置文件或定义它的项目配置文件。

特别是对于 openldap,我使用了库中提供的配置文件。但问题是链接器选项 rpath 与两个破折号一起使用来设置以下变量,如下所示:

  • hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir'

该问题已在一些 aclocal.m4 文件(在不同文件夹中)和 libtool 脚本中通过删除多余的破折号得到修复。

该库也已在 linux 上构建,无需修改任何其他文件。

【讨论】:

    【解决方案2】:

    问题在于 Solaris 链接器无法识别许多以两个破折号开头的选项。

    Solaris ld: fatal: unrecognized option '--'
    

    可以用

    解决
    ld -z help
    

    并找到正确的替代品。


    在我的特殊情况下,我发现了一个solution in the qpid mailing list,它根本不使用--version-script:

    在 SunOs(至少在我的机器上)这不起作用:

    /usr/bin/gcc -fPIC -fno-visibility-inlines-hidden -fvisibility=hidden

    -Wl,--version-script=/export/home/noname/install/qpid-0.28_tmptest/cpp/src/qpid.linkmap

    -shared -Wl,-hlibqpidtypes.so.1 -o libqpidtypes.so.1.0.0 CMakeFiles/qpidtypes.dir/qpid/types/Exception.cpp.o CMakeFiles/qpidtypes.dir/qpid/types/Uuid.cpp.o CMakeFiles/qpidtypes.dir/qpid/types/Variant.cpp.o -L/usr/local/lib -L/usr/lib/mps -luuid -Wl,-R/usr/local/lib:/usr/lib/mps

    问题是:
    "-Wl,--version-script=/export/home/noname/install/qpid-0.28_tmptest/cpp/src/qpid.linkmap"

    所以需要在cpp/src/CMakeLists.txt中插入以下内容:

    184 if (GCC_VERSION VERSION_EQUAL 4.1.2) 185 消息 (状态“无法限制 gcc 上的库符号导出 4.1.2") 186 设置 (HIDE_SYMBOL_FLAGS "-fno-visibility-inlines-hidden") 187 其他 (GCC_VERSION VERSION_EQUAL 4.1.2) 188 集 (HIDE_SYMBOL_FLAGS "-fno-visibility-inlines-hidden -fvisibility=hidden") 189 设置 (QPID_LINKMAP ${CMAKE_CURRENT_SOURCE_DIR}/qpid.linkmap) 190 191 # --------------------- Solaris 192 需要插入以下三行 if (NOT CMAKE_SYSTEM_NAME STREQUAL SunOS) 193 设置(LINK_VERSION_SCRIPT_FLAG "-Wl,--version-script=${QPID_LINKMAP}") 194 endif(不是 CMAKE_SYSTEM_NAME STREQUAL SunOS)195 196
    endif (GCC_VERSION VERSION_EQUAL 4.1.2)

    【讨论】:

    • 不使用它有一些缺点(当然),但是我发现尽管 GNU 文档声明版本脚本的格式是相同的,但实际上并非如此。显然有一些差异很容易引入不兼容性,例如GNU 变体似乎支持/**/ cmets,但 Solaris 不支持。
    猜你喜欢
    • 1970-01-01
    • 2021-04-04
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 2021-01-28
    相关资源
    最近更新 更多