2

I have a SSH account at my university's computer in which I can only compile with gcc 4.4.7, which doesn't compatible with my C++ 11 code (I don't have the rights to install/update software). In my computer I have Debian but the program that I compiled in Debian is not compatible with Solaris.

Can I compile my source code under Debian to make work it with Solaris somehow? Or is there any solution for my problem?

  • 2
    What Solaris release? On what architecture (SPARC or x86)? – jlliagre Feb 11 '17 at 19:09
3

You could install VirtualBox (or some other virtual machine software) on your Debian machine, and install Solaris in that. Oracle (the vendor) provides downloads.

If the university's computer is compatible (x86-based, similar version), it would be possible to compile locally and use the executables on the other machine.

  • Where can I get Solaris OS installer? – DBalazs Feb 11 '17 at 18:07
  • 2
    It sounds like the issue is with the compiler and code rather than with having access Solaris. A cross-compiler for compiling C++11 code for Solaris on Debian, or installing a C++11-capable compiler in a home directory and compile static binaries would be a better solution. – Kusalananda Feb 11 '17 at 18:09
  • 2
    Cross compilers to platforms such as Solaris are less common than you might suppose (generally cross compilers are available for a few of the interesting low-capability targets). It would be a good learning exercise, but a dedicated machine is best practice. – Thomas Dickey Feb 11 '17 at 18:53
  • Just to say I made installing and setting up a Solaris 11.3 VM in VirtualBox my weekend project, and there's at least GCC 5.4 available to be installed through the package manager. g++ 5.4 is supposed to handle C++11 (ref). – Kusalananda Feb 12 '17 at 18:20
2

What you're asking for, as Thomas Dickey posted, is a cross compiler.

They're not difficult to do, but they are very tedious to set up and keep set up properly, because there are a lot of dependencies on the target system that have to be accounted for in order to build a proper executable.

What are some of those dependencies? Just off the top of my head:

  1. First, your target system is likely a hosted environment so your cross compiler would need to provide executable start-up code/binaries to allow the target system to actually get to the point of calling your main() function.
  2. There are a lot of implementation-defined details on the target system, such as "How big is a long". Those can differ, so you need, for lack of a better word - the target implementation. In general, that means at least all the header files for your target system that are "part of the implementation". Determining which ones you need and which ones you don't is a tedious task at best. So just grab all of them, right? Well, that increases the number of dependencies you have to worry about.
  3. So now you can compile - but you can't link without the target systems libraries (this relates back to #1 above, but even more is needed). While in theory you can link with just the target systems static libraries and without the target systems dynamic libraries, without all the libraries you can't really be certain the binary produced by your cross-compiler won't fail with a "missing symbol" error when you try to run it on your target system.

So you need the header files, the libraries, and the startup binaries/code for your target system to create a cross-compiler - and once you get it set up, you have to maintain it - if the target system gets patched in a way that impacts your cross-compiler, you need to replicate those changes in your compiler. How do you determine that patch "123456" or RPM "abc" impacts your cross compiler?

And I probably missed a whole lot.

It should be pretty obvious why no one bothers with cross compilers where the target system is something that's easy to create an instance of like Linux/Solaris/Windows/BSD on x86 hardware, and even why when the target system is something harder (like Solaris on SPARC) almost everyone with a need to compile for that target just buys some low-end compatible hardware for compiling on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.