"Undefined Reference" Errors When Building

I’ve successfully installed everything for the Orangutan Baby B-328 and successfully programmed it with the blink LED example, had fun messing with blink timings and it all works great, except when I try to use any other examples from the documentation. I’m currently trying to program the motor example found at:
https://www.pololu.com/docs/0J20/3.f

Here’s the build results of the blink LED example that was successful…

------ Build started: Project: NS, Configuration: Debug AVR ------
Build started.
Project “NS.cproj” (default targets):
Target “PreBuildEvent” skipped, due to false condition; (’$(PreBuildEvent)’!=’’) was evaluated as (’’!=’’).
Target “CoreBuild” in file “C:\Program Files (x86)\Atmel\Atmel Studio 6.0\Vs\Compiler.targets” from project “L:\Atmel Studio\NS\NS.cproj” (target “Build” depends on it):
Task “RunCompilerTask"
C:\Program Files (x86)\Atmel\Atmel Studio 6.0\make\make.exe all
Building file: …/./BlinkLED.c
Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
"C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe” -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF “BlinkLED.d” -MT"BlinkLED.d" -MT"BlinkLED.o" -mmcu=atmega328p -o"BlinkLED.o" “…/./BlinkLED.c"
Finished building: …/./BlinkLED.c
Building target: NS.elf
Invoking: AVR/GNU Linker : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
"C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe” -o NS.elf BlinkLED.o -Wl,-Map=“NS.map” -Wl,–start-group -Wl,-lm -Wl,–end-group -mmcu=atmega328p
Finished building target: NS.elf
"C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature “NS.elf” “NS.hex”
“C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objcopy.exe” -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex “NS.elf” “NS.eep” || exit 0
"C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objdump.exe" -h -S “NS.elf” > “NS.lss”
“C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objcopy.exe” -O srec -R .eeprom -R .fuse -R .lock -R .signature “NS.elf” “NS.srec”
“C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-size.exe” "NS.elf"
text data bss dec hex filename
214 0 0 214 d6 NS.elf
Done executing task “RunCompilerTask”.
Using “RunOutputFileVerifyTask” task from assembly “C:\Program Files (x86)\Atmel\Atmel Studio 6.0\Vs\Compiler.Task.dll”.
Task "RunOutputFileVerifyTask"
Program Memory Usage : 214 bytes 0.7 % Full
Data Memory Usage : 0 bytes 0.0 % Full
Done executing task “RunOutputFileVerifyTask”.
Done building target “CoreBuild” in project “NS.cproj”.
Target “PostBuildEvent” skipped, due to false condition; (’$(PostBuildEvent)’ != ‘’) was evaluated as (’’ != ‘’).
Target “Build” in file “C:\Program Files (x86)\Atmel\Atmel Studio 6.0\Vs\Avr.common.targets” from project “L:\Atmel Studio\NS\NS.cproj” (entry point):
Done building target “Build” in project “NS.cproj”.
Done building project “NS.cproj”.

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Here’s the build results of the motor example that failed…

------ Build started: Project: NS, Configuration: Debug AVR ------
Build started.
Project “NS.cproj” (default targets):
Target “PreBuildEvent” skipped, due to false condition; (’$(PreBuildEvent)’!=’’) was evaluated as (’’!=’’).
Target “CoreBuild” in file “C:\Program Files (x86)\Atmel\Atmel Studio 6.0\Vs\Compiler.targets” from project “L:\Atmel Studio\NS\NS.cproj” (target “Build” depends on it):
Task “RunCompilerTask"
C:\Program Files (x86)\Atmel\Atmel Studio 6.0\make\make.exe all
Building file: …/./PWMFanViaPot.c
Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
"C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe” -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF “PWMFanViaPot.d” -MT"PWMFanViaPot.d" -MT"PWMFanViaPot.o" -mmcu=atmega328p -o"PWMFanViaPot.o" “…/./PWMFanViaPot.c"
Finished building: …/./PWMFanViaPot.c
Building target: NS.elf
Invoking: AVR/GNU Linker : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
"C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe” -o NS.elf PWMFanViaPot.o -Wl,-Map=“NS.map” -Wl,–start-group -Wl,-lm -Wl,–end-group -mmcu=atmega328p
PWMFanViaPot.o: In function main': L:\Atmel Studio\NS\Debug/.././PWMFanViaPot.c(29,1): undefined reference toread_trimpot’
L:\Atmel Studio\NS\Debug/…/./PWMFanViaPot.c(33,1): undefined reference to set_motors' L:\Atmel Studio\NS\Debug/.././PWMFanViaPot.c(39,1): undefined reference todelay_ms’
L:\Atmel Studio\NS\Debug/…/./PWMFanViaPot.c(41,1): undefined reference to `delay_ms’
collect2: ld returned 1 exit status
make: *** [NS.elf] Error 1
Done executing task “RunCompilerTask” – FAILED.
Done building target “CoreBuild” in project “NS.cproj” – FAILED.
Done building project “NS.cproj” – FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

I’m seeing undefined reference to 4 commands. I’ve spent hours searching the forum and the web for possible causes and found that it’s typically due to missing include files as a result of the Pololu AVR Development Bundle not being installed, however I had done this. So I’ve followed the chain of includes initiating from “orangutan.h” and all of those commands are defined within the includes chain, so I’m confused why the build is still not recognizing those commands. I followed all instructions exactly several times and was successful with the blink led example, but all other examples fail due to unrecognized commands that are clearly already defined in the includes chains. I’ve re-installed the latest Pololu AVR Development Bundle for Windows (release 121115), and verified the commands do exist and are defined in the includes chain, all un-modified.

Hello.

You seem to have not configured the AVR/GNU Linker to use the pololu_atmega328p library, which caused your code to fail. Please check if you have the Pololu templates installed in Atmel Studio. Try using the Baby Orangutan B-328 template and see if your code works. More information about compling an example program can be found in the Pololu AVR Programming Quick Start Guide.

- Jeremy

Sorry, I tried to explain clearly, the templates are installed and the results shown of the first successful build are from the template for the Orangutan Baby B-328 when following the guide. The guide then instructs to review the Pololu AVR C/C++ Library User’s Guide for more example code to explore the other features of the board, but those are the examples that fail to build. The second build result shown is a failed build from example #1 of section 3.f Organutan Motor Control Functions.

Thank you David and the rest of the crew at Pololu! We’re good to go!

I think maybe the problem was that I was copying and pasting code from the PDF rather than the web page. Works like a charm now.