Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - Error: 'undefined reference to ABC' while linking static libraries: (3 Items)
   
Error: 'undefined reference to ABC' while linking static libraries  
I am building static llibraries A & B such that B is making calls to the functions defined in library A. The source file
 of lib B includes the .h file of lib A that is having function prototypes of lib A.

I am observing error: 'undefined reference to ABC' when I try to create an executable which uses these libraries. I am 
linking these libraries properly(and also I am giving proper search path for both lib A & B).
Re: Error: 'undefined reference to ABC' while linking static libraries  
On 11-02-14 09:36 AM, Girisha SG wrote:
> I am building static llibraries A & B such that B is making calls to the
> functions defined in library A. The source file of lib B includes the .h
> file of lib A that is having function prototypes of lib A.
>
> I am observing error: 'undefined reference to ABC' when I try to create
> an executable which uses these libraries. I am linking these libraries
> properly(and also I am giving proper search path for both lib A & B).

OK, but this is completely unrelated to -Wc,-std=c99 at all.

This is no doubt an issue of link order. When you are statically 
linking, the definition must come after the reference and the linker 
processes these in a left-to-right order. That is, if libB.a calls a 
function in libA.a, then the link order must be -lB -lA. If libA.a calls 
a function in libB.a, the link order must be -lA -lB. And if you have 
circular dependices you must group them so the linker will make a second 
pass. To do this, you do --Wl,--start-group -lA -lB --Wl,--end-group.

Regards,

Ryan Mansfield
Re: Error: 'undefined reference to ABC' while linking static libraries  
Yes it is completely unrelated to -Wc,-std=c99 and hence I have created a seperate thread.

One more thing is while building static library B (which is dependent on library A) I am getting warning like 'reference
 to undefined function' though I am including a header file that has prototype of the functions that are part of library
 A.

Why it is so ???