0

I am trying to modify a Makefile to include an externally compiled object, but am getting an "undefined reference" error. This it the first time I've dealt with Makefiles - please be gentle.

What I've done so far:

  • Modified main.c to include a new header file, cudacrack.h
  • Added a call to runCudaImplementation() to main.c, which is defined in cudacrack.h
  • Modified the Makefile.in file to include cudacrack.o as an object dependency
  • Modified Makefile.in to include cudacrack.h as a source file
  • make clean
  • Compiled cudacrack.c with: g++ -c cudacrack.c -o cudacrack.o
  • ./configure
  • make --debug==verbose

I get this error during linking:

g++ -L/usr/local/cuda/lib64/ -lcuda -lcudart  -g -O2 -funroll-loops -O3   -o fcrackzip  main.o crack.o cudacrack.o
main.o: In function `main':
$HOME/fcrackzip/fcrackzip-1.0/main.c:367: undefined reference to `runCudaImplementation'
collect2: ld returned 1 exit status

Note: At this point the "cuda" file name only contain basic C methods. Later I will compile this part with nvcc. I explain a little more on my other question that led me here: Building GPL C program with CUDA module

Some debug info from make:
     Considering target file `cudacrack.h'.
       Finished prerequisites of target file `cudacrack.h'.
      No commands for `cudacrack.h' and no prerequisites actually changed.
      No need to remake target `cudacrack.h'.

..later..

    Considering target file `cudacrack.o'.
      Considering target file `cudacrack.c'.
       Finished prerequisites of target file `cudacrack.c'.
      No need to remake target `cudacrack.c'.
     Finished prerequisites of target file `cudacrack.o'.
     Prerequisite `cudacrack.c' is older than target `cudacrack.o'.
    No need to remake target `cudacrack.o'.

What needs to happen for make to link the main program with the cudacrack.o dependency?

Community
  • 1
  • 1
emulcahy
  • 1,055
  • 3
  • 18
  • 28
  • It would help if you showed us how your makefile builds the other objects-- I suspect the problem is an incompatibility there. Try a simpler case; write a little test routine for `cudacrack` (if you haven't already) and confirm that you can build and run that. Then try a middle case... – Beta Feb 23 '12 at 19:31

1 Answers1

1

Have you checked if the symbol runCudaImplementation is actually defined in cudacrack.o? Perhaps the name got mangled because you use g++ to compile it, instead of gcc.

eriktous
  • 6,569
  • 2
  • 25
  • 35
  • I think you win: $objdump -t cudacrack.o: 0000000000000000 g F .text 000000000000000b _Z21runCudaImplementationv, $objdump -t -C cudacrack.o: 0000000000000000 g F .text 000000000000000b runCudaImplementation() edit: It works when using gcc. Thank you! – emulcahy Feb 24 '12 at 23:31