Reputation: 3484
I have two files: osm.h and osm.cpp
I tried to create static lib from them, called "libosm.a" with Makefile.
my cpp and h file work( I compiled them without Makefile), but my Makefile doesn't 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'm getting:
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?
Upvotes: 1
Views: 11065
Reputation: 21269
I believe a make file as simple as this one will do the job
LIBSRC = osm.cpp
OSMLIB = libosm.a
CFLAGS = -Wall -g -O0
LOADLIBES = -L./
$(OSMLIB): $(LIBSRC)
just with the built-in rules of GNU make. And you really don't want to set CC to g++
at all. If then to gcc
which will pick the proper backend for you.
Note: to see the built-in rules of your make
, use this:
make -pn -f /dev/null
Upvotes: 3