打印
[嵌入式Linux]

为什么这个c++的代码死活编译不过去

[复制链接]
1010|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
grf9527|  楼主 | 2015-11-17 10:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

以下是我的代码

#include<iostream>
using namespace std;

static pthread_mutex_t testlock;
pthread_t test_thread;

void *test(void*)
{
  pthread_mutex_lock(&testlock);
  printf("thread Test() \n");
  pthread_mutex_unlock(&testlock);
}

int main()
{
  pthread_mutex_init(&testlock, NULL);
  pthread_mutex_lock(&testlock);

  printf("Main lock \n");

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

  sleep(1);

  pthread_join(test_thread,NULL);
  pthread_mutex_destroy(&testlock);
  return 0;
}


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

粉丝