How use an struct variable in app project and library project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How use an struct variable in app project and library project

1,244 Views
Mr_Chen
Contributor II

I created a library project and app project.I want to use the sturct variable which declared in library project,but I can't do that.Why?The code shown as below:

企业微信截图_20230219151221.png

企业微信截图_20230219151419.png

企业微信截图_20230219151241.png

 Please help me.Thanks!

   

 

7 Replies

1,208 Views
Joey_van_Hummel
Contributor IV

You've declared ss as an external, but define it as a local variable on the stack in main(). Make it a global variable in your C-file (outside of the function) and it should work.

1,211 Views
Mr_Chen
Contributor II

The library project can be built successfully.Firstly,I declared a structure in library header file and also defined a extern structure variable. Secondly,I defined a function which used this structure variable in library source file. And then I export from library header file and the variable also used in library source file.Then I defined a same structure variable and call that function in app project.But it reported some errors while building.

1,210 Views
jiri_kral
NXP Employee
NXP Employee

I see. But which kind of error? It is possible share output from build console? Or even better - your library and app project? 

1,221 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

I'm not sure what is your library/project structure. But basically - you need to implement functions in your library code. Structure definition can be done in library header file. 

For using your library in your project, you need to tell linker where the library is. Right click on project name -> Properties: 

jiri_kral_0-1676892753230.png

 

If you specify function/variable as a extern - it tells linker to search such function in other obj files. 

 

 

 

1,218 Views
Mr_Chen
Contributor II

Yes,the library path have been set.But it failed when building the project.

0 Kudos
Reply

1,213 Views
jiri_kral
NXP Employee
NXP Employee

Um, sorry - the error is during build, right? Can you please share the output from build console and share screenshot from Linker settings (the window which I shared). 

0 Kudos
Reply

1,215 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

how the debug fails? Is there some error message?  Did you build your library with debug info?