c - 我的 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;
}
这是 Makefile :
#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,来自 last1.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' 或 '<strong>attribute' 在 '{' 标记 { ^
在 /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 ^ ~~~~~~~
编译终止。Makefile:8:目标“last1.o”的配方失败 make:*** [last1.o] 错误 1
解决方案
您正在编译C
用C++
编译器编写的代码。
只需将.c
文件更改为文件,然后使用而不是在 Unix 系统上进行.cpp
编译。g++
gcc
推荐阅读
- javascript - Flappy Bird 代码不起作用 - JavaScript
- java - 两个服务在android中不能一起工作
- c++ - 导出到 HTML5 FWebSocketsModule 不起作用
- vue.js - 将 vue 项目构建为“库”后导入路径错误
- c# - 从托管服务中调用 IServiceProvider.CreateScope 是一种反模式吗?
- join - flink 如何组合流和乘法映射
- haskell - 带有数据的实例函子
- maven - 在同一连接器的流程中使用自定义连接器的组件
- facebook-graph-api - Facebook Marketing API:广告未获批准时获取受影响的图片
- http - Dart - 如何建立一个 http 流?