pythonic
pythonic

Reputation: 21665

Simple makefile for compiling a shared object library file

I need a very simple makefile to compile a shared object library file (*.so). I also need to know how to pass optimization parameters like -O2 and -O3. I tried to search for simple examples using google, but all examples are twisted.

I don't need to create any version like *.so.1.0 but only a simple *.so file. My project would have multiple files, so I need an example which compiles multiple files.

Upvotes: 2

Views: 12316

Answers (1)

Robᵩ
Robᵩ

Reputation: 168836

The simplest makefile that I can think of that does what you want:

CXXFLAGS += -fPIC
CXXFLAGS += -O3
x.so: x.o y.o
    g++ -shared $^ -o $@

In the alternative, you may want to use more of make's built-in rules and variables:

CXXFLAGS += -fPIC
CXXFLAGS += -O3
x.so: x.o y.o
    $(LINK.cc) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@

Upvotes: 3

Related Questions