Ryan Mansfield(deleted)
|
Re: Error: 'undefined reference to ABC' while linking static libraries
|
Ryan Mansfield(deleted)
02/14/2011 9:42 AM
post83147
|
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
|
|
|