c++linkerboost-asiosolaris-10solaris-studio

Solaris SunStudio 12.4 Standard Library Linking Issue


I'm trying to compile a sample from boost-asio on Solaris-10 using SunStudio 12.4. Compiling with GCC 4.9.2 works, but down the line I will be required to support both compilers, so just switching is not an option.

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

Compilation Line: (for each cpp file)

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

Linker Line: (note that *.o is actually a list of all the object files previously generated)

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

The Problem:

I get a bunch of unresolved symbols for standard library stuff (like string, ios_base, locale, etc.). I posted the linker errors here.

I strongly suspect that this is related to the use of -std=c++11. I included this option because of a compilation issue with iterator_traits. Even though iterator_traits is not a C++11 feature, for some reason SunStudio can't compile it unless it is compiling in c++11 mode. The error regarding iterator_traits:

Error: iterator_traits is not a member of std.

The code causing this compile failure is in boost boost/detail/iterator.hpp. Code follows.

// (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_

Other things which include and use this header generate errors like Error: iterator_traits is not a member of boost::detail, and then other syntax errors because now it thinks all the following code is invalid.

Other Things I've Tried:

Other (Less Relevant) Information:


Solution

  • From The Docs:

    In C++ 11 mode, the CC compiler uses the g++ ABI and a version of the g++ runtime library that is supplied with Oracle Solaris Studio. For this release, version 4.8.2 of the g++ runtime library is used.

    An ABI describes the low-level details in the generated object code. Modules that use different ABIs cannot successfully be linked together into a program. This means that you must use C++11 mode on all modules in your program, or none of them.

    So with that said, you must specify "--std=c++11" to the linker phase too. You're not doing this presently.