LinuxQuestions.org
Visit Jeremy's Blog.
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 04-04-2007, 07:55 AM   #1
entz
Member
 
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Rep: Reputation: 40
Inter-distro binary compatibility


Greetings,

Well this post isn't about programming in the direct sense of the word more it deals with an issue I'm having when I try to run a binary executable on different boxes (local as well as remote ones)

The point is that I'm writting a server-side application that is supposed to run on a remote machine (listening on port/s , processing data etc ...) , which runs fine on my local suse box and also without glitches on another (remote) linux box but It doesn't run at all giving me a strange error (I'll present the errot message later in this post) on the third box until I scp the code to that machine and compile it there ...

so here is a summary of the box versions and on which the binary runs and which not:
MY SUSE 10.1 box
Code:
Linux version 2.6.16.21-0.25-default (geeko@buildhost) (gcc version 4.1.0 (SUSE Linux)) #1 Tue Sep 19 07:26:15 UTC 2006
first remote A.K.A "Robinhood"
Code:
Linux version 2.6.18-3-686 (Debian 2.6.18-7) (waldi@debian.org) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)) #1 SMP Mon Dec 4 16:41:14 UTC 2006
Second Remote A.K.A "Phoenix"
Code:
Linux version 2.6.18-028test010.1-ovz (root@build32.sarge.systs.org) (gcc version 3.3.5 (Debian 1:3.3.5-13)) #1 Fri Jan 12 22:33:48 CET 2007
SO far so good?
now the binary that's compiled on Suse works on my box (how obvious) and works on Robinhood but does NOT work on phoenix !
But when the same code is uploaded to phoenix and compiled there then , it works there and also on Suse (after I download the binary back to my machine)

Now the error message that I get when trying to run the binary on phoenix which was compiled on suse is as follows:
Code:
./server: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
Well to me it sounds like a runtime linking error or something in that direction.

I'd appreciate as much feedback as you can offer , feel free to let me know in case I didn't give enough infos to solve this issue.

and thanks
 
Old 04-04-2007, 09:52 AM   #2
debulu
Member
 
Registered: May 2006
Location: India
Distribution: Redhat
Posts: 49

Rep: Reputation: 15
Do a ldd on your program executable and see the library dependencies. Looking your gcc specs believe that its a GCC version issue.
Upgrade the GCC version on the trouble giving machine.

Hope helps
 
Old 04-04-2007, 10:20 AM   #3
runnerfrog
Member
 
Registered: Jul 2006
Location: Paraná, Argentina
Distribution: Frugalware 0.6 (Terminus) - Kubuntu 7.04 (Feisty Fawn Herd 5)
Posts: 217

Rep: Reputation: 31
Quote:
Originally posted by entz:
Now the error message that I get when trying to run the binary on phoenix which was compiled on suse is as follows:

Code:
./server: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
As I see it, having in mind the error message, and from one may be simplistic perspective, you should only compile after configured including static libraries, not shared ones.
Start by trying to configure with that option, something like: ./configure --enable-static
then make and the rest of the process.

Quote:
Originally posted by debulu:
Upgrade the GCC version on the trouble giving machine.
I'd be surprised if that gives any improvement to this particular situation, but strange things happens sometimes, isn't?

Cheers.
 
Old 04-04-2007, 11:19 AM   #4
entz
Member
 
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Original Poster
Rep: Reputation: 40
Aha I guess I'm starting to grasp the problem!

first things first
Quote:
Upgrade the GCC version on the trouble giving machine.
Well this is definately ruled out since I'm not enjoying root privileges on that machine.

Quote:
As I see it, having in mind the error message, and from one may be simplistic perspective, you should only compile after configured including static libraries, not shared ones.
Start by trying to configure with that option, something like: ./configure --enable-static
then make and the rest of the process.
Actually it may sound embarrasing to me but I must admit that I don't use "make" to compile my apps (or more precisely I don't know how or even what a make file is good for)
I just resort to a simple shell script I've written which passes something like this to the command-line:
Code:
g++ -o mybinary /wherever/source/main.cpp
you get the idea I'm a *unix nOOby

SO can you gimme a crash course on what a make file is and/or what makes it different from passing some stupid arguments to GCC/G++ in order to compile a proggie using a shell script?
another things is , what is the difference between a static and a shared library ?
from my windows background I'd assume that those two library types are equivilant to the *.lib and *.dll (dynamic link library) In Billy's world where the first is linked at process startup and cannot be unlinked while the second can be linked/unlinked whenever the process sees it fit , correct me plz if i'm wrong!

and thanks
 
Old 04-04-2007, 11:56 AM   #5
runnerfrog
Member
 
Registered: Jul 2006
Location: Paraná, Argentina
Distribution: Frugalware 0.6 (Terminus) - Kubuntu 7.04 (Feisty Fawn Herd 5)
Posts: 217

Rep: Reputation: 31
The thing is that your main.cpp file surely has (at least) one include directed to a file of the libstdc++6-dev package that is in a different version than the correspondent libs on the other box.
You want a fast solution instead of recoding? Upgrade your GNU Standard C++ Library (libstdc++6 and libstdc++6-dev) in both boxes to a compatible or same version, including the development package too, for better results. Watchout because that might require upgrading other packages aswell.
For staticly linking the dependency, which might be the neat way here, you should show your code and script, but I _suck_ at programming so I can't promise anything yet. Hopefully a good coder will see it, if you post it.

Just a crazy guess from a deranged guy, try:
Code:
g++ -o -static mybinary /wherever/source/main.cpp
Or try:
Code:
g++ -o -static-libgcc mybinary /wherever/source/main.cpp
Have you read the g++ man pages?
I quote:
Quote:
-static
On systems that support dynamic linking, this prevents linking with
the shared libraries. On other systems, this option has no effect.

-shared
Produce a shared object which can then be linked with other objects
to form an executable. Not all systems support this option. For
predictable results, you must also specify the same set of options
that were used to generate code (-fpic, -fPIC, or model suboptions)
when you specify this option.[1]
 
Old 04-04-2007, 11:57 AM   #6
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
you are right on about the runtime link error. you either dont have libstdc++.so.6, or it is not at the standard location. if you do have it, you can add the path to /etc/ld.so.conf and run ldconfig (or just add that path to LD_LIBRARY_PATH).. either of those methods will allow the runtime linker to find the lib..

> or more precisely I don't know how or even what a make file is good for
what you are doing for a single file, or even small projects is fine, and really it is an overkill to use make for a single file or even a couple files. however when you have a large project make, along with configure (and optionally others), allow you to easily manage changes to the build, and to allow for a flexible build for your users.

simple make files can be written by hand, and its good to learn, but once you get into complex builds you will want to learn how to use the tools that generate the configure and make files for you.

edit> and yes you are right about the differences btw the static and shared libs. static are compiled into your binary, shared libs (like a dll) are expected to be available at run time from an external source.

Last edited by xhi; 04-04-2007 at 11:59 AM.
 
Old 04-04-2007, 02:39 PM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,752

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
That's one of the problems with using C++ -extra compiler-library dependencies. The same thing written in C would be much more portable...
 
Old 04-04-2007, 02:46 PM   #8
entz
Member
 
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Original Poster
Rep: Reputation: 40
OK , so the conclusion to this problem is that the machine in question is either missing or mis-placing the libstdc++.so6 (if not more) shared library file.

@runnerfrog:
I've tried using the argument that u specified "-static" , it resulted in a binary file that's insanely huger (about 1 MB compared to the previous 9 KB ) than before . but I assume that this is
supposed to happen because static linking after all (as xhi mentioned earlier) means that all static and non-static dependcies are compiled right away into the executable.

Ironically , I can't log into the trouble-making machine , because the sshd daemon on it is dead or something (Btw did I mention that this "phoenix" is probably one of the worst managed servers online??) , after putting all the evidence together it seems natural why things weren't working on it.

Thanks for the feedback so far guys , I'm gonna post again in case the "-static" compiler option didn't bring me further.
 
Old 04-05-2007, 08:38 AM   #9
entz
Member
 
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Original Poster
Rep: Reputation: 40
HI again

I wanted to say that I've finally got the chance to test whether a statically build binary would work and Yes it did!
but I've just one final rather simpe question in this regard , which is :
HOW can I tell g++ to statically link only one shared object (basically that which is missing on the machine that's supposed to run on) instead of linking everything to avoid making astronomical binaries.

btw I'v tried to specify the shared object path after the argument "-static" (-static /usr/lib/libstdc++.so.6) But it gives me an error saying : "attempted static link of a shared object"
guess that's weird , why can I static link everything but NOT static link only a handpicked object?
 
Old 04-05-2007, 07:07 PM   #10
runnerfrog
Member
 
Registered: Jul 2006
Location: Paraná, Argentina
Distribution: Frugalware 0.6 (Terminus) - Kubuntu 7.04 (Feisty Fawn Herd 5)
Posts: 217

Rep: Reputation: 31
Quote:
Originally posted by entz:
I'v tried to specify the shared object path after the argument "-static" (-static /usr/lib/libstdc++.so.6) But it gives me an error saying : "attempted static link of a shared object"
Because you are trying to link to a compiled library, not to a header.
To know to which particular header of the libstdc++ package to link (there are many), you'll have to examine those starting lines in your main.cpp file that points to headers contained in the libstdc++-dev package (or libstdc++-devel).
Enough said, but anyway, e.g:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
(Those doesn't belong to libstdc++, you'll have to check).
 
  


Reply


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
Looking for binary install Gentoo-based Distro pengu Linux - Distributions 5 06-14-2006 10:29 AM
Distro: Less scripting. Looking for mainly Elf binary based distro Z505 Linux - General 1 04-02-2005 11:33 PM
Best Binary-based distro w/ many packages? ShyGuy91284 Linux - General 9 03-16-2005 03:31 AM
Binary Compatibility Between Redhat 9 And Fedora lordofring Linux - Software 0 02-14-2005 09:27 PM
Binary/Source Distro Installation Help SML Linux - Newbie 1 02-17-2004 12:32 AM


All times are GMT -5. The time now is 02:46 PM.

Main Menu
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