Issue with Undefined References for Global Variables in Static Library

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

Issue with Undefined References for Global Variables in Static Library

Jump to solution
376 Views
Ranjith_kumar
Contributor II

Dear NXP Team,

I have a source file filename.c and its corresponding header filename.h. Within filename.c, I define and initialize some global variables, which are declared as extern in filename.h.

I have compiled filename.c into a static library file (filename.a). However, when linking this static library, I encounter "undefined reference" errors related to those global variables.

Ranjith_kumar_0-1753764504383.png

 

Could you please provide guidance or best practices on how to correctly manage these global variables with extern declarations and static library creation to resolve the undefined reference issue?

Thank you for your support.

Best regards,

P.Ranjth kumar

0 Kudos
Reply
1 Solution
337 Views
_Leo_
NXP TechSupport
NXP TechSupport


Thank you for your interest in our products and for contributing to our community.

Please refer to HOWTO: Add a static library file into S32DS GCC project.

I hope this information is helpful. Feel free to reach out if you have any further questions.

View solution in original post

0 Kudos
Reply
1 Reply
338 Views
_Leo_
NXP TechSupport
NXP TechSupport


Thank you for your interest in our products and for contributing to our community.

Please refer to HOWTO: Add a static library file into S32DS GCC project.

I hope this information is helpful. Feel free to reach out if you have any further questions.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2142248%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EIssue%20with%20Undefined%20References%20for%20Global%20Variables%20in%20Static%20Library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2142248%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%20class%3D%22%22%3EDear%20NXP%20Team%2C%3C%2FP%3E%3CP%20class%3D%22%22%3EI%20have%20a%20source%20file%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efilename.c%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20its%20corresponding%20header%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efilename.h.%20Within%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efilename.c%2C%20I%20define%20and%20initialize%20some%20global%20variables%2C%20which%20are%20declared%20as%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eextern%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ein%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efilename.h.%3C%2FP%3E%3CP%20class%3D%22%22%3EI%20have%20compiled%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efilename.c%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einto%20a%20static%20library%20file%20(filename.a).%20However%2C%20when%20linking%20this%20static%20library%2C%20I%20encounter%20%22undefined%20reference%22%20errors%20related%20to%20those%20global%20variables.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ranjith_kumar_0-1753764504383.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Ranjith_kumar_0-1753764504383.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F349872i4581D3C7CD9EE3CC%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Ranjith_kumar_0-1753764504383.png%22%20alt%3D%22Ranjith_kumar_0-1753764504383.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22%22%3ECould%20you%20please%20provide%20guidance%20or%20best%20practices%20on%20how%20to%20correctly%20manage%20these%20global%20variables%20with%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eextern%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edeclarations%20and%20static%20library%20creation%20to%20resolve%20the%20undefined%20reference%20issue%3F%3C%2FP%3E%3CP%20class%3D%22%22%3EThank%20you%20for%20your%20support.%3C%2FP%3E%3CP%20class%3D%22%22%3EBest%20regards%2C%3C%2FP%3E%3CP%20class%3D%22%22%3EP.Ranjth%20kumar%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2146429%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Issue%20with%20Undefined%20References%20for%20Global%20Variables%20in%20Static%20Library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2146429%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CBR%20%2F%3EThank%20you%20for%20your%20interest%20in%20our%20products%20and%20for%20contributing%20to%20our%20community.%3C%2FP%3E%0A%3CP%3EPlease%20refer%20to%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32-Design-Studio-Knowledge-Base%2FHOWTO-Add-a-static-library-file-into-S32DS-GCC-project%2Fta-p%2F1110308%22%20target%3D%22_blank%22%3EHOWTO%3A%20Add%20a%20static%20library%20file%20into%20S32DS%20GCC%20project.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EI%20hope%20this%20information%20is%20helpful.%20Feel%20free%20to%20reach%20out%20if%20you%20have%20any%20further%20questions.%3C%2FP%3E%3C%2FLINGO-BODY%3E