I need to compile fat binary file to be able use it on another linux machine. But there are some libraries missing so as I understand I should compile it with some -shared options. But I don't understand how to configure a Makefile for that. Currently my makefile looks like this:
CC = g++
CC_FLAGS = -std=c++11 -O2 -static -Wall
EXEC = cpp_server
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
LIBS = -lpthread -lmicrohttpd -lz
$(EXEC): $(OBJECTS)
$(CC) $(OBJECTS) -o $(EXEC) $(LIBS)
%.o: %.cpp
$(CC) -c $(CC_FLAGS) $< -o $@
clean:
rm -f $(EXEC) $(OBJECTS)
You'll better take advantage of the many built-in rules of GNU make. Run once
make -p
to learn them. So you should useCXX
instead ofCC
and replaceCC_FLAGS
withCXXFLAGS
.You may want to build a statically linked executable. Then you should pass
-static
into your linking command, usingLINKFLAGS
So try with
AFAIK you don't need anything more in your
Makefile
(provided you use a GNUmake
, not e.g. a BSD one). Of course you need appropriate TAB characters in yourMakefile
(so you need to use some editor able to insert them).You could want to statically link only
-lmicrohttpd
(and dynamically link the other libraries; however, you might want to also statically link the C++ standard library, which depends upon the compiler and could change when the compiler changes; linking also the C++ library statically is left as an exercise). You could do that with removing theLINKFLAGS
line and usingBTW the
-shared
linker option is need to build from position-independent code object files a shared library (not to use one). See this and that.You may want to use
make --trace
(orremake -x
, using remake) to debug yourMakefile
If you want to understand what actual files are linked, add
-v -Wl,--verbose
toLINKFLAGS
perhaps by runningmake 'LINKFLAGS=-v -Wl,--verbose'
on your terminal.You might want to
make clean
before anything else.