LinuxQuestions.org
Review your favorite Linux distribution.
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 06-13-2013, 08:54 PM   #16
derekpock
Member
 
Registered: Apr 2012
Location: USA
Distribution: Elementary OS Luna
Posts: 83

Original Poster
Rep: Reputation: 4

Sorry for misunderstandings. I'm looking for a solution to the problem. I am not trying to debate the question, just looking for an answer.

Simple programs people. No 16GB memory, just simple, non-gui based programs.

Last edited by derekpock; 06-13-2013 at 08:55 PM.
 
Old 06-13-2013, 08:56 PM   #17
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by derekpock View Post
Simple programs people. No 16GB memory, just simple, non-gui based programs.
Compile in 32-bit with static libs
Code:
g++ -m32 -static <everything else>
The problems of doing this can be debated for eternity, but first you should determine if there's even a problem to begin with. If not, then carry on.

Last edited by suicidaleggroll; 06-13-2013 at 08:58 PM.
 
Old 06-13-2013, 09:04 PM   #18
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by derekpock View Post
... just simple, non-gui based programs.
Then make sure you are using a standard-compliant C++ compiler and make sure in the programs you use only standard C++ library - its contents and behavior are mandated by the C++ standard and thus is computer-independent.
 
Old 06-13-2013, 09:06 PM   #19
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by Sergei Steshenko View Post
Then make sure you are using a standard-compliant C++ compiler and make sure in the programs you use only standard C++ library - its contents and behavior are mandated by the C++ standard and thus is computer-independent.
That ensures that the source code is computer-independent, but not that the compiled binary is computer-independent.
 
Old 06-13-2013, 09:09 PM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by suicidaleggroll View Post
That ensures that the source code is computer-independent, but not that the compiled binary is computer-independent.

Correct - but, as stated earlier. different operating systems have different libraries and different executable file formats.

Yes, static linking is the way, but, again, as stated earlier, it is not in practice always possible; also in practice sometimes part of the program remains dynamically linked.
 
Old 06-13-2013, 09:16 PM   #21
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by Sergei Steshenko View Post
Yes, static linking is the way, but, again, as stated earlier, it is not in practice always possible; also in practice sometimes part of the program remains dynamically linked.
Yes, sometimes a statically linked executable still won't run on a user's distro, and sometimes a program is so convoluted that compiling it with static libs isn't possible, but shouldn't we wait to see if that's even a problem for the OP before dismissing it outright? He's not looking for a way to compile any program so that it can run on any OS, he's looking for a way to compile one specific program so that it can run on his computer and his friend's computer (also running Linux). That's it. It doesn't need to be any more complicated than that. If it's a relatively simple program (which he has stated it is) and both machines are running relatively modern OSs (released in the last 5 years), then I see no reason why compiling with static libs and in 32-bit (if necessary) won't solve his problem.

Last edited by suicidaleggroll; 06-13-2013 at 09:17 PM.
 
Old 06-13-2013, 09:41 PM   #22
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by suicidaleggroll View Post
... He's not looking for a way to compile any program so that it can run on any OS, he's looking for a way to compile one specific program so that it can run on his computer and his friend's computer (also running Linux). That's it. ...
Then both the OP and the friend should install g++ and compile from source. That's it.
 
Old 06-13-2013, 09:50 PM   #23
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by Sergei Steshenko View Post
Then both the OP and the friend should install g++ and compile from source. That's it.
lol, an engineer's reply

Being an engineer myself I appreciate the irony, and I could see myself giving the exact same answer to a similar question in another situation, but it sounds like the OP is looking for a single executable he can give to his friend to run.

I have several pieces of software under my control that are used to interface with proprietary hardware, that need to be distributed to customers running any number of Linux setups. Obviously offering the source with a makefile they can use to build it for their system would be ideal, but it's not an option since the source code is controlled. Building it with static libs in 32-bit and distributing the resulting binary covers 99% of the use-cases, and I deal with the exceptions on an individual basis (of which there have been exactly zero).
 
Old 06-13-2013, 09:57 PM   #24
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by suicidaleggroll View Post
lol, an engineer's reply

... it's not an option since the source code is controlled. ...
Deviating from the OP's question - you can distribute assembly produced by gcc/g++. Binary can be disassembled anyway, so you retain the same level of control, but let your customers link locally.
 
Old 06-13-2013, 10:44 PM   #25
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,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
perhaps then the best option would be to cross compile the source for your target, this can be done as well.
 
Old 06-13-2013, 11:04 PM   #26
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Oh, by the way, there is now LLVM-based technology translating C/C++ into JavaScript.
 
Old 06-14-2013, 02:10 PM   #27
derekpock
Member
 
Registered: Apr 2012
Location: USA
Distribution: Elementary OS Luna
Posts: 83

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by suicidaleggroll View Post
Yes, sometimes a statically linked executable still won't run on a user's distro, and sometimes a program is so convoluted that compiling it with static libs isn't possible, but shouldn't we wait to see if that's even a problem for the OP before dismissing it outright? He's not looking for a way to compile any program so that it can run on any OS, he's looking for a way to compile one specific program so that it can run on his computer and his friend's computer (also running Linux). That's it. It doesn't need to be any more complicated than that. If it's a relatively simple program (which he has stated it is) and both machines are running relatively modern OSs (released in the last 5 years), then I see no reason why compiling with static libs and in 32-bit (if necessary) won't solve his problem.
THANK YOU! Finally someone understands! Honestly, going to far with a question is the problem here. I did not want him to have to run compilations, mainly because he now has my source-code. The static options worked for my situation, it may not work for other programs though, this works for now, yes, IT DOES WORK. That's all, marking as solved.
 
  


Reply

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



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

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

All times are GMT -5. The time now is 03:38 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