【发布时间】:2015-03-12 06:36:01
【问题描述】:
在 debian linux arm-none-eabi-g++ pthread.c -o pthread -lpthread 中运行会引发以下编译错误。但是如果我运行g++ pthread.c -o pthread -lpthread 则没有编译错误。我从来没有使用过交叉编译器。我知道库中的链接存在问题。请帮我。我在互联网上搜索了很多,但没有运气。
我的pthread.c 程序:
include "pthread.h"
include "stdio.h"
include "stdlib.h"
void *worker_thread(void *arg)
{
printf("This is worker_thread()\n");
pthread_exit(NULL);
}
int main()
{
pthread_t my_thread;
int ret;
printf("In main: creating thread\n");
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
if(ret != 0)
{
printf("Error: pthread_create() failed\n");
exit(EXIT_FAILURE);
}
pthread_exit(NULL);
}
编译错误:
pthread.c: In function 'void* worker_thread(void*)':
pthread.c:8:18: error: 'pthread_exit' was not declared in this scope
pthread_exit(NULL);
^
pthread.c: In function 'int main()':
pthread.c:15:1: error: 'pthread_t' was not declared in this scope
pthread_t my_thread;
^
pthread.c:15:11: error: expected ';' before 'my_thread'
pthread_t my_thread;
^
pthread.c:18:23: error: 'my_thread' was not declared in this scope
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
^
pthread.c:18:60: error: 'pthread_create' was not declared in this scope
ret = pthread_create(&my_thread, NULL, &worker_thread, NULL);
^
pthread.c:24:21: error: 'pthread_exit' was not declared in this scope
} pthread_exit(NULL);
【问题讨论】:
-
你自己创建了一个
pthread.h文件? -
如果他这样做了,那么g++也会优先匹配
-I.中的头文件。我想问题可能出在 arm 交叉编译器附带的pthread.h上。 -
我没有创建 pthread.h。 arm-none-eabi-g++ 参考 pthread.h 文件 #1 "/usr/include/newlib/pthread.h" 1 3 # 25 "/usr/include/newlib/pthread.h" 3 # 29 "/usr /include/newlib/pthread.h" 2 3 # 427 "/usr/include/newlib/pthread.h" 3
-
是否需要重新安装arm交叉编译器?
-
@Raj:看我的回答。重新安装 arm 交叉编译器没有帮助。
标签: c++ linux c++11 debian cross-compiling