Re: undefined reference to

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
On Tue, Aug 24, 2010 at 11:55:52PM -0700, jmchu@xxxxxxx wrote:
> I am running Cygwin on Windows 7 and I am trying to compile a c file that
> has uses a function from a c++ file. However I keep on getting undefined
> reference to the c++ function
> 
> In my ATmegaBOOT_xx8.c file,
> I declared the header of the c++ file
> 
> extern "C" {
> #include "wireless.h"
> }
>
> [...]
>
>  c:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe
> -m avr5 -Tdata 0x800100 -o ATmegaBOOT_xx8_adaboot328.elf
> c:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5/crtm328p.o
> -Lc:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr5
> -Lc:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5
> -Lc:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2
> -Lc:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc
> -Lc:/users/school/arduino-0015/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib
> --section-start=.text=0x7800 ATmegaBOOT_xx8.o -lgcc -lm -lgcc -lc -lgcc
> ATmegaBOOT_xx8.o: In function `main':
> C:\Users\School\dkirkby-athomeleaf-a657898/ATmegaBOOT_xx8.c:262: undefined
> reference to `initNordic'
> make: *** [ATmegaBOOT_xx8_adaboot328.elf] Error 1
> 
> 
> I think the linker does not know where to look for my wireless.o file,
> it is at the current directory of make file/build.328/obj
> 
> how do I tell the linker where to look?  when I tried -l/build.328/obj ,
> it kept saying folder not found
There might be two problems:
1) You have to tell the linke explicitely all files it shall use -- by
   simply adding them to the command line when you call the linker.
   If the file is in the same directory from where you call the linker,
   the filename (wireless.o) is sufficient. If not, try adding something
   like "build.328/obj/wireless.o" to the command when the linker is
   started.
2) When you compile the file wireless.cc (?) in order to create
   wireless.o you have to guarantee that at least the function
   initNordic (which you call from C-code) is compiled as extern "C" --
   if not, g++ uses different naming conventions and the linker won't
   find the function.

HTH,

Axel



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux