Pthread_create C11 中的函数
Pthread_create function in C11
我正在尝试用 Pthread_create
创建一个 pthread
:
#include <pthread.h>
void *worker(void *arg) {
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t p1, p2;
Pthread_create(&p1, NULL, worker, NULL);
Pthread_create(&p2, NULL, worker, NULL);
return 0;
}
clang -Wall -std=c11 -pthread thread.c -o thread
体系结构的未定义符号 x86_64:"_Pthread_create"
:
thread.c:13:2: warning: implicit declaration of function 'Pthread_create' is
invalid in C99 [-Wimplicit-function-declaration]
Pthread_create(&p1, NULL, worker, NULL);
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_Pthread_create", referenced from:
_main in thread-3223a1.o
ld: symbol(s) not found for architecture x86_64
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
改成-std=c99
后没有任何变化
我的代码有什么问题?
clang --version
clang version 3.8.0 (http://llvm.org/git/clang.git 68170291648f0112957a8b3d6912a1a1fed81965) (http://llvm.org/git/llvm.git 92ca4a0cd38e8f17e62ecf6e93a44c8ecf098b12)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
PS: 我不想改成C++因为我正在做操作系统书(UNIX C环境)
错误表明 linker 无法找到符号 Pthread_create。这是 pthread_create 还是 Pthread_create?您还需要 link 带有“-lpthread”的库。
我正在尝试用 Pthread_create
创建一个 pthread
:
#include <pthread.h>
void *worker(void *arg) {
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t p1, p2;
Pthread_create(&p1, NULL, worker, NULL);
Pthread_create(&p2, NULL, worker, NULL);
return 0;
}
clang -Wall -std=c11 -pthread thread.c -o thread
体系结构的未定义符号 x86_64:"_Pthread_create"
:
thread.c:13:2: warning: implicit declaration of function 'Pthread_create' is
invalid in C99 [-Wimplicit-function-declaration]
Pthread_create(&p1, NULL, worker, NULL);
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_Pthread_create", referenced from:
_main in thread-3223a1.o
ld: symbol(s) not found for architecture x86_64
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
改成-std=c99
我的代码有什么问题?
clang --version
clang version 3.8.0 (http://llvm.org/git/clang.git 68170291648f0112957a8b3d6912a1a1fed81965) (http://llvm.org/git/llvm.git 92ca4a0cd38e8f17e62ecf6e93a44c8ecf098b12)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
PS: 我不想改成C++因为我正在做操作系统书(UNIX C环境)
错误表明 linker 无法找到符号 Pthread_create。这是 pthread_create 还是 Pthread_create?您还需要 link 带有“-lpthread”的库。