Solved

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

Posted on 1998-12-24
7
291 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 32

Accepted Solution

by:
jhance earned 350 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now