cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
stuartten
Observer
Observer
1,800 Views
Registered: ‎11-08-2013

OpenAMP in C++ Project Doesn't Build in Vitis2020.1

I am trying to incorporate OpenAMP into my R5 (core 0) C++ project on the ZCU104 board using Vitis 2020.1. However, when I build the project I get a bunch of errors in the file 'atomic' complaining about a 'template with C linkage'. Clearly this has to do with the extern "C" directives sprinkled throughout the OpenAMP and Metal libraries. I have successfully run the OpenAMP echo test so I know the libraries work, they just don't like to be compiled in a C++ environment.

Unfortunately, my project revolves around a large legacy C++ codebase so compiling the project in a C environment is not an option. I've even tried setting just the OpenAMP .C files to use the GCC compiler while the other .CPP files in the project use the G++ compiler. Sadly, Vitis 2020.1 ignores this File->Properties->C/C++ General->Language Mappings setting and always uses the G++ compiler for all files in the project.

There are several posts on this topic, but no definitive answer. Has anyone conquered this one?

Thanks.

11 Replies
jovitac
Moderator
Moderator
1,777 Views
Registered: ‎05-10-2017

Sorry for the issues you are facing. I suspect this is a bug.

Could you please provide steps to reproduce this issue? I can file this as a bug internally and keep you posted on the solution we receive from the dev team.

-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
stuartten
Observer
Observer
1,771 Views
Registered: ‎11-08-2013

Hi Jovitac,

The steps to reproduce the problem couldn't be simpler.

  1. Any ZCU104 compatible platform project will do. Ensure OpenAMP and LibMetal are included in the BSP.
  2. Just for reference, create an application project using the OpenAMP echo-test template to establish the required source files.
  3. Create another application project using the Empty Application (C) template.
  4. Copy all source files from OpenAMP echo-test project to C project. Build project - no errors.
  5. Create another application project using the Empty Application (C++) template.
  6. Copy all source files from OpenAMP echo-test project to C++ project. Build project - many errors.

Is it really the case that no one has used OpenAMP & Metal libraries in a C++ environment?

Please let me know if there is a short term workaround for this. Thanks.

0 Kudos
jovitac
Moderator
Moderator
1,769 Views
Registered: ‎05-10-2017

Yes, we usually don't have many customers using C++ environment so this must have not been caught.

Thank you for the steps. Will circle back after speaking with the dev team

-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
stuartten
Observer
Observer
1,678 Views
Registered: ‎11-08-2013

Jovitac,

Do you have any idea how long it might take for a solution or workaround? We cannot proceed with our development without one or the other. If it's going to be a substantial amount of time, we may have to go with an undesirable, interim solution - a dedicated C app running on R5 core 1 (currently not used) which acts as an OpenAMP go-between for R5 core 0 and APU. R5 cores 0 and 1 would communicate through a simple shared memory scheme, not OpenAMP.

Thanks.

0 Kudos
harahika
Participant
Participant
1,643 Views
Registered: ‎10-17-2019

Hi,

Could it be related to incompatible atomics between the languages? https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932

Just throwing it out there if you haven't bumped into this one. Haven't played around with atomics myself so can't say much further.

BR,
Harri
0 Kudos
jovitac
Moderator
Moderator
1,544 Views
Registered: ‎05-10-2017

Update on this.

I created a CR for this. It turns out that OpenAMP does not fully support C++ applications. At this point this is not a bug but more of a new feature or enhancement that will need to be worked on. I will update once I learn more.

 

-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
aravindb
Moderator
Moderator
1,519 Views
Registered: ‎02-07-2018

HI @stuartten 

Can you please follow steps provided in this AR:https://www.xilinx.com/support/answers/72561.html

 

Thanks & regards

Aravind

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
---------------------------------------------------------------------------------------------

0 Kudos
stuartten
Observer
Observer
1,498 Views
Registered: ‎11-08-2013

Hi @aravindb,

I've seen the answer record you referenced, but isn't that for a PetaLinux build? I'm trying to build OpenAMP for bare metal. Is there a similar patch for bare metal?

Until Xilinx can provide a solution or workaround, I've devised my own. I built OpenAMP as a standalone C library (therefore no errors) and then linked to it from my C++ project using extern "C" declarations. This arrangement seems to be working fine so we're past the crisis for now.

Thanks,
Stuart

nenghan
Participant
Participant
1,326 Views
Registered: ‎06-07-2018

Hi, I'm facing the same issue too. Getting the R5 to work on CPP too as I'm using the Eigen c++ lib for computation. 

Can you share how you accomplish what you mentioned?

You still compiled the R5 bsp using C. As for the R5 application, did you use c application or cpp application in vitis? How to you link in the open amp using extern c? If u could share. Thanks

 

 

0 Kudos
stuartten
Observer
Observer
1,302 Views
Registered: ‎11-08-2013

Hi Nenghan,
In Vitis I have my platform project which defines my BSP and target processor (R5, core 0). I also have my application project which I created using the empty C++ template. The third step was to create a new C (not C++) library project in Vitis based on one of the OpenAMP demos (I used OpenAMPEchoTest). I modified the OpenAMPEchoTest source files as required to meet the needs of my simple OpenAMP driver. Then, back in my application project I created an OpenAMP.h file containing the API to my OpenAMP library:
extern "C"
{

extern bool OpenAMPSend(char *msgPtr, uint32_t msgLen);
...

}

In the linker settings of my application project, I added my OpenAMP.lib as a library.

That's it. Everything worked fine from there. I hope this helps.

0 Kudos
694 Views
Registered: ‎05-09-2019

Still having this issue in January 2021.  Not a satisfying workaround, but it got the job done.

 

// I fixed c++ libmetal atomics problem with hacks like this:

#include <atomic>
using std::atomic_int;
using std::atomic_uchar;
using std::atomic_uint;
using std::atomic_ushort;
using std::atomic_ulong;
using std::atomic_ullong;
using std::memory_order;
using std::memory_order_acquire;
using std::memory_order_seq_cst;
#include "xrfdc.h" // The offending file in my BSP

#include <iostream>

int main(){
std::cout << "Hello World" << std::endl;
}

0 Kudos