1

我有一个简单的 c 应用程序

Ctest.c 文件

#include <stdio.h>
#include "new.h"
#include "new.c"

int main()
{
    switching();
    return 0;
}

我有那些 new.c 和 new.h 文件。

new.h 文件为

void switching();

我的 new.c 文件为

void switching(){
    char grade ='B';
    switch(grade){
        case 'A':
            printf("Excellent\n");
            break;
        case 'B':
            printf("Super\n");
            break;
        case 'C':
            printf("Well done\n");
            break;
        case 'D':
            printf("You passed\n");
            break;
        case 'F':
            printf("Better try again");
            break;
        default:
            printf("invalid grade");
            break;
    }

    printf("your grade is %c \n",grade);

    }

当我尝试在我的嵌入式 linux 工具中使用构建命令来编译和生成二进制文件时,构建失败,这是我为 rootfs 上的应用程序更改的 make 文件。

为应用程序 Ctest 制作文件:

APP  = Ctest


# Add any other object files to this list below

APP_OBJS = Ctest.o
APP_OBJS += new.o


all: build

build: $(APP)

$(APP): $(APP_OBJS)
    $(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)

这是我在编译时的错误日志

    DEBUG: Executing shell function do_compile
NOTE: make -j 4
ERROR: oe_runmake failed
aarch64-xilinx-linux-gcc  --sysroot=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64 -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/work/aarch64-xilinx-linux/Ctest/1.0-r0=/usr/src/debug/Ctest/1.0-r0 -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64=   -c -o Ctest.o Ctest.c
aarch64-xilinx-linux-gcc  --sysroot=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64 -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/work/aarch64-xilinx-linux/Ctest/1.0-r0=/usr/src/debug/Ctest/1.0-r0 -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-map=/home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/sysroots/plnx_aarch64=   -c -o new.o new.c
new.c: In function 'switching':
new.c:5:13: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
             printf("Excellent\n");
             ^~~~~~
new.c:5:13: warning: incompatible implicit declaration of built-in function 'printf'
new.c:5:13: note: include '<stdio.h>' or provide a declaration of 'printf'
new.c:24:5: warning: incompatible implicit declaration of built-in function 'printf'
     printf("your grade is %c \n",grade);
     ^~~~~~
new.c:24:5: note: include '<stdio.h>' or provide a declaration of 'printf'
Ctest.c:33:17: fatal error: new.h: No such file or directory
 #include "new.h"
                 ^
compilation terminated.
make: *** [<builtin>: Ctest.o] Error 1
make: *** Waiting for unfinished jobs....
ERROR: Function failed: do_compile (log file is located at /home/janani/projects/peta2017.1-zcu102/zcu102/petlnx_zcu102/build/tmp/work/aarch64-xilinx-linux/Ctest/1.0-r0/temp/log.do_compile.19737)

我知道我需要在构建应用程序的 make 文件或 bitbake 文件中进行更改,即 Ctest.bb 文件如果是这样,有哪些更改?我正在使用 petalinux 2017.1

应用程序的 bitbake 文件是

#
# This file is the Ctest recipe.
#

SUMMARY = "Simple Ctest application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://Ctest.c \
       file://new.c \
       file://Makefile \
      "

S = "${WORKDIR}"

do_compile() {
         oe_runmake
}

do_install() {
         install -d ${D}${bindir}
         install -m 0755 Ctest ${D}${bindir}
         install -m 0755 new ${D}${bindir}
}

如何将 new.h 文件放入 make 文件中,还是需要更改 bitbake 文件?

4

1 回答 1

3

您的Ctest.c文件包含new.c,因此您根本不应该尝试构建new.o。删除线

APP_OBJS += new.o

install -m 0755 new ${D}${bindir}

您没有在 SRC_URI 中提供 new.h 文件。将其更改为

SRC_URI = "file://Ctest.c \
   file://new.c \
   file://new.h \
   file://Makefile \
"
于 2017-07-24T16:09:45.440 回答