这可能是一个简单的答案,但我正在尝试为简单的用户级文件系统编译代码。我在Windows Ubuntu子系统上运行代码。
我已更新并安装了所有lpthread和lreadline库,并且在编译时仍得到未定义的引用。
gcc -Wall -g -lreadline -lcurses -lpthread userfs.c parse.c crash.c -o userfs
/tmp/ccNrZDqQ.o: In function `main':
/home/kupinah/userfs/userfs.c:75: undefined reference to `readline'
/tmp/ccwcrZEh.o: In function `init_crasher':
/home/kupinah/userfs/crash.c:10: undefined reference to `pthread_create'
/home/kupinah/userfs/crash.c:14: undefined reference to `pthread_detach'
collect2: error: ld returned 1 exit status
Makefile:12: recipe for target 'userfs' failed
make: *** [userfs] Error 1
这里是每个位置的代码位置和标头。
userfs.c:
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <assert.h>
#include <string.h>
#include "parse.h"
#include "userfs.h"
#include "crash.h"
...
...
...
while(1) {
cmd_line = readline(buildPrompt());
if (cmd_line == NULL) {
fprintf(stderr, "Unable to read command\n");
continue;
}
...
...
makefile
CC = gcc
COMPILER_WARNINGS = -Wall
GDB_FLAGS = -g
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
GPROF_FLAGS = -pg -a
LD_LIBS = -lreadline -lcurses -lpthread
CFLAGS = $(COMPILER_WARNINGS) $(GDB_FLAGS) $(LD_LIBS)
all: userfs
userfs: userfs.c parse.c crash.c
$(CC) $(CFLAGS) userfs.c parse.c crash.c -o userfs
clean:
/bin/rm -f userfs *.o *~
帮助请
@ MadScientist帮助我解决了这一问题。
解决此问题的原因是对make文件进行了一些简单的编辑。
CC = gcc
COMPILER_WARNINGS = -Wall
GDB_FLAGS = -g
GCOV_FLAGS = -fprofile-arcs -ftest-coverage
GPROF_FLAGS = -pg -a
LD_LIBS = -lpthread -lreadline -lcurses
CFLAGS = $(COMPILER_WARNINGS) $(GDB_FLAGS)
all: userfs
userfs: userfs.c parse.c crash.c
$(CC) $(CFLAGS) userfs.c parse.c crash.c -o userfs $(LD_LIBS)
clean:
/bin/rm -f userfs *.o *~
更改:
LD_LIBS = -lpthread -lreadline -lcurses
----重新排序
CFLAGS = $(COMPILER_WARNINGS) $(GDB_FLAGS)
----已删除$(LD_LIBS)
userfs: userfs.c parse.c crash.c
$(CC) $(CFLAGS) userfs.c parse.c crash.c -o userfs $(LD_LIBS)
----添加了$(LD_LIBS)