2012-03-07 96 views
1

我有两个文件:osm.h和osm.cppMakefile文件 - 创建一个静态库

我试图创建从中静态库,被称为“libosm.a”与Makefile文件。

我的cpp和h文件的工作(我编译他们没有Makefile),但我的Makefile不起作用。这是在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) 

,这是我得到的错误的部分:

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 

谁能帮助?

+0

也请写发出此错误消息的命令。 – 2012-03-07 14:45:58

+0

在你的问题中添加'osm.o:'功能...'上方的行。它应该是由make生成的命令生成错误。 – 2012-03-07 15:24:41

回答

3

我相信make文件那么简单,这个人会做的工作

LIBSRC = osm.cpp 
OSMLIB = libosm.a 

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

$(OSMLIB): $(LIBSRC) 

只是GNU的内置规则做出。而你真的根本不想将CC设置为g++如果然后到gcc这将为您选择适当的后端。

注:看到您的make的内置规则,使用此:

make -pn -f /dev/null