gpt4 book ai didi

c - 我的 C 程序出现问题 : compilation error occurs

转载 作者:行者123 更新时间:2023-11-30 16:13:18 24 4
gpt4 key购买 nike

我正在使用 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 时得到的结果:

In file included from /home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/common.hpp:28:0, from /home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa.hpp:27, from last1.c:4:

/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/types.hpp:32:1: error: unknown type name ‘namespace’ namespace mraa ^~~~~~~~~

/home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/types.hpp:33:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token { ^

In file included from /home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa.hpp:27:0, from last1.c:4: /home/gaston/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/mraa/usr/include/mraa/common.hpp:29:10: fatal error: string: No such file or directory #include ^~~~~~~~

compilation terminated. Makefile:8: recipe for target 'last1.o' failed make: *** [last1.o] Error 1

最佳答案

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

关于c - 我的 C 程序出现问题 : compilation error occurs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58078145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com