3

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:

  • Adding -lC before -lCrun (the linker can't find that library)
  • Adding -lc (similar issue).
  • Checked in the SUNWspro/libs directory and found that libCrun.so and libCstd.so both exist.
  • Putting -lCstd before -lCrun

Other (Less Relevant) Information:

  • SPARC
  • the asio sample in question is the httpServer (I believe it's under the server directory in examples)
Maria
  • 547
  • 5
  • 20
  • I deleted my answer because I think I was wrong. Maybe I glossed over your linker errors before. –  Apr 22 '15 at 03:15
  • Try adding -lstdc++ to your compiler args. –  Apr 22 '15 at 03:18
  • @TechnikEmpire the linker can't find the sdtc++ library. Also in a previous comment you suggested adding -lm. I tried that as well, and although the linker can find it, it makes no difference. – Maria Apr 22 '15 at 16:47
  • http://docs.oracle.com/cd/E37069_01/html/E37071/gndfg.html - It's definitely an issue with simply failing to link to the standard library somehow. –  Apr 22 '15 at 23:09
  • If you just just your linked compiler errors as search terms you'll come across dozens of posts like this http://stackoverflow.com/questions/7038258/gcc-4-5-2-linker-gots-problem-while-using-exceptions-c all pointing to the source issue. According to do the docs in C++11 mode, it's simply using the standard library provided by g++ 4.8.2. Search your file system and "obviously where it should be" paths trying to find this to see if it's even on your system. –  Apr 22 '15 at 23:12
  • Instead of `-std=c++11`, did you try `-library=stdcxx4` (or `-library=stlport4`)? Those are the recommended modes for use with boost. Note that all those flags need to be exactly the same when compiling and linking (and drop `-lCrun` and `-lCstd`). – Marc Glisse Apr 22 '15 at 23:19
  • @MarcGlisse Yes I tried stlport4 and was able to compile, but upon running immediately seg faults. In the end, we've decided to go another route, but I think that I could have figured this out with more effort. Should I keep the question for other viewers, or delete it? – Maria Apr 23 '15 at 17:46
  • @maria I'm not sure what you should do, since you're abandoning the question. I'd suggest only for the sake of avoiding getting flagged for a post bad to just leave the question alone rather than deleting it. This site has a silly system where if you start deleting your own posts, it suspects you of being a creator of low quality stuff and will eventually ban. Did you try specifying std=... on both your compile and linker phase commands? –  Apr 24 '15 at 06:54
  • @TechnikEmpire We decided to abandon it before I got to it, unfortunately. If I ever do try this I'll let the community know. I do suspect that that would have solved the issue. – Maria Apr 27 '15 at 18:34

1 Answers1

2

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.

  • But iterator_traits isn't even a C++11 feature, is it? I thought it was C++03, so I'm really confused as to why it can't compile it without setting std to c++11. I will look into posting code tomorrow. – Maria Apr 22 '15 at 03:00
  • It's both. I need std=c++11 to compile, but when I compile with c++11 on I can't link. Interesting about the fact that the compiler only supports x86 architectures. – Maria Apr 22 '15 at 03:07
  • Ah! Okay, that's really good info. Thanks for all your effort. – Maria Apr 23 '15 at 17:47