LinuxQuestions.org
Help answer threads with 0 replies.
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-24-2015, 06:04 PM   #1
Joesphin
LQ Newbie
 
Registered: Apr 2015
Posts: 11

Rep: Reputation: Disabled
One Executable for 32bit and 64bit


Hello,

I compiled an executable on 64bit Ubuntu and served users. It was working fine on 64bit systems.

Yesterday, I got complaints from 32bit Linux users becuase the file was 64bit.

I tried to compile 32bit on my 64bit Ubuntu. Installed required 32bit libraries and compiled with gcc. It worked fine on 64bit Ubuntu.

But then I ported the executable to CentOS 64bit and when I run that 32bit application, I get:

Code:
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
Probably it is because missing 32bit libraries on CentOS 64bit. It is OK to install on CentOS 64bit but I do not want to force users to install 32bit libraries.

Is it possible to have single file that can run on 32bit and 64bit? And is it possible to pack 32bit libraries into executable?

Cheers
 
Old 06-24-2015, 06:10 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,220

Rep: Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319
FatELF, maybe?

The way I've usually seen this dealt with is by including the 32-bit and 64-bit executables in the same tarball, and then having the launcher be a shell script that executes either the 32-bit or 64-bit executable depending on the system architecture.
 
Old 06-24-2015, 07:02 PM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Could it be built as a astatic app? That would remove the need for external libs, corse you would still need both a 32 and 64 bit build
 
Old 06-24-2015, 07:16 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,220

Rep: Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319
Quote:
Originally Posted by Keith Hedger View Post
Could it be built as a astatic app? That would remove the need for external libs, corse you would still need both a 32 and 64 bit build
Building it with "rpath=$ORIGIN" is another way to achieve that.
 
Old 06-24-2015, 07:18 PM   #5
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
Building it in 32-bit with static libs will let it run on nearly any system out there. If you need 64-bit support (large memory, large file access), then just build both 32 and 64-bit versions and have a shell script decide which one to use at runtime.
 
Old 06-24-2015, 11:12 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Simply: no.
There are 32-bit systems, that don't run 64-bit executables; and there are 64-bit systems that don't run 32-bit executables.
The best idea is providing source code and letting the user to compile it.
 
Old 06-25-2015, 07:56 PM   #7
Joesphin
LQ Newbie
 
Registered: Apr 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks guys,

According to your help, I think I will create both 32bit and 64bit versions and let them users to chose which to download.

Chers
 
Old 06-26-2015, 02:01 PM   #8
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
Quote:
Originally Posted by Joesphin View Post
But then I ported the executable to CentOS 64bit and when I run that 32bit application, I get:

Code:
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
Probably it is because missing 32bit libraries on CentOS 64bit. It is OK to install on CentOS 64bit but I do not want to force users to install 32bit libraries.

Is it possible to have single file that can run on 32bit and 64bit? And is it possible to pack 32bit libraries into executable?

Cheers
it says that it can not find /lib/ld-linux.so.2
that's the linker/loader, that loads libraries

best would be to compile it statically

other option would be to ship it with all the libraries it needs (and that that libraries need)
then start it with LD_LIBRARY_PATH or LD_PRELOAD
that would also make it portable as you could choose the version to run from a script
i haven't done this and i think you would have to mess around for it to use the linker you supplied, but im sure it can be done
 
Old 06-26-2015, 02:03 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938
I agree: compile it both ways, and provide two download options.

On your page, give a couple lines helpful hints: "Don't know what kind of system you've got? Here's how to find out..." Etcetera.

Given that they only need one, let them just have to download one. (Or both, if they're feeling grand . . .)
 
Old 06-26-2015, 04:15 PM   #10
Joesphin
LQ Newbie
 
Registered: Apr 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks guys again.

Is it sure all 32bit Linux distros have /lib/ld-linux.so.2? I do not have 32bit Linux to try and I compiled 32bit executable on 64bit linux.

Cheers
 
Old 06-26-2015, 04:53 PM   #11
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
I personally never supply binararys as its way too much hassle what with different distros running different lib versions I just supply source code and build instructions and what dependencies are needed etc, you may be better off doing it that way, if not you could always compile the 32bit version in a vm that way you can test it on various distros in vmware, I do this with my source code as I dont run ubuntu but ubuntu breaks loads of stuff so its worth running it in that in vm just to lessen the hassle
 
Old 06-28-2015, 02:26 PM   #12
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 263

Rep: Reputation: Disabled
Source code may not be a simple cure.
I ran into the same problem with pure C. Depending on data, my arrays could get big enough to cross page boundaries when run on a 32 bit machine. That was not a problem with a 64 bit machine. I solved that for the 32 bit machine by using pointers in linked lists instead of arrays.

Quote:
Originally Posted by Keith Hedger View Post
I personally never supply binararys as its way too much hassle what with different distros running different lib versions I just supply source code and build instructions and what dependencies are needed etc, you may be better off doing it that way, if not you could always compile the 32bit version in a vm that way you can test it on various distros in vmware, I do this with my source code as I dont run ubuntu but ubuntu breaks loads of stuff so its worth running it in that in vm just to lessen the hassle
 
Old 06-28-2015, 05:02 PM   #13
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by piobair View Post
Source code may not be a simple cure.
I ran into the same problem with pure C. Depending on data, my arrays could get big enough to cross page boundaries when run on a 32 bit machine. That was not a problem with a 64 bit machine. I solved that for the 32 bit machine by using pointers in linked lists instead of arrays.
I think this a completly different problem regarding 32/64 bits.
 
  


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
Porting 32bit application to 64bit on 64bit RedHat 5.4 pvpnguyen Programming 4 07-23-2010 06:52 AM
In a 64bit PC may make 4 partitions vista 32bit, vista 64bit, and ... lse123 Linux - Newbie 3 03-14-2009 09:09 AM
32bit(i386) or 64bit(amd64) on an amd 64bit cpu (amd 6000+)? d-_-b Debian 7 10-28-2007 07:48 PM
can 64bit processor run both 64bit and 32bit computers? DJOtaku Linux - General 4 09-08-2005 08:14 PM
64bit or 32bit ginger.fish0 Ubuntu 3 09-01-2005 05:12 PM

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

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