06-25-2020 08:47 AM - edited 06-29-2020 04:42 AM
I have written an application in C that contains about 21 .c files and a few more .h files. I've now been asked to integrate a .cpp file into the application.
From the research I've found, I can either develop a C++ application and reference C code, as the main method should be compiled with as C++. I've also found references to having building a C application, but referencing the C++. I would prefer this method, C application calling the C++ object. As I would prefer not to have to update any of the C code I've already written.
My question here is related to considerations related to building the application as a petalinux recipe. I'm using petalinux-build to build the application, so I'll be modifying the recipe Makefile and .bb file. What do I need to consider when doing this. Is it possible to mix within petalinux? is one of the two direction preferred/required?
UPDATE:
I've written a very simple test application. which contains. the following files.
Here are the files that I'm currently using.
cppObject.cpp
cppObject.h
cppFunctions.cpp
cppFunctions.h
test.c
I ended up modifying the .bb file to this
#
# This file is the test recipe.
#
SUMMARY = "Simple test application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://test.c \
file://Makefile \
file://cppObject.cpp \
file://cppFunctions.cpp \
file://cppObject.h \
file://cppFunctions.cpp \
"
S = "${WORKDIR}"
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}${bindir}
install -m 0755 test ${D}${bindir}
}
and the makefile to this
APP = test
# Add any other object files to this list below
# APP_OBJS = test.o cppFunctions.o cppObject.o
APP_OBJS = cppObject.o cppFunctions.o test.o
all: build
build: $(APP)
$(APP): $(APP_OBJS)
$(CXX) -o $@ $(APP_OBJS) $(LDFLAGS) $(LDLIBS)
clean:
rm -f $(APP) *.o
The application compiles and runs just fine if I use the commandline to build it.
g++ cppObject.cpp cppFunctions.cpp test.c -o test
The error I get when I run petalinux build says it doesn't see the cppFunctions.h file. "No such file or directory" All files are in the same directory.
Any insight?
06-29-2020 01:41 PM
It might have something to do with the "exter C" being misspelled in cppFunctions.h. Since the error is a link error and cppFunctions.o is on the linker command line, that points to a disagreement in whether the linkage is C or C++ for the functions in that file.
It also looks like the PetaLinux recipe wasn't cleaned before building - you can do a "petalinux-build -c test -x distclean" to fully clean it.
06-25-2020 11:50 AM
I've attempted to reorder the files in the .bb file and the Makefile, thinking it may be an ordering issue, but I've had no success.
06-26-2020 01:19 PM
It looks like you have cppFunctions.ccp listed in the source files of your recipe twice, and cppFunctions.h is missing. I think bitbake doesn't copy the source over due to that.
06-26-2020 02:14 PM - edited 06-26-2020 02:23 PM
Hi thanks for reaching out to me. I noticed that I did make a mistake on the .bb file as well. I ended up changing the .bb file and I'm no longer getting the error related to not finding the cppFunctions.h file. However, now its giving me a
undefined reference to <a function>
The function that its calling is the first function call to the cpp object. I've commented it out to see if calling the other function would have any affect, but no still throws the same error.
Not sure what else to do. as I mentioned it builds and runs 100% if I just build it as g++ from the make file, rather than building though petalinux. Is there an ordering I need to be aware of.
maybe seeing the actual files will help. I've attached a zip folder to what I currently have for my sample application, makefile, and bitbake file. I'm also attaching a log of what I'm seeing when i run the build.
if you update the make file to the following.
```
06-29-2020 01:41 PM
It might have something to do with the "exter C" being misspelled in cppFunctions.h. Since the error is a link error and cppFunctions.o is on the linker command line, that points to a disagreement in whether the linkage is C or C++ for the functions in that file.
It also looks like the PetaLinux recipe wasn't cleaned before building - you can do a "petalinux-build -c test -x distclean" to fully clean it.
06-29-2020 03:40 PM