Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference errors in gcc when compiling on another machine

Tags:

c

gcc

I wrote a program (myreader.c) to manipulate a RFID reader.

I compile by type "make" in the root of the package, makefile is shown below

  # CC and CFLAGS are varilables 
  CC=gcc
  CFLAGS = -c
  # -c option ask g++ to compile the source files, but do not link.
  # -g option is for debugging version
  # -O2 option is for optimized version
  OPTFLAGS = -O2 -g

  myreader    : src/myreader.c
          $(CC) $(OPTFLAGS) src/myreader.c src/crypto1.c src/nfc-utils.c -lnfc -o ./bin/myreader 

  # clean all the .o and executable files
  clean:
          rm -rf bin/myreader

and it works well on my original machine(64 bits, Ubuntu 12.04 LTS), and the only problem is, when I type make, the warning info would come up.

  src/myreader.c:519:6: warning: conflicting types for ‘printResult’ [enabled by default]
  src/myreader.c:211:3: note: previous implicit declaration of ‘printResult’ was here

But /bin/myreader works well.


However, when I move the package to another machine(64 bits, Ubuntu 11.10), and type make in the same way as in the original machine.

Error messages in the below appears:

  berln@ubuntu:~/桌面/useful code$ make
  gcc -O2 -g src/myreader.c src/crypto1.c src/nfc-utils.c -lnfc -o ./bin/myreader
  src/myreader.c:519:6: warning: conflicting types for ‘printResult’ [enabled by default]
  src/myreader.c:211:3: note: previous implicit declaration of ‘printResult’ was here
  /tmp/ccrKvhjm.o: In function `mf_enhanced_auth':/home/berln/桌面/useful code/src/myreader.c:373: undefined reference to `nfc_configure'
  /home/berln/桌面/useful code/src/myreader.c:380: undefined reference to `nfc_configure'
  /home/berln/桌面/useful code/src/myreader.c:390: undefined reference to `nfc_configure'
  /home/berln/桌面/useful code/src/myreader.c:434: undefined reference to `nfc_configure'
  /tmp/ccrKvhjm.o: In function `mf_configure':
  /home/berln/桌面/useful code/src/myreader.c:484: undefined reference to `nfc_configure'
  /tmp/ccrKvhjm.o:/home/berln/桌面/useful code/src/myreader.c:489: more undefined references to `nfc_configure' follow
  /tmp/ccrKvhjm.o: In function `main':
  /home/berln/桌面/useful code/src/myreader.c:155: undefined reference to `nfc_connect'
  /home/berln/桌面/useful code/src/myreader.c:213: undefined reference to `nfc_disconnect'
  collect2: ld returned 1 exit status
  make: *** [myreader] Error 1

I have no ideas why this error happened on only one machine instead of both.

If you need more information, you can download the package here.

Thanks in advance.

like image 293
Po-Jen Lai Avatar asked Apr 24 '26 01:04

Po-Jen Lai


1 Answers

It seems the problem is in the nfc library, but the linker doesn't complain that it's missing, so something wrong with it. Try to recompile it. If it's a package check that it's the same version as on the other server.

like image 88
Karoly Horvath Avatar answered Apr 25 '26 19:04

Karoly Horvath