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?
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 \
"
Related
I am trying to cross compile espeak-ng for target=arm-linux-gnueabihf
The sudo make install step gives the following error :
~:~/Downloads/Dependencies/espeak-ng-master$ sudo make install
[sudo] password for abc:
ESPEAK_DATA_PATH=../Downloads/Dependencies/espeak-ng-master src/espeak-ng --compile-intonations && \
ESPEAK_DATA_PATH=../Downloads/Dependencies/espeak-ng-master src/espeak-ng --compile-phonemes && \
touch phsource/phonemes.stamp
src/espeak-ng: line 117: ../Downloads/Dependencies/espeak-ng-master/src/.libs/espeak-ng: cannot execute binary file: Exec format error
src/espeak-ng: line 117: ../Downloads/Dependencies/espeak-ng-master/src/.libs/espeak-ng: Success
Makefile:2590: recipe for target 'phsource/phonemes.stamp' failed
make: *** [phsource/phonemes.stamp] Error 126
I have cross compiled using the following :
./configure CC=arm-linux-gnueabihf-gcc -prefix /opt/myproject-sysroot/usr --build=$MACHTYPE --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
make -B src/speak-ng src/espeak-ng
Configure output
Configuration for eSpeak NG complete.
Source code location: .
C99 Compiler: arm-linux-gnueabihf-gcc
C99 Compiler flags: -Wunused-parameter -Wunused -Wuninitialized -Wreturn-type -Wmissing-prototypes -Wimplicit -g -O2 -std=c99
Sonic: no
PCAudioLib: no
gradle (Android): gradle
ndk-build (Android):
Klatt: yes
MBROLA: yes
Async: yes
Extended Dictionaries:
Russian: no
Chinese (Mandarin): no
Chinese (Cantonese): no
~/Downloads/Dependencies/ESPEAK/espeak-ng-master$ sudo make -B src/speak-ng src/espeak-ng
Output for make command:
---------------
-----------
CC src/libespeak-ng/src_libespeak_ng_la-tr_languages.lo
CC src/libespeak-ng/src_libespeak_ng_la-voices.lo
CC src/libespeak-ng/src_libespeak_ng_la-wavegen.lo
src/libespeak-ng/wavegen.c: In function ‘WavegenFill’:
src/libespeak-ng/wavegen.c:1400:17: warning: variable ‘p_start’ set but not used [-Wunused-but-set-variable]
unsigned char *p_start;
^~~~~~~
CC src/libespeak-ng/src_libespeak_ng_la-klatt.lo
CC src/libespeak-ng/src_libespeak_ng_la-mbrowrap.lo
CC src/libespeak-ng/src_libespeak_ng_la-espeak_command.lo
CC src/libespeak-ng/src_libespeak_ng_la-event.lo
CC src/libespeak-ng/src_libespeak_ng_la-fifo.lo
CCLD src/libespeak-ng.la
arm-linux-gnueabihf-ar: `u' modifier ignored since `D' is the default (see `U')
CCLD src/speak-ng
CC src/espeak-ng.o
src/espeak-ng.c: In function ‘main’:
src/espeak-ng.c:744:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(p_text, 1, filesize, f_text);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CCLD src/espeak-ng
Make install output
~/Downloads/Dependencies/ESPEAK/espeak-ng-master$ sudo make LIBDIR=/opt/myproject-sysroot/usr install
ESPEAK_DATA_PATH=../Downloads/Dependencies/ESPEAK/espeak-ng-master src/espeak-ng --compile-intonations && \
ESPEAK_DATA_PATH=../Downloads/Dependencies/ESPEAK/espeak-ng-master src/espeak-ng --compile-phonemes && \
touch phsource/phonemes.stamp
src/espeak-ng: line 117: ../Downloads/Dependencies/ESPEAK/espeak-ng-master/src/.libs/espeak-ng: cannot execute binary file: Exec format error
src/espeak-ng: line 117: ../Downloads/Dependencies/ESPEAK/espeak-ng-master/src/.libs/espeak-ng: Success
Makefile:2590: recipe for target 'phsource/phonemes.stamp' failed
make: *** [phsource/phonemes.stamp] Error 126
the Opencv 2.4.9: VideoCapture cann't open the MJPG-streamer:
VideoCapture cap;
cap.open("http://127.0.0.1:8080/?action=stream&type=.mjpg");
if (!cap.isOpened()) // if not success, exit program
{
cout << "Cannot open the video cam" << endl;
return -1;
}
I can see the video use gst-launch. and I have searched a lot,like this and tried the fifo like this,but still cann't open it.
then I want to debug into opencv,compile opencv with CMAKE_BUILD_TYPE=DEBUG, but my GDB just cann't step into the open function.any idea?
my makefile:
OpencvDebugLibDir=/home/ry/lib
CFLAGS = -g -I$(OpencvDebugLibDir)/include/opencv -I$(OpencvDebugLibDir)
LIBS = $(OpencvDebugLibDir)/lib/*.so
target : main.cpp
g++ $(CFLAGS) $(LIBS) -o $# $<
by the way, I am in opensue13.1, with the same code,I can open the video in win 7.
thank you.
Update
now I can step into some function like:imshow,waitKey, but I can not step into others like:imread,namedWindow,it shows:
29 image = cv::imread(name);
(gdb) s
std::allocator<char>::allocator (this=0x7fffffffdc7f)
at /usr/src/debug/gcc-4.8.1-20130909/obj-x86_64-suse-linux/x86_64-suse-linux/libstdc++-v3/include/bits/allocator.h:113
113 allocator() throw() { }
test4.cpp:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread( "LinuxLogo.jpg", 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
my makefile:
OpencvDebugLibDir=/home/ry/lib
CFLAGS=-g -I$(OpencvDebugLibDir)/include/opencv -I$(OpencvDebugLibDir)
LIBS=$(OpencvDebugLibDir)/lib
test4:test4.cpp
g++ $(CFLAGS) -o $# $< -L$(LIBS) -lopencv_highgui -lopencv_core -Wl,-rpath=/home/ry/lib/lib
run gdb:
gdb test4 -d /home/ry/learn/opencv/install/OpenCV/opencv-2.4.9/modules/core/src -d /home/ry/learn/opencv/install/OpenCV/opencv-2.4.9/modules/highgui/src
opencv videocapture can't open MJPEG stream,because I don't compile opencv with FFMPEG support.
detail:
when cmake the opencv:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=ON -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_OPENCL=ON -D WITH_CUDA=ON -D WITH_GTK=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_JPEG=ON -D BUILD_PNG=ON -D BUILD_JASPER=ON -D BUILD_ZLIB=ON -D WITH_JPEG=ON -D WITH_PNG=ON -D WITH_JASPER=ON -D WITH_ZLIB=ON -D WITH_OPENEXR=OFF ..
you get something like:
FFMPEG: NO
-- codec: NO
-- format: NO
-- util: NO
-- swscale: NO
-- gentoo-style: NO
so the cmake don't find the FFMPEG. I should install libffmpeg-devel in my machine(Opensuse 13.1),then the pkg-config can find FFMPEG,you can check with this:
pkg-config --list-all | grep libavcodec
then run the above cmake command again, I get:
FFMPEG: YES
-- codec: YES (ver 55.69.100)
-- format: YES (ver 55.48.100)
-- util: YES (ver 52.92.100)
-- swscale: YES (ver 2.6.100)
-- gentoo-style: YES
make,and I get the opencv videocapture able to open MJPG_Streamer.
PS:to find the reason,I compile a debug version opencv,and step into the VideoCapture's open function,and in the construction function of icvInitFFMPEG() in " opencv-2.4.9/modules/highgui/src/cap.cpp ":
#elif defined HAVE_FFMPEG
icvCreateFileCapture_FFMPEG_p = (CvCreateFileCapture_Plugin)cvCreateFileCapture_FFMPEG;
icvReleaseCapture_FFMPEG_p = (CvReleaseCapture_Plugin)cvReleaseCapture_FFMPEG;
icvGrabFrame_FFMPEG_p = (CvGrabFrame_Plugin)cvGrabFrame_FFMPEG;
icvRetrieveFrame_FFMPEG_p = (CvRetrieveFrame_Plugin)cvRetrieveFrame_FFMPEG;
icvSetCaptureProperty_FFMPEG_p = (CvSetCaptureProperty_Plugin)cvSetCaptureProperty_FFMPEG;
icvGetCaptureProperty_FFMPEG_p = (CvGetCaptureProperty_Plugin)cvGetCaptureProperty_FFMPEG;
icvCreateVideoWriter_FFMPEG_p = (CvCreateVideoWriter_Plugin)cvCreateVideoWriter_FFMPEG;
icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG;
icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG;
#endif
it just step over these code,so I know because I don't have the HAVE_FFMPEG defined in compiling process.
I am using latest poky-am335x to build simple helloworld application. With some workaround I can able to compile the application. I am doing lot of trails to install binaries but build is throwing error.
error log :
DEBUG: SITE files ['endian-little', 'bit-32', 'arm-common', 'common-linux', 'common-glibc', 'arm-linux', 'arm-linux-gnueabi', 'common']
DEBUG: Executing shell function do_install
NOTE: make -j 4 DESTDIR=/home/pis1kor/workspace/poky-am335x/build/tmp/work/armv7a-vfp-neon-poky-linux-gnueabi/helloworld-1.0-r0/image install
make: *** No rule to make target `install'. Stop.
ERROR: oe_runmake failed
ERROR: Function failed: do_install (see /home/pis1kor/workspace/poky-am335x/build/tmp/work/armv7a-vfp-neon-poky-linux-gnueabi/helloworld-1.0-r0/temp/log.do_install.29583 for further information)
Bitbake file :
DESCRIPTION = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "r0"
SRC_URI = "file://helloworld.tar"
do_compile () {
make -C ${WORKDIR}/helloworld all
}
do_install() {
oe_runmake install DESTDIR=${D}
}
#do_install() {
# oe_runmake install DESTDIR=${D}
# make -C ${WORKDIR}/helloworld/ install
# oe_runmake 'DESTDIR=${D}' install
# cp -f ${WORKDIR}/helloworld/helloworld ${WORKDIR}/image
# oe_runmake install ${WORKDIR}/helloworld
# make -C ${WORKDIR}/helloworld install
# install -d ${D}${bindir}/ ZZ
#}
inherit autotools gettext
Makefile :
IDIR = ./include
CC = arm-arago-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon -mtune=cortex-a8 --sysroot=/home/pis1kor/workspace/poky-am335x/build/tmp/sysroots/am335x-evm
CFLAGS = -I$(IDIR)
LIBS = -lm
FILES = ./src/helloworld.c
OUT_EXE = helloworld
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
all: $(FILES)
$(CC) -o $(OUT_EXE) $(FILES) $(CFLAGS) $(LIBS)
install:
$(INSTALL_DATA) -C helloworld ../image
# sudo cp ./helloworld ../image/
clean:
rm -f *.o helloworld
The commented lines are kept like that because just to mansion all the trails I tried with.
The basic differences are the below.
S = "${WORKDIR}/helloworld/"
EXTRA_OEMAKE = 'all -C ${S}'
"EXTRA_OEMAKE" is the key macro which I didn't used before.
I have changed the bitbake file helloworld.bb file like below.
DESCRIPTION = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "r0"
S = "${WORKDIR}/helloworld/"
EXTRA_OEMAKE = 'all -C ${S}'
SRC_URI = "file://helloworld.tar"
inherit autotools gettext
I made userdef.c for adding some function otsu_Threshold and onBinarOtzu.
The function library header file is pxa_lib.h and I typed function like this
void otzu_Threshold(unsigned char* orgImg, unsigned char* outImg, int height, int width);
void onBinarOtzu(unsigned char* m_InImg);
In camera.c that is in Folder 'demo', I typed
'#include < pxa_lib.h >
....
....
onBinarOtzu(vidbuf->ycbcr.y);
MakeFile
CC=/usr/local/arm-linux-4.1.1/bin/arm-linux-gcc
CFLAGS+= -mcpu=iwmmxt -mtune=iwmmxt -mabi=aapcs-linux \
-Iinclude/ -DDEBUG_BUILD
LFLAGS+=-Llib/ -lpxadev
.PHONY: all compile install-host install-target clean clean-local \
uninstall-host uninstall-target
all: compile install-host install-target
compile: lib/libpxadev.so bin/camera
lib/libpxadev.so: driver/camera.o driver/overlay2.o driver/userdef.o
$(CC) $(CFLAGS) -shared -W1,-soname,libpxadev.so -o lib/libpxadev.so $^
bin/camera: demo/camera.c
$(CC) $(CFLAGS) $(LFLAGS) -o $# $^
install-host:
install-target:
clean: clean-local uninstall-host uninstall-target
clean-local:
-rm -f lib/* driver/*.o
-rm -f bin/*
uninstall-host:
-rm -f $(PXA_HOST_LIB_DIR)/libpxadev.so
uninstall-target:
$(SUDO) rm -f $(PXA_TARGET_BIN_DIR)/camera
$(SUDO) rm -f $(PXA_TARGET_LIB_DIR)/libpxadev.so
I made binary file and transmitted in robot by minicom,zmodem.
But, error had occured.
[root#WENDERS root]# [root#WENDERS root]# ./camera
PXA_CAMERA:choose MT.... sensor
PXA_CAMERA:choose MT.... sensor
camera_config : streamparm.type = 1
count = 3
width=320, height=240
./camera: symbol lookup error: ./camera: undefined symbol: onBinarOtzu
What sould I do...
ps. I'm sorry. I can't English well...
It looks like you linked to shared libraries while compiling, but they aren't loaded on the target.
You'll have to add the libraries somewhere Linux can find them, perhaps in /usr/lib or /lib, or somewhere specified by the $LD_LIBRARY_PATH variable. Exactly how you do this is dependent on the environment you have set up.
I'm having trouble compiling wmii v3.9.2 on Fedora 15; Here's the interesting part (things break down at the linking stage):
% bmake -de
MAKE all libbio/
MAKE all libfmt/
MAKE all libregexp/
MAKE all libutf/
MAKE all libixp/
MAKE all doc/
MAKE all man/
MAKE all cmd/
MAKE all cmd/wmii/
MAKE all cmd/menu/
LD cmd/wmii9menu.out
/usr/bin/ld: wmii/xext.o: undefined reference to symbol 'XRenderFindVisualFormat'
/usr/bin/ld: note: 'XRenderFindVisualFormat' is defined in DSO /usr/lib64/libXrender.so.1 so try adding it to the linker command line
/usr/lib64/libXrender.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
*** Failed target: wmii9menu.out
*** Failed command: ../util/link "cc" "$(pkg-config --libs 2>/dev/null) -g -L../lib -L/usr/lib64 ../lib/libregexp9.a ../lib/libbio.a ../lib/libfmt.a ../lib/libutf.a -L../lib -L/usr/lib64 ../lib/libregexp9.a ../lib/libbio.a ../lib/libfmt.a ../lib/libutf.a" wmii9menu.out wmii9menu.o clientutil.o wmii/x11.o wmii/xext.o wmii/geom.o wmii/map.o util.o ../lib/libixp.a $(pkg-config --libs xft xrandr xinerama) -lXext
*** Error code 1
Stop.
bmake: stopped in /srv/redhat/BUILD/wmii+ixp-3.9.2/cmd
*** Failed target: dall
*** Failed command: dirs="libbio libfmt libregexp libutf libixp doc man cmd libwmii_hack rc alternative_wmiircs"; set -e; targ=dall; targ=${targ#d}; for i in $dirs; do export WMII_HGVERSION=""; export BASE=$i/; if [ ! -d $i ]; then echo Skipping nonexistent directory: $i 1>&2; else echo MAKE $targ $BASE; (cd $i && bmake $targ) || exit ; fi; done
*** Error code 1
Stop.
bmake: stopped in /srv/redhat/BUILD/wmii+ixp-3.9.2
Finally, in config.mk, I have the following settings:
...
INCLUDES = -I. -I$(ROOT)/include -I$(INCLUDE) -I/usr/include
LIBS = -L$(ROOT)/lib -L/usr/lib64
...
LDFLAGS += -g $(LIBS)
SOLDFLAGS += $(LDFLAGS)
SHARED = -shared -Wl,-soname=$(SONAME)
STATIC = -static
...
With a little more manual resolution, the statement generating the error is essentially as follows:
gcc \
-o wmii9menu.out\
-L../lib -L/usr/lib $(pkg-config --libs xft xrandr xinerama xext)\
../lib/libregexp9.a ../lib/libbio.a ../lib/libfmt.a\
../lib/libutf.a ../lib/libixp.a\
wmii9menu.o clientutil.o util.o\
wmii/x11.o wmii/xext.o wmii/geom.o wmii/map.o
Here, the pkg-config resolves to the following, which by itself is perfectly correct:
-lXft -lXrandr -lXinerama -lXext
And the solution is as follows:
--- wmii+ixp-3.9.2/config.mk 2011-06-03 14:03:22.950163074 +1000
+++ wmii+ixp-3.9.2/config.mk 2011-06-03 14:03:16.086129011 +1000
## -32 +32 ##
-X11PACKAGES = xft
+X11PACKAGES = xft xext xrandr xrender xinerama