Solved

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

Posted on 1998-12-24
7
304 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 68
Expand macro to ask for filename column 8 37
canBalance challenge 34 69
How to convert MFC::CString to UTF8 wchar_t* 10 137
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

12 Experts available now in Live!

Get 1:1 Help Now