编译时报错:
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
解决办法:检查函数发现"main()"并没有写错,然后去看到makefile文件:
include ../unpv22e/Make.defines
# Following required by Solaris 2.x for Posix version of sigwait().
#CFLAGS += -D_POSIX_PTHREAD_SEMANTICS
PROGS = 246
CFLAGS = -Wall -g
VPATH = ../unpv22e/lib
depends_c = $(wildcard ../unpv22e/lib/*.c)
depends_o = $(wildcard ../unpv22e/lib/*.o)
depends_h = $(wildcard ../unpv22e/lib/*.h)
all: ${PROGS}
#ar rv ${LIBUNPIPC_NAME} $? #创建库文件
#${RANLIB} ${LIBUNPIPC_NAME}
246:246.o ../unpv22e/lib/px_ipc_name.c ../unpv22e/lib/error.c
${CC} ${CFLAGS} -o 246.o ../unpv22e/lib/px_ipc_name.c ../unpv22e/lib/error.c -pthread
246.o : 246.c
clean:
rm -f *.o
错误原因还是不熟悉gcc的编译参数,-o后接的应该是生成的可执行文件名,改成下面这样:
${CC} ${CFLAGS} -o 246 246.o ../unpv22e/lib/px_ipc_name.c ../unpv22e/lib/error.c -pthread