LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2012, 02:12 PM   #1
cOde13
LQ Newbie
 
Registered: Sep 2012
Location: /home/
Distribution: CentOS, RHEL, Ubuntu, Fedora, WindowsXP
Posts: 13

Rep: Reputation: 0
Question C++ -- How to make cross-platform programs


Hello,

What option should I use while compile to make cross-platform (this is the name, I guess) program files for using in both Linux & Windows platforms? How complex is it?
For example, I use c++ Hello.cpp -o Hello to compile the Hello.cpp by gcc-c++ to run in Linux pc. How can I make it for both 'Linux & Windows'


Thanks.
 
Old 09-26-2012, 02:34 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
You can't. You need to build it separately for each platform you want to support.

If cross-platform binary compatibility is a requirement, then you need something like Java.

Last edited by dugan; 09-26-2012 at 02:40 PM.
 
Old 09-26-2012, 03:43 PM   #3
cOde13
LQ Newbie
 
Registered: Sep 2012
Location: /home/
Distribution: CentOS, RHEL, Ubuntu, Fedora, WindowsXP
Posts: 13

Original Poster
Rep: Reputation: 0
Understood. Thanks.

I do Java programming too. Shall I make a new thread for this?
 
Old 09-26-2012, 04:09 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Actually, C++ definitely can be used to build cross-platform software, but most of the time you see this being done at a fairly low level, commensurate with say "the Linux kernel." The pragmatic problem that always comes up is the User Interface. There is no standardization on this.

Therefore, what you normally see being done is something like Java, which has "abstracted completely away" all of these environment-specific details and inserted a user-interface (GUI widgets, etc.) layer of its own devising ... which the language does undertake to support across a wide range of host platforms and environments. The host-specific language system itself works on bytecodes, not native machine instructions, and "compiled" programs are transportable among environments without recompilation. (Basically, the slight "overhead" is an acceptable and justifiable price to pay.)

All things considered, it's a strategy that works well in practice. (Java not of course being the only language-system that does it, nor that takes this general approach.)

Footnote: Some language-systems in this space are quite machine-specific. Microsoft's "C#" C-sharp compiler for dot-Net can be very expressive at a "bits and bytes" level if you want to be, and yet it all runs under the so-called "CLR" runtime environment.

Last edited by sundialsvcs; 09-26-2012 at 04:11 PM.
 
Old 09-26-2012, 04:22 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by sundialsvcs View Post
The pragmatic problem that always comes up is the User Interface. There is no standardization on this.
I'm not sure if I understand what you're saying.

There are many good cross-platform user-interface libraries for C++. However, "cross-platform" in C++ means that you can compile the source on, or for, a selection of target platforms (one platform per compile). It doesn't mean that you can compile it once, and then run the same binaries on multiple platforms.

Last edited by dugan; 09-26-2012 at 04:47 PM.
 
Old 09-27-2012, 09:54 AM   #6
cOde13
LQ Newbie
 
Registered: Sep 2012
Location: /home/
Distribution: CentOS, RHEL, Ubuntu, Fedora, WindowsXP
Posts: 13

Original Poster
Rep: Reputation: 0
Low level or Kernel level programming. Obviously I'm not that expert yet. So, I guess its not for me yet.

Thanks all for explain in details.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: WebOS' Enyo 2.0 dev platform goes cross-platform, adopts Apache license LXer Syndicated Linux News 0 01-27-2012 06:30 AM
How to Run "make xconfig" for Cross Platform? Peatmoss Linux - General 3 06-15-2010 07:01 PM
Whats the best cross-platform GUI kit for developing opengl programs? chutsu Programming 4 04-18-2008 03:27 PM
cross-platform application to make window apps & contribute to Open Source Projects? bgryderclock Linux - Software 4 03-23-2008 02:08 PM
cross platform c++ nyomon Programming 6 07-03-2005 03:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration