cancel
Showing results for 
Search instead for 
Did you mean: 

Linker error : no definition for "DATA"(variable of type struct data_t)

youssef.amimi
Associate III

I have declared a typedef struct data_t on my jsmn.h

0690X000009Yt5TQAS.pngafter that I declared a variable DATA of type data_t on jsmn.c

0690X000009Yt6cQAC.png

and i defined N,T,C and H

0690X000009Yt6wQAC.png

then i declared DATA of type Data_t as extern on ScreenViewBase.cpp

0690X000009Yt7QQAS.png

and i try to display DATA.N on the screen

0690X000009Yt8OQAS.png

but a linker error appear : no definition for DATA referenced from ScreenViewBase.o

PS1: I do the same with time : in ScreenViewBase.cpp I declared extern RTC_TimeTypeDef sTime then  I write Unicode::snprintf(Ndata, 6, "%02d",sTime.Hours ); and it work perfectly.

PS2: I work with stm32f769 and with IAR 8.32.3

10 REPLIES 10

Perhaps because DATA isn't very original, and is used as a variable or section name within the namespace of the project, or associated libraries.

Pick something more unique...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
youssef.amimi
Associate III

Hi @Community member​ 

I tried that(I replaced with youssef_data) but steel the same problem

Are we sure this is a linker error?

Post a build log, saves playing guess what's wrong.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

this is a screenshot of the build log

0690X000009YtKPQA0.png

Kind of suggests

a) jsmn.c isn't in the project

b) The mixing of C/CPP compilation results in name mangling on the C++ side, and thus an inability to find the symbol

Perhaps use

extern "C" Data_t DATA;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

a) jsmn.c is in the project.

b) I used extern "C" , but the same problem.

The linker seems to disagree, perhaps you need to disassemble the objects and see what symbols are actually inside them.

Not sure if the IAR linker outputs a .MAP on failure cases, or if there are options for verbose output, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@Community member​ 

I don't know why but when I add this line (Data_t DATA); in main.cpp the error disappear.

I know now what is the problem the Data_t DATA was declared localy on a function in jsmn.c , I declare Data_t DATA globally and I elimineted this declaration in main.cpp