簡體   English   中英

我的 C 程序出現問題:發生編譯錯誤

[英]Issue with my C program : compilation error occurs

我正在使用 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' 或 ' 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”的配方失敗制作:*** [last1.o] 錯誤 1

您正在使用C++編譯器編譯用C編寫的代碼。
Just change your .c files to .cpp files, and compile using g++ rather than gcc if you are on Unix systems.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM