我的 C 程序问题:发生编译错误



我正在使用Yocto项目交叉编译器来编译我的C代码。

但是由于某些原因,我有编译错误。

这是我的 C 代码:

#include <stdio.h>
#include <stdlib.h>
#include "/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa.hpp"
/* MRAA does not yet understand GPIO-A - GPIO-L       */
/* Linaro will add this                   */
/* What Mraa does understand is pin out numbers so,     */
/* pin 23 is GPIO-A and pin 25 is GPIO-C          */
#define LED 10
#define BUTTON 29
bool running = true;
bool led_state = false;
int last_touch;
void sig_handler(int signo)
{
if (signo == SIGINT)
running = false;
}
int main(int argc, char* argv[])
{
mraa::Result ret;
int touch;
mraa::Gpio* touch_gpio = new mraa::Gpio(BUTTON);
if (touch_gpio == NULL){
return mraa::ERROR_UNSPECIFIED;
}
mraa::Gpio* led_gpio = new mraa::Gpio(LED);
if (led_gpio == NULL){
return mraa::ERROR_UNSPECIFIED;
}
signal(SIGINT, sig_handler);
if ((ret = touch_gpio->dir(mraa::DIR_IN))!= mraa::SUCCESS){
return ret;
}
if ((ret = led_gpio->dir(mraa::DIR_OUT))!= mraa::SUCCESS){
return ret;
}
led_gpio->write(led_state);
while (running) {
touch = touch_gpio->read();
if (touch == 1 && last_touch == 0) {
led_state = !led_state;
ret = led_gpio->write(led_state);
usleep(100000);
}
last_touch = touch;
usleep(1);
}
delete led_gpio;
delete touch_gpio;
return ret;
}

这是生成文件:

#CC=arm-poky-linux-gnueabi-gcc -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a5 --sysroot=/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi
#CC="gcc"
all: last1.o
${CC} last1.o -o target_bin -lmraa
last1.o: last1.c
${CC} -I . -c last1.c
clean:
rm -rf *.o
rm target_bin

这就是我运行make all时得到的:

在文件中包含自/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/common.hpp:28:0, 来自/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa.hpp:27, 从最后1.c:4:

/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/types.hpp:32:1: 错误:未知类型名称"命名空间"命名空间 MRAA ^

~~~~~~~~/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/types.hpp:33:1: 错误:在"{"之前应为"="、"、";"、"ASM"或">属性" 令牌 { ^

在文件中包含自/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa.hpp:27:0, 来自 last1.c:4:/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/common.hpp:29:10: 致命错误:字符串:没有这样的文件或目录 #include ^~~~~~~~

编译终止。生成文件:8:目标"last1.o"的配方失败 制造: *** [最后1.o] 错误 1

您正在使用C++编译器编译用C编写的代码。
只需将.c文件更改为.cpp文件,并使用g++而不是gcc(如果您使用的是Unix系统(进行编译。

最新更新