undefined reference to function() error.

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

Hi all,

I tried to build a simple UART code.
I called HAL_UartInit() function from main.c and HAL_UartInit() is defined in another file hal_uart.c.
I have added function prototype in header file hal_uart.h.
I have added both files in project explorer.

but why it is not getting definition of that function, I think its not linking properly.

please help me, any suggestion would be helpful.

Regards,
shreyas.

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

Quote:

I have added both files in project explorer.

Well the error suggests that either the file that contains the function was not built/linked or that there's something in it (perhaps #if protection?) that prevents the body of the function in question being compiled.

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

You can start by copying all of the build output and paste it into a post here.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

JohanEkdahl wrote:
You can start by copying all of the build output and paste it into a post here.

below is the build output I got.

------ Build started: Project: GccApplication2, Configuration: Debug AVR ------
Build started.
Project "GccApplication2.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "D:\TOOLs\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\Users\Shreyas.Patel.172\Documents\Atmel Studio\6.1\GccApplication2\GccApplication2\GccApplication2.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		D:\TOOLs\Atmel\Atmel Studio 6.1\shellUtils\make.exe -C "C:\Users\Shreyas.Patel.172\Documents\Atmel Studio\6.1\GccApplication2\GccApplication2\Debug" -f "Makefile" all 
		make: Entering directory `C:/Users/Shreyas.Patel.172/Documents/Atmel Studio/6.1/GccApplication2/GccApplication2/Debug'
		Building file: .././GccApplication2.c
		Invoking: AVR/GNU C Compiler : 
		"D:\TOOLs\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.876\avr8-gnu-toolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -DDEBUG  -I"../.."  -O1 -ffunction-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega256rfr2 -c -std=gnu99 -MD -MP -MF "GccApplication2.d" -MT"GccApplication2.d" -MT"GccApplication2.o"   -o"GccApplication2.o" ".././GccApplication2.c" 
		Finished building: .././GccApplication2.c
		Building file: .././hal_uart.c
		Invoking: AVR/GNU C Compiler : 
		"D:\TOOLs\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.876\avr8-gnu-toolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -DDEBUG  -I"../.."  -O1 -ffunction-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega256rfr2 -c -std=gnu99 -MD -MP -MF "hal_uart.d" -MT"hal_uart.d" -MT"hal_uart.o"   -o"hal_uart.o" ".././hal_uart.c" 
		Finished building: .././hal_uart.c
		Building target: GccApplication2.elf
		Invoking: AVR/GNU Linker : 
		"D:\TOOLs\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.876\avr8-gnu-toolchain\bin\avr-gcc.exe" -o GccApplication2.elf  GccApplication2.o hal_uart.o   -Wl,-Map="GccApplication2.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega256rfr2 
		GccApplication2.o: In function `main':
C:\Users\Shreyas.Patel.172\Documents\Atmel Studio\6.1\GccApplication2\GccApplication2\Debug/.././GccApplication2.c(34,1): undefined reference to `HAL_UartInit'
C:\Users\Shreyas.Patel.172\Documents\Atmel Studio\6.1\GccApplication2\GccApplication2\Debug/.././GccApplication2.c(37,1): undefined reference to `HAL_UartTaskHandler'
collect2.exe(0,0): ld returned 1 exit status
		make: Leaving directory `C:/Users/Shreyas.Patel.172/Documents/Atmel Studio/6.1/GccApplication2/GccApplication2/Debug'
		make: *** [GccApplication2.elf] Error 1
		The command exited with code 2.
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "GccApplication2.cproj" -- FAILED.
Done building project "GccApplication2.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you.

The output shows that:

- hal_uart.c is compiled into hal_uart.o
- the linking stage has hal_uart.o as one of its parameters

Still, the linking stage fails as the linker can not find the (compiled) functions HAL_UartInit and HAL_UartTaskHandler anywhere.

So, next stage is to see code - the two source files and the header file hal_uart.h, please..

If they are not trivially short, please zip the three files up and make that ZIP an attachement to a post here (no fun scrolling hundreds of lines of code in a browser).

(One alternative would be to ZIP up the whole project directory tree.)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

clawson wrote:
Quote:

I have added both files in project explorer.

Well the error suggests that either the file that contains the function was not built/linked or that there's something in it (perhaps #if protection?) that prevents the body of the function in question being compiled.

thank you clawson,

you are right it was a #if protection, I should define HAL_ENABLE_UART before including that file.

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

i have the same problem with header files , the header file i'm trying to include contains #if protection what shall i do to overcome this protection thing ? 

 

 

omar yousri