Solved

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

Posted on 1998-12-24
7
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

726 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