1

I have compiled an Ada program on Ubuntu using GNAT.

Afterwards, I tried a few test runs with that program and it worked properly.

But when I uploaded this to my Apache (UNIX) webserver and tried to run the program, there was no output. Why is this so?

Could it be that programs which have been compiled on Ubuntu don't work on a UNIX server?

(Sorry for the stupid question!)

Linux version of the system I use for compiling (uname -a):

Linux ubuntu 3.0.0-12-generic #20-Ubuntu x86-64 GNU/Linux

Linux version of the system I want to run the program on later (uname -a):

Linux 2.6.37-he-xeon-64gb+1 i686 GNU/Linux

For compiling on the Ubuntu machine, I use:

gnatmake -O3 myprogram -bargs -static
caw
  • 30,999
  • 61
  • 181
  • 291
  • 3
    What specific operating system is your webserver? (what is the output of 'uname -a', for starters) – blueshift Mar 18 '12 at 15:11
  • 2
    it wouldn't surprise me that switching operating systems would necessitate a recompile, but I'm not familiar with Ada/GNAT – dldnh Mar 18 '12 at 15:13
  • Thank you, blueshift and dldnh! The server is: "Linux 2.6.37-he-xeon-64gb+1 i686 GNU/Linux" – caw Mar 18 '12 at 15:22
  • 1
    Try running the (an) Ada program in a terminal shell on the web server? (My guess would be, some problem with shared libraries, in which case `ldd` should give a clue). – Simon Wright Mar 18 '12 at 16:10
  • Yes I try to run this program with the help of PHP's function shell_exec(). The problem is: I got a pre-compiled version that works - even when I use PHP to access it. But the one I compiled does not. – caw Mar 18 '12 at 16:13
  • What happens when you run it from the command line? Is there an error message? – Keith Thompson Mar 18 '12 at 21:22
  • I don't have the possibility to run it from the command line, unfortunately. So the only way to use it, for me, is those PHP functions. – caw Mar 18 '12 at 23:11
  • 1
    You want to crosscompile from 64-bit to 32-bit. Not that easy. – Rommudoh Mar 19 '12 at 08:31
  • Thank you very much oenone! So I have to install Ubuntu as a 32-bit version and then it will probably work, right? – caw Mar 19 '12 at 09:34
  • I have now updated my Ubuntu for compiling to the 32-bit version. When I then run my Ubuntu-compiled version on the webserver and try `ldd myprogram`, it returns `statically linked` now instead of `not a dynamic executable`. Is this good news? (I can't see any output, though, so it doesn't really work yet.) – caw Mar 19 '12 at 14:14
  • 1
    "cross compile" is a bit over the top for this scenario. It's trivial to produce 32bit binaries on a 64bit system. Use gcc -m32 – Ярослав Рахматуллин Mar 26 '12 at 06:32

3 Answers3

7

When you build a GNAT program (gnatmake my_program), by default it links against dynamic libraries (libgnat.so, libgnarl.so). These libraries are part of the GNAT system and are very unlikely to be available on your web server.

If you say ldd my_program it will show you the shared libraries used.

You can force the build to use the static GNAT libraries by saying

gnatmake my_program -bargs -static

(the -bargs -static must come after regular flags like -O2).

Edit: more info on -bargs and friends.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • Thank you very much! And when I use `gnatmake -O3 -bargs -static myprogram` for example, it will (probably) work on my webserver? – caw Mar 18 '12 at 18:23
  • Did `ldd my_program` (on the original) show shared libs? If it did, then yes, you stand a better chance. `-bargs -static` needs to come last, as I showed; the way you have it, the `myprogram` would be sent only to the binder, not to the builder. – Simon Wright Mar 18 '12 at 21:11
  • When I run `ldd myprogram` on my webserver, it says `not a dynamic executable` whereas for the pre-compiled (working) program I get `linux-gate.so.1 => (0xffffe000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb777e000) libc.so.6 => /lib/libc.so.6 (0xb7640000) /lib/ld-linux.so.2 (0xb7793000) ` – caw Mar 18 '12 at 22:44
  • Now, after recompiling the program with `-bargs -static`, the size of the program increased from about 800kB to 1100kB. But nevertheless, `ldd` says: "not a dynamic executable". – caw Mar 18 '12 at 23:12
  • webserver is 32-bit, it won't execute 64-bit executables. – Rommudoh Mar 19 '12 at 08:32
  • When using a 32-bit version of Ubuntu for compiling, `ldd myprogram` does answer with `statically linked` now instead of `not a dynamic executable`. But there's still no output. – caw Mar 19 '12 at 14:15
  • Is it executable? what's the return value in the shell you started it? are you sure the program produces output? – Rommudoh Mar 19 '12 at 14:57
  • I don't know if it is executable. How do I check this? I'm sure that it produces output because when I run this program under Unix, it does. But PHP's `shell_exec()` has no output for this program. But if I take the pre-compiled version (that someone else has compiled, but I modified it) it has output - both under Ubuntu and with PHP's `shell_exec()`. – caw Mar 19 '12 at 15:33
  • The problem is that `ldd` returns `statically linked` for my own compilation but the list of libraries for the version that someone else has compiled. – caw Mar 19 '12 at 22:52
  • For my own compilation, `ldd` says `linux-gate.so.1 => (0xffffe000) libgnat-4.4.so.1 => not found libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb780e000) libc.so.6 => /lib/libc.so.6 (0xb76cf000) /lib/ld-linux.so.2 (0xb7823000)`. Could this be the problem? When you compare it to the output named in the comment above, the only difference is that libgcc is "not found". – caw Mar 27 '12 at 12:56
1

You must make sure that the server has the libraries your app links against or link them statically like already suggested by others. Some other comments point out that you need to "cross compile" or that the server won't run 64 bit binaries. This is easily solved unless the app you're building is very complex.

gnatmake --GCC='gcc -m32'

Will make a binary that will run on a 32bit system. However the chief problem is that the servers (g)libc is very likely to be older than what's on your ubunu box. Programs compiled against newer glibc will not necessarily run on systems with an older glibc installed.

for more info and plenty more links, look here:

Linking against an old version of libc to provide greater application coverage
How can I link to a specific glibc version?

edit: Besides, apache may not be configured to accept invocation of external binaries. Have you "tried to run the program" with something you know exists on the server? Try to run something trivial like /bin/ls to make sure your method of running the program works. Look at the logs if it doesn't work. Programs need to be executable, by the way: chmod 755 /path/to/webeserver/uploads/ada-app

Community
  • 1
  • 1
  • Thank you very much! The problem of cross-compiling is already solved as I'm using a 32-bit Ubuntu now. The question that is still open is why `ldd` returns `statically linked` for my own compilation but a list of libraries for the pre-compiled version. Is the pre-compiled version not statical so that it doesn't include the libraries and has dependences? – caw Mar 27 '12 at 12:32
  • And as I have statically linked the libraries, Apache doesn't need to allow the invocation of external libraries, does it? – caw Mar 27 '12 at 12:34
  • When I do NOT statically link the program (as the pre-compiled version is), `ldd` says `linux-gate.so.1 => (0xffffe000) libgnat-4.4.so.1 => not found libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb780e000) libc.so.6 => /lib/libc.so.6 (0xb76cf000) /lib/ld-linux.so.2 (0xb7823000)`. Is this the problem? It says "not found" ... – caw Mar 27 '12 at 12:54
  • 1
    Marco, the GNAT shared libraries being not found is why I recommended `-static` in the first place; the GNAT libraries are then linked in, so it doesn’t matter whether the webserver has them installed or not (it probably doesn’t). Have you tried building a simple ‘hello world’ application and just running that on the webserver? – Simon Wright Mar 27 '12 at 16:15
  • Yes, I know, but the static program didn't produce any output so I tried a dynamic one again. The hello_world program does produce output. It works. – caw Mar 27 '12 at 17:07
  • Even `./programname 2>&1` doesn't show any output. I'm really becoming desperate. – caw Mar 27 '12 at 17:09
  • And `/bin/ls` works, by the way. It shows the full list of files in the directory. And maybe even directories, but there are none. – caw Mar 27 '12 at 17:12
0

Why don't you just compile it on your Webserver instead of your local machine ?

Aswell cat /etc/issue or cat /etc/release could give us some information about the distribution you're using.

Nexus2k
  • 345
  • 1
  • 4
  • 13
  • On my Ubuntu machine, this command with "release" does say that there is no such directory. The command with "issue" says it's `Ubuntu 11.10 \n \l`. On my webserver, both commands produce no output. Is this the problem? No output here as well ... – caw Mar 27 '12 at 12:52
  • @MarcoW. Are you sure you're running Linux on your web server? – Earlz Mar 27 '12 at 21:07
  • Yes, of course. See the note in the question: `Linux 2.6.37-he-xeon-64gb+1 i686 GNU/Linux` – caw Mar 28 '12 at 16:22
  • does apt-get update produce some output ? Then you should be able to download all the nessecary tools to your Webserver to compile your programm – Nexus2k Mar 29 '12 at 17:17