嵌入式Linux的rootfs中的多个源文件时如何构建

嵌入式Linux的rootfs中的多个源文件时如何构建

本文介绍了嵌入式Linux的rootfs中的多个源文件时如何构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a simple c application

Ctest.c文件

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

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

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

and i have those new.c and new.h files.

new.h文件为

void switching();

和我的new.c文件为

and my new.c file as

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文件。

When i try to use build commands in my embedded linux tool for compiling and generating a binary , building is failed and here is my changed make file for the application on rootfs.

应用程序Ctest的make文件:

make file for the app 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)

这是我在编译期间的错误日志

Here is my error log during compile time

    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

i understood that i need to do changes in the make file or bitbake file that build the application ie., Ctest.bb file If so what are the changes? And I am using petalinux 2017.1

应用程序的bitbake文件是

the bitbake file of the application is

#
# 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}
}

我如何给新硬币。将文件添加到生成文件中还是需要更改位烘烤文件?

How can i give new.h file into the make file or do i need to change the bitbake file?

推荐答案

您的 Ctest。 c 文件包含 new.c ,因此您不应该尝试构建 new.o 完全没有删除行

Your Ctest.c file includes new.c so you should not be trying to build new.o at all. Remove the line

APP_OBJS += new.o

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

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

You are not providing the new.h file in your SRC_URI. Change it to

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

这篇关于嵌入式Linux的rootfs中的多个源文件时如何构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 14:15