Vivado HLS and the “no function body” error: Using a C++ function in plain C code

This post was written by eli on December 31, 2016
Posted Under: FPGA,Vivado

It’s quite well-known, that in order to call a function in C, which has been compiled in a C++ source file, there’s need for an extern “C” statement.

So if this appears on a C++ source file:

void my_puts(const char *str) {
 ...
}

and there’s an attempt to call my_puts() in a plain C file, this will fail with a normal compiler as well as HLS.

In HLS, specifically, the function call in the C file will yield an error like

ERROR: [SYNCHK 200-71] myproject/example/src/main.c:20: function 'my_puts' has no function body.

The thing is, that just adding an extern “C” in the .cpp file will not be enough. The “no function body” error will not go away. What’s required is setting the namespace to hls as well. Something like this:

namespace hls {

extern "C" {

void my_puts(const char *str) {
 ...
}

}
}

The inspiration for this solution came from the source files of the HLS suite itself. I don’t know if this is really a good idea, only that it works.

Reader Comments

Hi there,

I am encountering the same problem as stated here. Unfortunately I could not resolve it using this method(have tried multiple variants of this). I have a .cpp that uses a couple of #include functions like cexp() and csqrt().

Still getting these errors:

ERROR: [SYNCHK 200-71] function ‘csqrt’ has no function body.
ERROR: [SYNCHK 200-71] function ‘cexp’ has no function body.

Can you give me some insight into this please?

Thanks!

#1 
Written By J on May 22nd, 2017 @ 23:09

Add a Comment

required, use real name
required, will not be published
optional, your blog address