jenny jenny - 3 years ago 152
Bash Question

How to build when multiple source files in rootfs in embedded linux?

I have a simple c application

Ctest.c file

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

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


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

new.h file as

void switching();


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);

}


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.

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)


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

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?

Answer Source

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

and

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

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 \
"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download