Write and compile C++ code.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
icosac
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hello everybody,

I've received a TX375 lite kit form my University onto which I should port an already written library . Such library is completely written in C++, hence I would like to be able to write the rest of the code in C++.

I'm having some trouble making AURIX Development Studio recognize and compile C++ code.

Up until now I've tried different settings and things found on the internet and/or on some old manuals (I'm running v1.5.4, but the most updated manual I could find is v.1.4 something), but I couldn't make it work. I've tried using an external compiler, but I cannot access a Tricore compiler, I've tried following this guide, but it does not work, nor does any other option I set.

Is there anyway to compile C++ code with AURIX Development Studio or do I have to re-write all the code to C?

Thank you very much,

Enrico

0 Likes
1 Solution
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Hi Enrico,

I'm using Aurix Development Studio V1.5.4 and the pre-compiled DMA_ADC_Transfer_1_KIT_TC375_LK example program and in that I've manually added function (_Z12__call_ctorsv();) as mentioned in the thread https://community.infineon.com/t5/AURIX/Use-C-to-development-TCxxx-like-tc275/m-p/318464 in a C file in the project and I see the Compilation is successful.

Could you please check if all the options required for C++ build are enabled. You may check those in the below windows:

1.

Prudhvi_0-1647517060419.png

 

2.

Prudhvi_1-1647517114254.png

Are above options configured in your project ?

View solution in original post

3 Replies
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Hi Enrico,

I'm using Aurix Development Studio V1.5.4 and the pre-compiled DMA_ADC_Transfer_1_KIT_TC375_LK example program and in that I've manually added function (_Z12__call_ctorsv();) as mentioned in the thread https://community.infineon.com/t5/AURIX/Use-C-to-development-TCxxx-like-tc275/m-p/318464 in a C file in the project and I see the Compilation is successful.

Could you please check if all the options required for C++ build are enabled. You may check those in the below windows:

1.

Prudhvi_0-1647517060419.png

 

2.

Prudhvi_1-1647517114254.png

Are above options configured in your project ?

Hi Prudhvi,

Thank you very much for answering. Yes, all the options were correctly set, and actually my error was on extern "C" syntax, so nothing related to AURIX.

I don't know whether asking another question is good practice for this forum or not, but now that I'm able compile and link C++ code, I've written a simple function that assigns an int value to a variable, but when I try to run it and set a break point to the variable to check whether it is working fine, I get the following error: "Default:Cannot read variable, no storage assigned." What am I doing wrong? I attach the code below.

 

 

// libraries/service/test/test.hpp
#pragma once

#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif

EXTERNC int value();

 

 

 

// libraries/service/test/test.cpp
#include<test/test.hpp>

int value () {
    int a=3;
    return a;
}

 

 

 

// Cpu0_Main.c
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include <test/test.hpp>

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

    int v=0;
    // printf("1v: %d\n", v);
    v=value();
    // printf("2v: %d\n", v);
    v=6;

    while(1)
    {
    }
}

 

 

EDIT: apparently yesterday evening I was not really awake... The only problem with the above code is the missing #include<stdio.h> to let the program know where to get printf()...

 

0 Likes
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Good to know that you're issue is solved !!

0 Likes