2

I figured it wouldn't work, but i just uploaded my program file from local machine to a new instance on Amazon EC2. Than tried to run it:

[ec2-user@domU-12-31-39-14-2A-1A ~]$ ./webserver.net
-bash: ./webserver.net: /lib/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory

Apparently there is no /lib/ld-linux-x86-64.so.2. It is a 64 bit Instance.

How would i compile/link on local machine targeting the EC2 instance. I don't want to build it on the instance.

My Makefile

OBJECTS= ./obj/hello.o
LDFLAGS = -L/usr/lib -lwt -lwthttp

./bin/webserver.net : $(OBJECTS)
    g++ -o ./bin/webserver.net $(OBJECTS) $(LDFLAGS)

./obj/hello.o : ./src/hello.cpp 
    g++ -c ./src/hello.cpp -o ./obj/hello.o 

.PHONY: clean

clean:
    -rm -f obj/*.o bin/webserver.net core *~ src/*~ 

Update Statically linked file. There were undefined references until I added each library manually and in the right order. Is this necessary? or am I doing it wrong?

g++ -static -pthread -o ./bin/out.net ./obj/hello.o -lwthttp -lwt  -lboost_thread -lboost_system -lboost_program_options -lboost_random -lboost_signals -lboost_filesystem -lboost_regex -lboost_serialization -lboost_date_time -lssl -lcrypto -lz -ldl 
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Joe McGrath
  • 1,481
  • 10
  • 26

2 Answers2

2

An ugly but simple solution might be to link statically your program.

A more elaborate solution could be to mimic the environment of the EC2 instance in e.g. a chroot-ed environment on your local machine.

In between you might copy the EC2's /usr/include and /usr/lib/libc.so... etc.. locally, but that is risky.

Perhaps also you could compile locally, and link on the EC2... (but that might not work)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
1

A dynamic library lib*.so can be built with dependencies on other dynamic libraries. (for instance, try ldd /usr/lib/libgtk-3.so or ldd on some other system *.so library on your machine).

A static library lib*.a is essentially only a mix of *.o object files and don't know its dependencies.

So when linking statically, you need indeed to link all the libraries, in the correct order.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Thanks. my next question "Can i just join all these files together?" was already answered on SO [here](http://stackoverflow.com/questions/13128/how-to-combine-several-c-c-libraries-into-one) – Joe McGrath Nov 07 '11 at 17:02