2017-07-24 66 views
0

我有一個簡單的C程序如何在嵌入式linux的rootfs中創建多個源文件?

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

make文件:

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 [email protected] $(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的?

+0

編譯是否發生在源以外的目錄中?如果是這樣,'CFLAGS + = - I/path/to/where/source /' – Fox

+0

'.c'文件不包含在內,而是單獨編譯。請正確使用基礎知識;一本C書會幫助很多。 – Olaf

回答

0

您的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 \ 
" 
+0

你正在推薦完全錯誤的東西。 '.c'文件不應該包含在其他文件中。這是非常糟糕的做法。 – Olaf

+0

@Olaf我同意你的意見,這不是一個好主意。我只是在回答關於yocto的問題。我相信海報會在適當的時候推進到更好的實施。 – meuh

+0

我不明白這與yocto有什麼關係。這是錯誤的方法,就是這樣。 – Olaf

相關問題