我正在尝试使用 make 编译我的一段代码。通常我编译我的代码是这样的:
mipsisa32r2el-timesys-linux-gnu-g++ -o testing -I/usr/include/libxml2 -L/develop/xc4/rootfs/parsecpp/lib -L/develop/xc4/rootfs/parsecpp/sqlite-mips2/lib -I/develop/xc4/rootfs/parsecpp/sqlite-mips2/include db.cpp main.cpp networkinterfacemodule.cpp network.cpp multiplex.cpp program.cpp service.cpp -lsqlite3 -lxml2
为了摆脱这个长命令,我尝试编写一个 makefile:
CC= mipsisa32r2el-timesys-linux-gnu-g++
export LD_LIBRARY_PATH=:/parsecpp/sqlite-mips2/lib:/parsecpp/lib:/tmp/vixs_temp/DirectFB/single_core/lib
CFLAGS=-I/usr/include/libxml2 -I/develop/xc4/rootfs/parsecpp/sqlite-mips2/include
LDFLAGS=-L/develop/xc4/rootfs/parsecpp/lib -L/develop/xc4/rootfs/parsecpp/sqlite-mips2/lib
LIBS = -lsqlite3 -lxml2
PROG=testing
all: main.o db.o mod.o multiplex.o network.o networkinterfacemodule.o program.o service.o
$(CC) -o $(PROG) $(CFLAGS) $(LDFLAGS) main.o db.o mod.o multiplex.o network.o networkinterfacemodule.o program.o service.o $(LIBS)
main.o: main.cpp
$(CC) $(CFLAGS) $(LDFLAGS) main.cpp db.cpp networkinterfacemodule.cpp mod.cpp multiplex.cpp network.cpp program.cpp service.cpp $(LIBS)
db.o: db.cpp
$(CC) $(CFLAGS) $(LDFLAGS) db.cpp $(LIBS)
mod.o: mod.cpp
$(CC) $(CFLAGS) $(LDFLAGS) mod.cpp $(LIBS)
multiplex.o: multiplex.cpp
$(CC) $(CFLAGS) $(LDFLAGS) multiplex.cpp $(LIBS)
network.o: network.cpp
$(CC) $(CFLAGS) $(LDFLAGS) network.cpp $(LIBS)
networkmoduleinterface.o: networkinterfacemodule.cpp
$(CC) $(CFLAGS) $(LDFLAGS) networkinterfacemodule.cpp $(LIBS)
program.o: program.cpp
$(CC) $(CFLAGS) $(LDFLAGS) program.cpp $(LIBS)
service.o: service.cpp
$(CC) $(CFLAGS) $(LDFLAGS) service.cpp $(LIBS)
clean:
rm -rf *o testing
然后我得到这个错误:
/opt/timesys/linux-gnu/toolchain/bin/../../toolchain/lib/crt1.o: In function `__start':
(.text+0xc): undefined reference to `main'
/opt/timesys/linux-gnu/toolchain/bin/../../toolchain/lib/crt1.o: In function `__start':
(.text+0x10): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [db.o] Error 1
有谁能够帮助我?