cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
513 Views
Registered: ‎04-06-2020

Petaliux recipe-app build that contains both C and C++ files

Jump to solution

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?

 

Tags (4)
0 Kudos
Reply
1 Solution

Accepted Solutions
Highlighted
Contributor
Contributor
301 Views
Registered: ‎10-08-2018

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.


Nathan Sullivan - Senior Embedded Software Engineer - www.designlinxhs.com

View solution in original post

5 Replies
Highlighted
Observer
Observer
483 Views
Registered: ‎04-06-2020

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. 

0 Kudos
Reply
Highlighted
Contributor
Contributor
408 Views
Registered: ‎10-08-2018

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.


Nathan Sullivan - Senior Embedded Software Engineer - www.designlinxhs.com
Observer
Observer
401 Views
Registered: ‎04-06-2020

@nsullivan 

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. 

```

# APP_OBJS = test.o cppFunctions.o cppObject.o 
APP_OBJS = cppObject.cpp cppFunctions.cpp test.c
```
and run make instead of building through petalinux, it runs just fine.
0 Kudos
Reply
Highlighted
Contributor
Contributor
302 Views
Registered: ‎10-08-2018

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.


Nathan Sullivan - Senior Embedded Software Engineer - www.designlinxhs.com

View solution in original post

Highlighted
Observer
Observer
288 Views
Registered: ‎04-06-2020
you have to be kidding me............I'm so sorry, that is entirely my stupidity. Thank you for this. It was a huge help. But I shouldn't have event gotten to the point of posting. Again sorry.
0 Kudos
Reply