LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 06-10-2013, 10:33 PM   #1
derekpock
Member
 
Registered: Apr 2012
Location: USA
Distribution: Elementary OS Luna
Posts: 66

Rep: Reputation: 4
How to make C++ projects computer independent. Detailed instructions needed.


Title says it all. I have "le project" that I want to compile on my computer. Send it to a friend on a different computer but same OS (linux) and it work. Most of the time it will say "Cannot Run this program!". It would also be good to know if there was any way to make it OS independent, but Windows will most-likely complain. So just this for now. How to package a system independent C++ program.
 
Old 06-10-2013, 10:54 PM   #2
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,227
Blog Entries: 23

Rep: Reputation: 279Reputation: 279Reputation: 279
C++ is not intended for that...Java is. Dotnet should be, but...I dont trust it...at all.
What you need is a runtimer that is made for the target OS/platform and program against that...
The thing lies in the compile...at compile time, the links get made for the OS/platform in use at compile time.
Just what program is it, by the way?

Thor
 
Old 06-10-2013, 11:29 PM   #3
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
If you compile it with static libraries there's a good chance your Linux friend will be able to run it (possibly 32-bit with static libs if you're running a 64-bit OS and he's not). Getting it to run on another OS is another matter entirely though, and needs a cross-platform language more like Java (as mentioned above).
 
Old 06-11-2013, 02:41 AM   #4
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
depends on the project itself. Creating GUIs will make it really hard, probably you will need wxWindows or similar.
You cannot have system independent packages, because all the installable packages are designed for a specific os. Linux and MS Windows are really different.
You can also try wine on linux
 
Old 06-11-2013, 04:24 PM   #5
derekpock
Member
 
Registered: Apr 2012
Location: USA
Distribution: Elementary OS Luna
Posts: 66

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by Thor_2.0 View Post
C++ is not intended for that...Java is. Dotnet should be, but...I dont trust it...at all.
What you need is a runtimer that is made for the target OS/platform and program against that...
The thing lies in the compile...at compile time, the links get made for the OS/platform in use at compile time.
Just what program is it, by the way?
Mmm...well anything is possible. I understand Java is better at this than C++, but C++ does things that Java won't be able to do. It would be good to know how to do this later on when the program gets more complicated. No GUI is yet implemented. Do you have an example of a runtimer that I could use with the default packages? Its a multi-utility program, including a study tool, advanced calculators, file editing, and so on.

Quote:
If you compile it with static libraries there's a good chance your Linux friend will be able to run it (possibly 32-bit with static libs if you're running a 64-bit OS and he's not). Getting it to run on another OS is another matter entirely though, and needs a cross-platform language more like Java (as mentioned above).
How would I use static libraries. Include the files with the program that it compiles from? Running on another OS is later to be implemented.

Quote:
depends on the project itself. Creating GUIs will make it really hard, probably you will need wxWindows or similar.
You cannot have system independent packages, because all the installable packages are designed for a specific os. Linux and MS Windows are really different.
You can also try wine on linux
I am eventually going to use GTK for GUI, not wxWindows. Again, the OS is later to be decided.
 
Old 06-11-2013, 04:59 PM   #6
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Originally Posted by derekpock View Post
How would I use static libraries. Include the files with the program that it compiles from? Running on another OS is later to be implemented.
Set "-static" in the compiler flags
 
Old 06-11-2013, 05:25 PM   #7
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,111

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
another issue not mentioned is that between windows, mac, linux, bsd etc.. they all use different executable formats

linux,bsd and a lot of *NIX operating systems uses the ELF binary format,
mac uses the Mach-O format
windows uses the PE (portbale exececutable) format

so right there, you would still have to compile the program for the target system, not to mention each system has a different API, which would require porting the program.
 
Old 06-11-2013, 06:37 PM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
You will get the best portability with using something like Java or .NET/Mono.
If you want to stick with C++ you should try to use an application framework that is available on all platforms you want to provide your software for, for example Qt. You still will have to compile for any platform you want to use, but the work need to port to a different platform should be as minimal as possible if you want to use C++.
 
Old 06-12-2013, 09:43 AM   #9
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The best ways to have an application that runs on multiple operating systems and distros:
  • Write as much of it as you can in a standardized language, isolate code for OS-specific things (like GUIs), and compile/link a version for each OS or distro. Or, provide the source code and hope someone is enterprising enough to compile it for Windows and provide it for download.
  • Write the application using a framework that has already done that, e.g. Python, Java, etc.
Static linking isn't a scalable solution because it will give you massive binaries. Also, although static linking is feasible in theory, in practice it's a huge headache and it almost never works like you want it to. That's because static "libraries" are merely archives of .o files, so you have to specify them in the right order and you have to specify every dependency recursively. Dynamic linking doesn't have that problem because a library you link to references its dependencies. Lastly, some functionality simply isn't available for static linking.

Some people just write their code for Linux and require that the user run it with cygwin. That's acceptable for some things, but it's not a very graceful solution in most cases. It's really meant for software that from the beginning wasn't intended to run on Windows.

As a final point, remember how much of a pain it is to even have the capability of compiling C++ code on/for Windows and OS X, regardless of if your code can compile for those OSes.

Kevin Barry
 
Old 06-12-2013, 02:26 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by derekpock View Post
Title says it all. I have "le project" that I want to compile on my computer. Send it to a friend on a different computer but same OS (linux) and it work. Most of the time it will say "Cannot Run this program!". It would also be good to know if there was any way to make it OS independent, but Windows will most-likely complain. So just this for now. How to package a system independent C++ program.
"Title says it all" - no, it doesn't.

Did you mean OS-independent ? CPU architecture independent ?
 
Old 06-12-2013, 07:54 PM   #11
derekpock
Member
 
Registered: Apr 2012
Location: USA
Distribution: Elementary OS Luna
Posts: 66

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by Sergei Steshenko View Post
"Title says it all" - no, it doesn't.

Did you mean OS-independent ? CPU architecture independent ?
Mhm...that is why I put text in my thread along with the title, for people like you.

Quote:
It would also be good to know if there was any way to make it OS independent, but Windows will most-likely complain.
That would be nice, but OS independent is NOT what I am looking for.

CPU architecture may be what I am looking for. What I am looking for specifically is a way to make C++ projects that are built on linux OS to run other linux OS's, different computers, different systems, different, but the same general linux OS. I don't understand what is confusing to you here.


Quote:
Set "-static" in the compiler flags
Thank you suicidaleggroll. This is good information, I will try this.


Quote:
another issue not mentioned is that between windows, mac, linux, bsd etc.. they all use different executable formats

linux,bsd and a lot of *NIX operating systems uses the ELF binary format,
mac uses the Mach-O format
windows uses the PE (portbale exececutable) format

so right there, you would still have to compile the program for the target system, not to mention each system has a different API, which would require porting the program.
NOT looking for OS independence.


Thanks for everyone that has replied. Again, I am not looking for OS independence, NOT Windows to Mac to Linux and back, No. Just Linux to linux. One compilation that will work for most linux computers. I, again, I UNDERSTAND that Java and other languages have already done this, that is why I am trying to make it work for C++. Its a headache and painful, yes, but someone should figure out how to do it, thats what I am trying to do.
 
Old 06-12-2013, 08:02 PM   #12
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Originally Posted by ta0kira View Post
Static linking isn't a scalable solution because it will give you massive binaries. Also, although static linking is feasible in theory, in practice it's a huge headache and it almost never works like you want it to. That's because static "libraries" are merely archives of .o files, so you have to specify them in the right order and you have to specify every dependency recursively. Dynamic linking doesn't have that problem because a library you link to references its dependencies. Lastly, some functionality simply isn't available for static linking.
You make it sound MUCH worse than it is in reality. In fact your post makes it sound completely impractical for almost any application, when I have found quite the opposite to be true. In fact I have yet to run into a problem statically linking any program I've written so it can run on multiple Linux machines, and I have never run into the problem you describe here:

you have to specify them in the right order and you have to specify every dependency recursively

While what you say may be true for certain massive applications with hundreds of dependencies, or applications that are linking in other static libraries that you've compiled, that are based on other static libraries that you've compiled...I think that's more the exception than the rule.

Last edited by suicidaleggroll; 06-12-2013 at 08:04 PM.
 
Old 06-12-2013, 09:00 PM   #13
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
You make it sound MUCH worse than it is in reality. In fact your post makes it sound completely impractical for almost any application, when I have found quite the opposite to be true. In fact I have yet to run into a problem statically linking any program I've written so it can run on multiple Linux machines, and I have never run into the problem you describe here:

you have to specify them in the right order and you have to specify every dependency recursively

While what you say may be true for certain massive applications with hundreds of dependencies, or applications that are linking in other static libraries that you've compiled, that are based on other static libraries that you've compiled...I think that's more the exception than the rule.
Given that we've have had the exact opposite experiences here, I'd say it's debatable at best. I'm sure we just write completely different types of software.
Quote:
Originally Posted by derekpock View Post
That would be nice, but OS independent is NOT what I am looking for.

CPU architecture may be what I am looking for. What I am looking for specifically is a way to make C++ projects that are built on linux OS to run other linux OS's, different computers, different systems, different, but the same general linux OS. I don't understand what is confusing to you here.
That's actually the opposite of what it sounded like in your other two posts, so confusion is understandable.

Kevin Barry
 
Old 06-12-2013, 09:23 PM   #14
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Originally Posted by ta0kira View Post
Given that we've have had the exact opposite experiences here, I'd say it's debatable at best. I'm sure we just write completely different types of software.
That sounds likely. I mostly write analysis and data processing software that's all command line driven and uses a limited set of libraries (lapack, gpstk, etc). I'm sure GUI software is quite a bit different.
 
Old 06-12-2013, 10:12 PM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by derekpock View Post
Mhm...that is why I put text in my thread along with the title, for people like you.
...
You apparently misunderstand English.

I have a laptop and a desktop computer. One is Intel-based, the other - AMD-based. Choosing 'i586' architecture during compilation makes my program run on both computers. So, on the set of the two computers the program is computer-independent.


OTOH, your program might need, say, 16GB of virtual memory. And two computers with identical motherboards and identical CPUs may be different from the point of the program - because in one of them there will be not enough virtual (let alone physical) memory.
 
  


Reply

Tags
c++, compile, package, program, programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple, detailed instructions to wipe free space please. PeterJD Linux - Newbie 19 05-05-2010 12:08 PM
Need Detailed Instructions On How To Customise Fbpanel Mark7 Linux - Desktop 0 02-06-2008 02:49 PM
distro-independent detailed description of linux installation process kabarbaik Linux - General 1 02-20-2007 12:16 PM
detailed instructions for getting HPg85xi to work through USB lazarys Linux - Newbie 5 05-05-2006 04:03 PM
Detailed instructions on loading win xp on a redhat 9 box?? ashwin_cse Red Hat 1 12-02-2004 03:42 AM


All times are GMT -5. The time now is 03:39 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration