This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: "Undefined reference to ..." Errors
- From: Andrew Haley <aph at redhat dot com>
- To: John Farmer <news02 at lavabit dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 06 May 2009 18:20:14 +0100
- Subject: Re: "Undefined reference to ..." Errors
- References: <23411190.post@talk.nabble.com>
John Farmer wrote:
> I have a module static variable that is not referenced by any C code but is
> referenced by non-extended __asm__() statements similar to this.
>
>
> static int MyInt;
> .
> .
> .
> void f(void)
> {
>
> __asm__("ldr r8, =MyInt\n" ...);
>
> }
>
> The problem is that when I build my release version I get "Undefined
> reference to MyInt" linker errors. I use the -Wunused compiler option for
> the release build to catch anything not referenced that I had forgotten to
> remove during debug. In general I would like to keep this option but perhaps
> selectively disable it for a particular data definition in a particular
> module if necessary.
>
> I have tried using the "unused" attribute for the data definition which
> removes the compiler warning "MyInt defined but not used" but still gives me
> the linker error.
>
> It occurs to me that perhaps the right way to remove this error is to get
> asm to recognise the variable as it would if using extended asm statements
> but I cannot how a way to do this. Perhaps someone could enlighten me or
> maybe there is another solution.
Attribute 'used' ?
Andrew.