[嵌入式Linux] 为什么这个c++的代码死活编译不过去

[复制链接]
1306|3
 楼主| grf9527 发表于 2015-11-17 10:56 | 显示全部楼层 |阅读模式

以下是我的代码

  1. #include<iostream>
  2. using namespace std;

  3. static pthread_mutex_t testlock;
  4. pthread_t test_thread;

  5. void *test(void*)
  6. {
  7.   pthread_mutex_lock(&testlock);
  8.   printf("thread Test() \n");
  9.   pthread_mutex_unlock(&testlock);
  10. }

  11. int main()
  12. {
  13.   pthread_mutex_init(&testlock, NULL);
  14.   pthread_mutex_lock(&testlock);

  15.   printf("Main lock \n");

  16.   pthread_create(&test_thread, NULL, test, NULL);
  17.   sleep(1); //更加明显的观察到是否执行了创建线程的互斥锁
  18.   printf("Main unlock \n");
  19.   pthread_mutex_unlock(&testlock);

  20.   sleep(1);

  21.   pthread_join(test_thread,NULL);
  22.   pthread_mutex_destroy(&testlock);
  23.   return 0;
  24. }


g++ 编译完全可以通过
g++ -o thread main.cpp -lpthread -lstdc++

x86的机器上可以跑

然后我开始尝试使用arm的c++编译器,结果拉稀了
root/gcc/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-none-linux-gnueabi-g++ main.cpp -o gfarmcpp -lpthread -lstdc++
main.cpp:4:19: error: iostream: No such file or directory
main.cpp: In function 'int main()':
main.cpp:25: error: 'sleep' was not declared in this scope
ayb_ice 发表于 2015-11-17 11:51 | 显示全部楼层
int main(void)
john_lee 发表于 2015-11-17 11:58 | 显示全部楼层
缺头文件,工具链没有配置齐。
mini1986 发表于 2015-12-15 09:27 | 显示全部楼层
除了前两行是C++之外,别的怎么看都是C......
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

3

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部