How use an struct variable in app project and library project

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How use an struct variable in app project and library project

2,366 次查看
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 回复数

2,330 次查看
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.

2,333 次查看
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.

2,332 次查看
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? 

2,343 次查看
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. 

 

 

 

2,340 次查看
Mr_Chen
Contributor II

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

0 项奖励
回复

2,335 次查看
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 项奖励
回复

2,337 次查看
jiri_kral
NXP Employee
NXP Employee

Hi, 

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