-2

Already fixed it thx

I got 5 files: cdouble.c cdouble.h cmatrix.c cmatrix.h and main.c

in my cdouble.c I have:

#include "cdouble.h"

in my cmatrix.c I have:

#include "cmatrix.h"

(in my cmatrix.h file i got: #include "cdouble.h"

And in my main file I have:

#include "cmatrix.h"

I need to compile it on my university's unix(?) server. I tried:

gcc -c cmatrix.c
gcc cmatrix.o main.c

but I got many "undefined reference errors"

$ gcc -c cmatrix.c

gcc cmatrix.o main.c: /tmp/ccZD6esL.o: In function ishermitian:
main.c:(.text+0x7b): undefined reference to cConj
main.c:(.text+0x8b): undefined reference to getCDoubleImag
main.c:(.text+0xa0): undefined reference to getCDoubleReal
main.c:(.text+0xde): undefined reference to getCDoubleImag
main.c:(.text+0xef): undefined reference to getCDoubleImag
main.c:(.text+0x111): undefined reference to getCDoubleReal
main.c:(.text+0x122): undefined reference to getCDoubleReal
/tmp/ccZD6esL.o: In function scancdouble:
main.c:(.text+0x203): undefined reference to newCDouble
/tmp/ccZD6esL.o: In function main:
main.c:(.text+0x2d8): undefined reference to getCDoubleImag
main.c:(.text+0x2fc): undefined reference to getCDoubleReal
collect2: error: ld returned 1 exit status

klutt
  • 30,332
  • 17
  • 55
  • 95
alex403
  • 15
  • 1
  • 3

1 Answers1

1

You need to compile cdouble.c and link its .o file as well. E.g:

gcc -c cmatrix.c
gcc -c cdouble.c
gcc main.c cmatrix.o cdouble.o

or, more simply:

gcc main.c cmatrix.c cdouble.c
mayaknife
  • 302
  • 1
  • 8