Solaris SunStudio 12.4标准库链接问题

时间:2015-04-21 23:09:13

标签: c++ linker boost-asio solaris-10 solaris-studio

我正在尝试使用SunStudio 12.4在Solaris-10上编译boost-asio中的示例。使用GCC 4.9.2进行编译可以正常工作,但是我需要支持这两个编译器,所以只需切换即可。

CC -V输出: CC: Sun C++ 5.13 SunOS_sparc 2014/10/20

编译行:(对于每个cpp文件)

CC -m32 -std=c++11 -I./asio-1.10.6/include -I./boost/include/boost-1_58 -c *.cpp -o *.o

链接线:(请注意* .o实际上是以前生成的所有目标文件的列表)

CC -m32 -L./boost/sparc/sun/release32/lib *.o -o httpServer -lCrun -lCstd -lxnet -lboost_system

问题:

我为标准库填充了一堆未解析的符号(比如string,ios_base,locale等)。我发布了链接器错误here

我强烈怀疑这与使用-std=c++11有关。由于iterator_traits的编译问题,我添加了此选项。尽管iterator_traits不是C ++ 11特性,但由于某些原因,除非在c ++ 11模式下进行编译,否则SunStudio无法编译它。有关iterator_traits的错误:

Error: iterator_traits is not a member of std.

导致此编译失败的代码在boost boost/detail/iterator.hpp中。代码如下。

// (C) Copyright David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef ITERATOR_DWA122600_HPP_
#define ITERATOR_DWA122600_HPP_

// This header is obsolete and will be deprecated.

#include <iterator>

namespace boost
{

namespace detail
{

using std::iterator_traits;
using std::distance;

} // namespace detail

} // namespace boost

#endif // ITERATOR_DWA122600_HPP_

包含和使用此标头的其他内容会生成Error: iterator_traits is not a member of boost::detail之类的错误,然后会出现其他语法错误,因为现在它认为以下所有代码都无效。

我尝试过的其他事情:

  • 在-lCrun之前添加-lC(链接器找不到该库)
  • 添加-lc(类似问题)。
  • 检查SUNWspro / libs目录,发现libCrun.so和libCstd.so都存在。
  • 在-lCrun之前放置-lCstd

其他(不太相关)信息:

  • SPARC
  • 有问题的asio示例是httpServer(我相信它在示例中位于服务器目录下)

1 个答案:

答案 0 :(得分:2)

From The Docs:

  

在C ++ 11模式下,CC编译器使用g ++ ABI和版本的   随Oracle Solaris Studio提供的g ++运行时库。对于   此版本使用了g ++运行时库的4.8.2版。

     

ABI描述了生成的目标代码中的低级细节。   使用不同ABI的模块无法成功链接在一起   进入一个程序。 这意味着您必须全部使用C ++ 11模式   程序中的模块,或者都不是

所以说,你必须在链接器阶段指定“--std = c ++ 11”。你现在不这样做。

相关问题