Programming compatiblity between Solaris x86 and Sun Sparc Solaris

Dear all,

I would like to compile a c program under Solaris x86 using gcc.

Then can this executable file be run under Sun Sparc Solaris?

Benson
benson031397Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

s_franklinCommented:
For future reference, you'll want to bookmark the Solaris X86 FAQ except from the reverse direction: http://sun.pmbc.com/faq/

The compiled applications reflect the instruction set of the target processor. Consequently, to get an x86 app to run on a sparc you would need an emulator. I can't say that an emulator doesn't exist but I sure haven't seen one to date and I wouldn't trust it for any kind of robust operation.

Also, as the FAQ points out, if you want to develop cross-platform (x86 vs sparc) code, you have to watch out for platform specific assumptions and calls. The man pages will sometimes address these differences and you will also want to be careful about your assumptions and operations on datatypes.
0
s_franklinCommented:
As an addendum, you can do cross-compiling on your x86 box to deploy to the target. This is different than what I originally addressed above, which was to compile a solaris x86 binary which you distribute to the sparc solaris box.

GCC supports cross-compiling, i.e. compiling on platform A an executable that is actually targetted for platform B. You will have to read about this at: http://www.objsw.com/CrossGCC/. The userbase for this application is small so you will find that if you get in trouble that you will have less support on the Internet to help you out. Provided you have access to the includes and libraries for your target architecture, it is theoretically possible to build a cross-compiler. Cross-compilers are generally used for embedded systems work, but there may be a Solaris-base one out there for you if you look hard enough (I've never seen one).

Good luck.

Steve

0
benson031397Author Commented:
Can yuo give me example how I can compile a program so that it can be run on Sun Sparc System V OS?

I really don't understand how to make a application for another machine after studying the document you mentioned above.


Thanks!

Benson
0
s_franklinCommented:
I don't think that's a good reason to reject the answer. The answer to your question is "No". You can't just use gcc, compile a program on your x86 Solaris box and drop it on your Sparc Solaris box.

However, I did provide you with a resource that with some effort will help you to set up cross-compiling with GCC, i.e. compiling on one architecture for another. It is not easy, it does not always work well, and it can sometimes take quite a bit of effort. If you don't want to tackle the problem with a cross-compiler as described in that document (which I think is what you're saying) then the answer is "no, you cannot compile on x86 Solaris with GCC for Sparc Solaris". If you are willing to invest in setting up the cross-compiler environment above, you will be able to achieve it. I don't think you will be able to find a better document covering the steps on the Net.

Setting the environment will take time - this isn't a one- or two-step solution. I encourage you to use the following mailing-list (cross-compiling with GCC - a.k.a crossgcc):

http://sourceware.cygnus.com/ml/crossgcc/

You can submit to it or search for discussions on Solaris cross-compilation. You will find some articles discussing x86 and Sparc, but in the end you're going to have to understand how to do this with some time and effort.

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cadabraCommented:
<interested>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.