Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Porting binaries compiled on Linux RedHat 5.1 on other systems / Gethostbyaddr()

Posted on 1998-12-24
7
Medium Priority
?
361 Views
Last Modified: 2013-12-26
Hello, this is for you experts, I've been browsing the net for days looking for an answer.

I have this simple program:

#include <stdio.h>
main()
{
   printf("\nSimple program.\n");
}

I compile it using the command line:

gcc -o port_test port_test.c

The program binary, about 4k of size, runs fine on my Linux Redhat 5.1, but as soon as I try to copy it on another system (tried with Slackware and Debian Linux), I get this error message:

./port_test: No such file or directory

I thought it could be a problem with the shared libraries, and I recompiled the program with this command line:

gcc -static -o port_test.st port_test.c

Now my program, which has reached a size of 435k, runs fine on every system.

Unfortunately, in a program slightly bigger than the example above, when I try to call an important system function, "gethostbyaddr()", it returns an error condition without setting any additional information in the external variable h_error.
However, the function call seems to work fine on my personal system (cannot say actually, since my pc is not connected, but it can resolve "localhost" at least).

I tought it was easier to solve the problem understanding how to run my binary with shared libraries on other systems, and this is what the question is about.

However, if someone has additional information about how to solve the problem with gethostbyaddr() I can provide more explanation about that aspect, and more points as well.

So the question is:

- How can I run my binary compiled on my Linux RedHat 5.1 without the -static switch, that is using shared libraries?
0
Comment
Question by:cip
  • 4
  • 3
7 Comments
 
LVL 1

Author Comment

by:cip
ID: 1294979
Pardon, I forgot something in the question at the end of the message, the right question is:

- How can I run my binary compiled on my Linux RedHat 5.1 without the -static switch, that is using shared libraries, on different Linux systems, such as Slackware and Debian?
0
 
LVL 32

Expert Comment

by:jhance
ID: 1294980
The problem is the VERSION of the dynamically linked C run-time libraries you are using on your RedHat system.  This is the "libc" problem and you can only solve it by using static linked executables or getting a compatible version of libc on your other systems.  Generally, it needs to be in the same version "family".  For example, you may have:

/lib/libc.so.5.3.12  on your RedHat system but something like:
/lib/libc.so.4.7.6   on your Slackware system.  You executable from the RedHat system is looking for a libc.so.5.x.x compatible runtime but can't find it.  You can download the libc.so.5.x.x from a Linux site and put it on the other systems.
0
 
LVL 1

Author Comment

by:cip
ID: 1294981
jhance, the problem looks to be exactly what you say. I have gnu library 2.0 (libc 6.0) on my system, while the target system has libc 5.4.13. But this doesn't answer my question.

I cannot run the risk of installing new libraries on the target system, since it is used by several other users, so I have to find a way to compile my application in a way that it is compatible with libc 5. In these days I have tried to build and install gcc as cross-compiler for libc 5, but it is a very difficult task and I'm still in the process of doing it.

I don't know if there is an easier way, and my question still remains:

- How can I compile my application on a system with gnulibc 2.0 (libc 6.0) so that it is compatible with a system with libc 5.4.13?

Any help in successfully setting up a gcc cross-compiler for a target system with libc 5 installed will obviously be worthing the points.

On my system, I have seen the directory /usr/lib/i486-linux-libc5, which seems to provide compatibility with application compiled with libc 5. Is there a way to use that directory with gcc to compile libc 5 compatible?

I can increase the points if needed.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 32

Accepted Solution

by:
jhance earned 700 total points
ID: 1294982
You cannot link with libc6 and run on a libc5 system.  

You must either upgrade the target system to include libc6 or link your executable with libc5.  Since updating the target system is not practical, you need to link with libc5 on your development system.
0
 
LVL 1

Author Comment

by:cip
ID: 1294983
Ok, jhance. I'll keep trying to install my cross-compiler.

My goal is now to compile with libc5 on a libc6 system, I'll take some additional days trying to do it.

If you do have any additional information about how to compile libc5 on a libc6 system, please insert comments, I can raise the points if they're useful. Anyway, you're answer is the major candidate at the moment.


0
 
LVL 32

Expert Comment

by:jhance
ID: 1294984
I wish I could help you more.  I _know_ that your problem is due to library incompatibility.  I _know_ that the best solution is to install compatible libraries on the target systems.  I _know_ that you can build "old library" apps by reverting back to an older version of the compiler and run-time libs that will work.

I _think_ you can set some switcher to gcc or the linker and get it to link with an older version of the library.  I just don't know how to do it and I've not been able to find out how.
0
 
LVL 1

Author Comment

by:cip
ID: 1294985
Ok, thanks for your help jhance.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question