树莓派论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1881|回复: 0
收起左侧

symbol lookup error:pthread_create

[复制链接]
发表于 2016-7-30 10:59:09 | 显示全部楼层 |阅读模式
想用树莓派做的事情:
树莓派利用视觉驱动小车找到目标物并执行相关操作;
目前情况:
1.树莓派安装的系统ubuntu mate16.04(系统还算稳定),系统中安装有opencv和wiringpi;
2.做的测试:go.c编写程序
#include <stdio.h>
#include <wiringPi.h>
#include <softPwm.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>

#define foward_left   25
#define back_left     24
#define foward_right  21
#define back_right    22
#define pwm_left      23
#define pwm_right     14//电机
#define blower        0

int RANGE=100;
int vel_left,vel_right;

void setup()
{
  int ret=0;
  pinMode(foward_left,OUTPUT);
  pinMode(back_left,OUTPUT);  
  pinMode(foward_right,OUTPUT);
  pinMode(back_right,OUTPUT);
  ret=softPwmCreate (pwm_left, 0, RANGE);
  if(ret!=0)
  {
    printf("error!\n");
  }
  ret=softPwmCreate (pwm_right, 0, RANGE);
  if(ret!=0)
  {
    printf("error!\n");
  }
  pinMode(blower,OUTPUT);
}

void advance()
{
  digitalWrite(foward_left,HIGH);
  digitalWrite(back_left,LOW);
  digitalWrite(foward_right,HIGH);
  digitalWrite(back_right,LOW);
  softPwmWrite(pwm_left,vel_left);
  softPwmWrite(pwm_right,vel_right);
}
void turn()
{
  digitalWrite(foward_left,HIGH);
  digitalWrite(back_left,LOW);
  digitalWrite(foward_right,HIGH);
  digitalWrite(back_right,LOW);
  softPwmWrite(pwm_left,vel_left);
  softPwmWrite(pwm_right,vel_right);
}

void stop()
{
  digitalWrite(foward_left,LOW);
  digitalWrite(back_left,LOW);
  digitalWrite(foward_right,LOW);
  digitalWrite(back_right,LOW);
  softPwmWrite(pwm_left,vel_left);
  softPwmWrite(pwm_right,vel_right);
}

int main()
{
  int ret=0;
  if(wiringPiSetup()==-1)
  {
    ret=-1;
    printf( "wiringPi failed\n");
  }
  setup();
  vel_left=10;
  vel_right=10;
  advance();
  return 0;
}
gcc  go.c -o go -lwiringpi -pthread
编译,运行,没问题。

但若把程序名改成go.cpp(因为后期要用到opencv,需要写成c++程序),编译成功,但运行./go时报错:symbol lookup error:pthread_create......

若用Cmakelists.txt编译,情况一样:
cmake_minimum_required(VERSION 2.8)
project(go C CXX)
SET(CMAKE_THREAD_PREFER_PTHREAD TRUE)
SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-pthread")
set(CMAKE_LINKER_FLAGS "-pthread" CACHE STRING "Linker Flags" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE)
find_package(OpenCV REQUIRED)
find_package(Threads REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS} /home/liv/wiringPi-b0a60c3/devLib )
add_executable(go go.cpp)
target_link_libraries(go ${OpenCV_LIBS} wiringPi ${CMAKE_THREAD_LIBS_INIT})
#link_libraries(pthread)


求大神指教!!!

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|树莓派论坛 ( 粤ICP备15075382号-1  

GMT+8, 2024-11-23 02:25 , Processed in 1.109375 second(s), 29 queries , Gzip On.

Powered by Shumeipai.net! X3.2

© 2001-2015 树莓派论坛安全联盟

快速回复 返回顶部 返回列表