www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D CGI test: linux.so.2: bad ELF interpreter: No such file or directory

reply "Nick Sabalausky" <a a.a> writes:
I've made a little test CGI app:

import std.conv;
import std.stdio;

void main()
{
 auto content = "<b><i>Hello world</i></b>";
 auto headers =
`HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: `~to!string(content.length);

 while(readln().length > 1) {}

 writeln(headers);
 writeln();
 writeln(content);
}

Works on Windows command line and through IIS. And it works on my Kubuntu 
10.6 command line. But if I copy the executable from my Kubuntu box to my 
web host's Debian server: Running it through Apache gives me a 500, and 
running it directly with ssh gives me:

linux.so.2: bad ELF interpreter: No such file or directory

I assume that error message is the cause of the 500 (can't tell for sure 
because the 500 isn't even showing up in my Apache error logs). But I'm not 
enough of a linux expert to have the slightest clue what that error message 
is all about. I don't need to actually compile it *on* the server do I? I 
would have thought that all (or at least most) Linux distros used the same 
executable format - especially (K)Ubuntu and Debian.
Apr 25 2011
parent reply Robert Clipsham <robert octarineparrot.com> writes:
On 25/04/2011 21:38, Nick Sabalausky wrote:
 Works on Windows command line and through IIS. And it works on my Kubuntu
 10.6 command line. But if I copy the executable from my Kubuntu box to my
 web host's Debian server: Running it through Apache gives me a 500, and
 running it directly with ssh gives me:

 linux.so.2: bad ELF interpreter: No such file or directory

 I assume that error message is the cause of the 500 (can't tell for sure
 because the 500 isn't even showing up in my Apache error logs). But I'm not
 enough of a linux expert to have the slightest clue what that error message
 is all about. I don't need to actually compile it *on* the server do I? I
 would have thought that all (or at least most) Linux distros used the same
 executable format - especially (K)Ubuntu and Debian.

This is probably occurring due to different versions of dynamic libraries on the kubuntu and debian boxes. ldd <executable> will tell you which versions the application is linking against, it's probably libc that's the issue, or one of the other core libraries. The solution is either to link against the correct library version, or statically link the version you need. Most likely the version of debian on the server uses an older library, which you'll need to link against. -- Robert http://octarineparrot.com/
Apr 25 2011
parent reply "Nick Sabalausky" <a a.a> writes:
"Robert Clipsham" <robert octarineparrot.com> wrote in message 
news:ip4nhc$2mdp$1 digitalmars.com...
 On 25/04/2011 21:38, Nick Sabalausky wrote:
 Works on Windows command line and through IIS. And it works on my Kubuntu
 10.6 command line. But if I copy the executable from my Kubuntu box to my
 web host's Debian server: Running it through Apache gives me a 500, and
 running it directly with ssh gives me:

 linux.so.2: bad ELF interpreter: No such file or directory

 I assume that error message is the cause of the 500 (can't tell for sure
 because the 500 isn't even showing up in my Apache error logs). But I'm 
 not
 enough of a linux expert to have the slightest clue what that error 
 message
 is all about. I don't need to actually compile it *on* the server do I? I
 would have thought that all (or at least most) Linux distros used the 
 same
 executable format - especially (K)Ubuntu and Debian.

This is probably occurring due to different versions of dynamic libraries on the kubuntu and debian boxes. ldd <executable> will tell you which versions the application is linking against, it's probably libc that's the issue, or one of the other core libraries. The solution is either to link against the correct library version, or statically link the version you need. Most likely the version of debian on the server uses an older library, which you'll need to link against.

Thanks. How would I statically link against libc?
Apr 25 2011
parent reply Robert Clipsham <robert octarineparrot.com> writes:
On 26/04/2011 00:05, Nick Sabalausky wrote:
 Thanks. How would I statically link against libc?

The way to do this with C is to pass -static to gcc, and I recall doing something similar with dmd to get it working (maybe -L-static?) - I don't have a linux machine near me to test with though, sorry. -- Robert http://octarineparrot.com/
Apr 26 2011
next sibling parent "Nick Sabalausky" <a a.a> writes:
"Robert Clipsham" <robert octarineparrot.com> wrote in message 
news:ip623p$23in$1 digitalmars.com...
 On 26/04/2011 00:05, Nick Sabalausky wrote:
 Thanks. How would I statically link against libc?

The way to do this with C is to pass -static to gcc, and I recall doing something similar with dmd to get it working (maybe -L-static?) - I don't have a linux machine near me to test with though, sorry.

Hmm, that doesn't seem to work, I just get: /usr/bin/ld: cannot find -lgcc_s collect2: ld returned 1 exit status --- errorlevel 1 I think I'm going to start a new thread for this...
Apr 26 2011
prev sibling parent Spacen Jasset <spacenjasset yahoo.co.uk> writes:
On 26/04/2011 10:05, Robert Clipsham wrote:
 On 26/04/2011 00:05, Nick Sabalausky wrote:
 Thanks. How would I statically link against libc?

The way to do this with C is to pass -static to gcc, and I recall doing something similar with dmd to get it working (maybe -L-static?) - I don't have a linux machine near me to test with though, sorry.

operating system applications. It may work, it may crash etc. The way to do this is to link against the oldest libc you need to support, thus making the binaries forward compatible.
Apr 26 2011