未定义的引用(readline,pthread_create,pthread_detach),makefile不包含库

黑莓

这可能是一个简单的答案,但是我正在尝试为简单的用户级文件系统编译代码。我在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;
        }

...
...


生成文件

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)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

编译boch时,对符号'pthread_create @@ GLIBC_2.2.5的未定义引用

来自分类Dev

编译boch时,对符号'pthread_create @@ GLIBC_2.2.5的未定义引用

来自分类Dev

编译对符号'pthread_create @@ GLIBC_2.2.5'的apib未定义引用

来自分类Dev

对pthread的未定义引用

来自分类Dev

未定义对`pthread_create'的引用使用ASIO和std :: thread制作C ++ 11应用程序时出错

来自分类Dev

如何在构建单线程库时删除pthread未定义引用

来自分类Dev

未定义对“ pthread_key_create”的引用(链接器错误)

来自分类Dev

对'__gthrw___pthread_key_create的未定义引用(unsigned int *,void(*)(void *))

来自分类Dev

未定义对“ pthread_key_create”的引用(链接器错误)

来自分类Dev

对pthread中的运行器的未定义引用

来自分类Dev

未定义对pthread创建的引用,即使使用lpthread

来自分类Dev

对pthread中的运行器的未定义引用

来自分类Dev

即使在pthread_detach之后也会泄漏

来自分类Dev

关于 pthread_join() 和 pthread_detach() 的问题

来自分类Dev

不带pthread_create的pthread_self

来自分类Dev

绕行的pthread_create产生的线程不执行指令

来自分类Dev

与 pthread_create (C) 不兼容的指针类型

来自分类Dev

pthread_detach()在64位Linux上导致SIGSEGV

来自分类Dev

存在现有联接程序时的pthread_detach行为

来自分类Dev

pthread不继承定义器并包含文件

来自分类Dev

pthread_create快速示例

来自分类Dev

在GCC6中未定义对'rt','pthread','stdc ++ fs'的引用

来自分类Dev

Synergy 1.4.16 无法编译 - 未定义对 `pthread_xxxx' 的引用

来自分类Dev

即使包含库等,也未定义对PQfinish的引用

来自分类Dev

C- Readline()未定义引用

来自分类Dev

关于线程的pthread_join()和pthread_detach()的“回收存储”是什么意思?

来自分类Dev

主Makefile中的未定义引用

来自分类Dev

Makefile链接:对_exit的未定义引用

来自分类Dev

主Makefile中的未定义引用

Related 相关文章

  1. 1

    编译boch时,对符号'pthread_create @@ GLIBC_2.2.5的未定义引用

  2. 2

    编译boch时,对符号'pthread_create @@ GLIBC_2.2.5的未定义引用

  3. 3

    编译对符号'pthread_create @@ GLIBC_2.2.5'的apib未定义引用

  4. 4

    对pthread的未定义引用

  5. 5

    未定义对`pthread_create'的引用使用ASIO和std :: thread制作C ++ 11应用程序时出错

  6. 6

    如何在构建单线程库时删除pthread未定义引用

  7. 7

    未定义对“ pthread_key_create”的引用(链接器错误)

  8. 8

    对'__gthrw___pthread_key_create的未定义引用(unsigned int *,void(*)(void *))

  9. 9

    未定义对“ pthread_key_create”的引用(链接器错误)

  10. 10

    对pthread中的运行器的未定义引用

  11. 11

    未定义对pthread创建的引用,即使使用lpthread

  12. 12

    对pthread中的运行器的未定义引用

  13. 13

    即使在pthread_detach之后也会泄漏

  14. 14

    关于 pthread_join() 和 pthread_detach() 的问题

  15. 15

    不带pthread_create的pthread_self

  16. 16

    绕行的pthread_create产生的线程不执行指令

  17. 17

    与 pthread_create (C) 不兼容的指针类型

  18. 18

    pthread_detach()在64位Linux上导致SIGSEGV

  19. 19

    存在现有联接程序时的pthread_detach行为

  20. 20

    pthread不继承定义器并包含文件

  21. 21

    pthread_create快速示例

  22. 22

    在GCC6中未定义对'rt','pthread','stdc ++ fs'的引用

  23. 23

    Synergy 1.4.16 无法编译 - 未定义对 `pthread_xxxx' 的引用

  24. 24

    即使包含库等,也未定义对PQfinish的引用

  25. 25

    C- Readline()未定义引用

  26. 26

    关于线程的pthread_join()和pthread_detach()的“回收存储”是什么意思?

  27. 27

    主Makefile中的未定义引用

  28. 28

    Makefile链接:对_exit的未定义引用

  29. 29

    主Makefile中的未定义引用

热门标签

归档