小编aas*_*rms的帖子

编译 -lpthread 时没有引用 pthread_mutex_lock

我正在编译一个包含来自 pthread 库的互斥信号量的程序,但是当我使用 -lpthread 标志进行编译时,我收到了未定义的引用错误。

gcc -lpthread prodcon.c
/tmp/ccESOlOn.o: In function `producer':
prodcon.c:(.text+0x2e): undefined reference to `pthead_mutex_lock'
prodcon.c:(.text+0xd6): undefined reference to `pthead_mutex_unlock'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

互斥锁的语法如下:

pthread_mutex_t mutex1;
Run Code Online (Sandbox Code Playgroud)

是一个全局声明,以便它可以被多个线程使用。在函数中,我像这样调用互斥体:

pthead_mutex_lock(&mutex1);
pthead_mutex_unlock(&mutex1);
Run Code Online (Sandbox Code Playgroud)

但我收到编译器错误,我也尝试使用 -pthread 标志进行编译

gcc -pthread prodcon.c
/tmp/cc6wiQPR.o: In function `producer':
prodcon.c:(.text+0x2e): undefined reference to `pthead_mutex_lock'
prodcon.c:(.text+0xd6): undefined reference to `pthead_mutex_unlock'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我已经寻找答案,但我不知所措,并且希望能够帮助您弄清楚当我链接到包含互斥锁的库时为什么它有未定义的引用。

c mutex pthreads linker-errors undefined-reference

3
推荐指数
1
解决办法
1万
查看次数

在LISP中作为未定义函数变量

作为一个项目,我需要使用递归在lisp中创建一个罗马数字转换器.在处理罗马数字到英语部分时,我遇到了一个问题,编译器告诉我,我的一个变量是一个未定义的函数.我是lisp的新手,可以使用此程序可能的任何提示或技巧.我想知道我必须做出的改变,以避免得到该错误,如果有人有我的递归的提示,将不胜感激.

我知道我的代码很乱,但我打算学习所有正确的格式化方法,当我有一些有用的东西时.该函数应该采用罗马数字列表,然后将列表的第一个和第二个元素转换为相应的整数并添加它们.它递归调用,直到它返回NIL时它将返回0并添加所有剩余的整数并将其显示为原子.希望这是有道理的.先感谢您.

(defun toNatural (numerals)
  "take a list of roman numerals and process them into a natural number"
  (cond ((eql numerals NIL) 0)
    ((< (romans (first (numerals)))
        (romans (second (numerals))))
     (+ (- (romans (first (numerals))))
        (toNatural (cdr (numerals)))))
    (t
     (+ (romans (first (numerals)))
        (toNatural (cdr (numerals)))))))


(defun romans (numer)
  "take a numeral and translate it to its integer value and return it"
  (cond((eql numer '(M)) 1000)
       ((eql numer '(D)) 500)
       ((eql numer '(C)) 100)
       ((eql numer '(L)) 50)
       ((eql numer …
Run Code Online (Sandbox Code Playgroud)

lisp common-lisp

1
推荐指数
1
解决办法
495
查看次数