Search code examples
c++amazon-web-servicescompilationg++amazon-ami

How do you build for Basic 64-bit Amazon Linux from Arch Linux?


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 

Solution

  • 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)