Undefined references [solved: overuse of static]

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have C/C++ programming exper but am just getting started with AS5. Have built a small library with 2 .c files as one lib solution then built a v-e-r-y simple test program as an EXE solution. The link pass on the test program fails: it can't "see" any of the functs invoked from the library. So I'm assuming it either has to do with getting the linker path options just right, or the generated lib file isn't right. A full read thru all the docs for avr-libc GCC and what little there is for AS5 has been no help.

Linker Library options question:
If the generated .a library file in the filepath\Debug folder is "libCB-Library.a", and if the path to that Debug folder is "C:\Users\abc\Documents\AVRStudio\CB-Library\CB-Library\Debug", then does the following linker invocation from AS5 look right?

"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -Wl,-L"C:\Users\abc\Documents\AVRStudio\CB-Library\CB-Library\Debug"   -mmcu=atmega328p  -Wl,-Map=Test-GLCD.map -o Test-GLCD.elf  Test-GLCD.o  -Wl,-lCB-Library

Thanks in advance for any help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
it can't "see" any of the functs invoked from the library.
So, what is the actual error message you get?

Quote:
...then does the following linker invocation from AS5 look right?
Yes

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
what is the actual error message you get?

Test program:

#include 
#include "Serial.h"
#include "GLCD-serial.h"
int main(void)
{
   init_UART();  // initialize UART port: function in library CB-Library
}

Linker output:

Invoking: AVR/GNU C/C++ Linker

"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -Wl,-L"C:\Users\abc\Documents\AVRStudio\CB-Library\CB-Library\Debug"   -mmcu=atmega328p  -Wl,-Map=Test-GLCD.map -o Test-GLCD.elf  Test-GLCD.o  -Wl,-lCB-Library 

Test-GLCD.o: In function `main':

C:\Users\abc\Documents\AVRStudio\Code\Tests\Test-GLCD\Test-GLCD\Debug/.././Test-GLCD.c(16,1): undefined reference to `init_UART'

collect2: ld returned 1 exit status

make: *** [Test-GLCD.elf] Error 1
Done executing task "RunAvrGCC" -- FAILED.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One more thing: I just used objdump -t to verify the symbol table of the lib. All the functions are there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it spelled the same in main, the header file, and the library file?

I don't see anything obviously wrong from what you've shown so far.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please delete your cross-post in the Studio 5 forum before someone tries to respond there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I deleted the AS5 post altho' the prob might still be caused by the IDE (low probability but non-zero).

Anyway, func spelling/naming is not issue: any function from the serial.o object in the library is not being linked. FWIW all functions in that module are declared type static void. I'll keep whittling it down but it's disturbingly simple already...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

microguy wrote:
I deleted the AS5 post altho' the prob might still be caused by the IDE (low probability but non-zero).
One of the Mods can always move the thread when necessary.

microguy wrote:

Anyway, func spelling/naming is not issue: any function from the serial.o object in the library is not being linked. FWIW all functions in that module are declared type static void. I'll keep whittling it down but it's disturbingly simple already...
static :!: :?: That makes them only accessible within the library file. If the function needs to be accessed outside of the translation unit/module/file then don't make it static.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That was it. That's what I get for blindly copying functions from another test program into a library.

I owe you one John. Next time I'm in San Diego I'll buy you a beer. Many thanks.

Chris

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a great example of WHY we want posted code in the OP, for future ref.. Your problem would've been solved in a 1st response.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1