不断收到隐式声明错误 [英] keep getting implicit declaration error

查看:208
本文介绍了不断收到隐式声明错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译时总是遇到这些错误.我修改了在arduino上运行的代码以在我的树莓派上运行.

I keep getting these errors when compiling. I modified the code that runs on an arduino to run on my raspberry pi.

test1.c: In function ‘loop’:
test1.c:24:3: warning: implicit declaration of function ‘rotateDeg’ [-Wimplicit-function-declaration]
test1.c:33:3: warning: implicit declaration of function ‘rotate’ [-Wimplicit-function-declaration]
test1.c: At top level:
test1.c:42:6: warning: conflicting types for ‘rotate’ [enabled by default]
test1.c:33:3: note: previous implicit declaration of ‘rotate’ was here
test1.c: In function ‘rotate’:
test1.c:46:3: warning: implicit declaration of function ‘abs’ [-Wimplicit-function-declaration]
test1.c: At top level:
test1.c:61:6: warning: conflicting types for ‘rotateDeg’ [enabled by default]
test1.c:24:3: note: previous implicit declaration of ‘rotateDeg’ was here
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
(.text+0x34): undefined reference to `main'
collect2: ld returned 1 exit status

这是我的源代码:

#include <wiringPi.h>
#include <stdio.h>
#include <stdio.h>

#define DIR_PIN 0
#define STEP_PIN 3

void setup() { 
  pinMode(DIR_PIN, OUTPUT); 
  pinMode(STEP_PIN, OUTPUT); 
} 

void loop(){ 

  rotateDeg(360, 1); 
  delay(1000);   
  rotateDeg(-360, .1);  //reverse
  delay(1000); 
  rotate(1600, .5); 
  delay(1000); 

  rotate(-1600, .25); //reverse
  delay(1000); 
}

void rotate(int steps, float speed){ 
  //rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
  //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
  int dir = (steps > 0)? HIGH:LOW;
  steps = abs(steps);

  digitalWrite(DIR_PIN,dir); 

  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){ 
    digitalWrite(STEP_PIN, HIGH); 
    delayMicroseconds(usDelay); 

    digitalWrite(STEP_PIN, LOW); 
    delayMicroseconds(usDelay); 
  } 
} 

void rotateDeg(float deg, float speed){ 
  //rotate a specific number of degrees (negitive for reverse movement)
  //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
  int dir = (deg > 0)? HIGH:LOW;
  digitalWrite(DIR_PIN,dir); 

  int steps = abs(deg)*(1/0.225);
  float usDelay = (1/speed) * 70;

  for(int i=0; i < steps; i++){ 
    digitalWrite(STEP_PIN, HIGH); 
    delayMicroseconds(usDelay); 

    digitalWrite(STEP_PIN, LOW); 
    delayMicroseconds(usDelay); 
  } 
}

推荐答案

当存在隐式声明的函数时,您会收到隐式声明警告.

You get an implicit declaration warning when there is an implicitly declared function.

一个隐式声明的函数是一个既没有 原型或定义,这就是为什么编译器无法验证 您想使用该功能做什么.

An implicitly declared function is a function which has neither a prototype nor a definition and that's why a compiler cannot verify that what do you want to do with the function.

如果没有可用的函数先前声明,则假定其第一个实例为隐式声明,其返回类型为int,并且对参数不作任何假设.

If no prior declaration of a function is available then its first instance is assumed to be a declaration implicitly with return type int and nothing is assumed about the parameters.

只需像下面这样声明函数rotaterotatedeg即可:

Just leave a declaration of functions rotate and rotatedeg like this :

void rotate (int , float );

void rotateDeg (float , float );

在循环中使用它之前:

void loop(){ 

  rotateDeg(360, 1); 
  ....
  ....
  rotate(1600, .5); 
  ... 
  rotate(-1600, .25); //reverse
  delay(1000); 
}

在使用任何数学函数(例如abs();)之前,请先使用#include<math.h>.

Also use #include<math.h> before using any mathematical functions like abs(); .

最重要的是,您必须让编译器了解所使用的功能.

The bottom line is , you have to make your compiler know about the functions you are using.

这篇关于不断收到隐式声明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆