Makefile - creating a static library

I have two files: osm.h and osm.cpp

I tried to create a static lib from them called "libosm.a" using the Makefile.

my cpp and h file work (I compiled them without a Makefile), but my Makefile does not work. This is the Makefile:

CC = g++
RANLIB = ranlib

LIBSRC = osm.cpp
LIBOBJ=$(LIBSRC:.cpp=.o)

CFLAGS = -Wall -g -O0
LOADLIBES = -L./

OSMLIB = libosm.a
TARGETS = $(OSMLIB)

all: $(TARGETS)

osm.o: osm.cpp osm.h
    $(CC) -c osm.cpp -o osm.o

$(TARGETS): $(LIBOBJ)
    ar rcs $(OSMLIB) osm.o
    ranlib $(OSMLIB)

clean:
    rm osm.o $(TARGETS) $(OSMLIB) $(LIBOBJ)

depend:
    makedepend -- $(CFLAGS) -- $(SRC) $(LIBSRC)

and this is part of the error I get:

osm.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12

can anyone help?

+1
source share
1 answer

I find the make file as easy as this to do the job

LIBSRC = osm.cpp
OSMLIB = libosm.a

CFLAGS = -Wall -g -O0
LOADLIBES = -L./

$(OSMLIB): $(LIBSRC)

just with built-in GNU make rules. And you really don't want to install CC on at g++all. If , then gcc, who will choose the appropriate server for you.

. make, :

make -pn -f /dev/null
+3

All Articles