Error 5882 when using B&R library functions/function blocks inside an ANSI C++ custom library

Hello, I am trying to create custom function blocks in C++. When I try to use function/function blocks from B&R libraries (ArCAN/AsTime/AsIOTime) I seem to be getting error 5882 compile error. Is there something else I had to do other than #include them?

Hi,

Iā€™d generally recommend posting a minimal example so people know what your current code looks like.
The error 5882 would let me think you are trying to access a FB instance that you made globally - which doesnā€™t work.
Generally speaking, everything a FB needs to access needs to be contained in there, so you need to have an instance of the FUB as part of your own FUBā€™s interface.

Additionally fyi, there is usually no need to add ā€œincludeā€ statements for libs manually (neither in tasks nor libs) - in tasks, the default include mechanism exists and works and in libs you can add any lib you want as a dependency and it will therefore also already be included by the automatically created header file.

Example with ā€œastimeā€ usage appended
Library.zip (6.9 KB)

Best regards
Michael

Hello Michael,

Thanks for pointing out.
I think I missed a crucial information here. I was doing it in AS6.

Today I tried to import the same library as reference into a test project in AS4.12 and it is able to compile.

The error will already occur (in AS6 only) with a simple call of clock_ms() from AsTime.
Here is my pseudo code example

#include <bur/plctypes.h>
#include "simpleCAN.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ArCan.h"
#include "AsIOTime.h"
#include "AsTime.h"

unsigned long bur_heap_size = 0xFFFF;

void simpleCAN(struct simpleCAN* inst){
	if (inst->Enable)
	{
		if (inst->Active)
		{
			plctime currentTime = clock_ms();
		}else
		{
			inst->internal.steps = SCAN_INIT;
		}			
	}else
	{
		inst->internal.steps = SCAN_ENABLE_FALSE;
	}

...

Since it only seems to occur in AS6 not sure if there was some setting I had to change, or it may be a bug Iā€™ll create a ticket on this.

Best,
Samuel

Hi everyone,

An update on the issue. It seems to be some bugs will be taken into consideration in AS6.1 update.

Workaround: add build option ā€œ-u__cxa_begin_cleanupā€ to additional build options of the library.

2 Likes

I get the same error 5882 (ā€œUnknown PV __cxa_begin_cleanupā€) when converting a project from AS 4.12.6, where there are no errors, to AS 6.0.2.177. However, your suggested solution of entering ā€œ-u__cxa_begin_cleanupā€ as ā€˜additional build optionsā€™ does not help either, as this only generates further errors ( ā€œundefined reference to ā€˜bur_heap_sizeā€™ā€ ).
The error seems to be related to the heap management in c/c++ code ? According to the help, nothing has changed there.

Hello Ludger,

Do you have bur_heap_size variable declare somewhere in the C++ library/Code (see the pseudo code above)?

For my case I will also get the ā€œundefined reference to ā€˜bur_heap_sizeā€™" if I donā€™t declare it in any one of the .cpp files in my library. And seems like it will share the same heap allocation across the entire library.

Hello Samuel,

I added ā€˜unsigned long bur_heap_sizeā€™ to my library code. But this only replaces error 5882 with another error: the linker (?) now complains about ā€œmultiple definition of bur_heap_sizeā€ ā€¦ so fixing one error generates only new errors.
I am frustated and will stop the conversion of my project to AS 6, as I now believe that the C/C++ integration is broken. Maybe there will be an AS6 version in the future that can be used in production ā€¦

with regards
Ludger