-2

I am now implementing 3DES, I got the error like this:
The log:

Compiling 'ReadTag_new' for 'Arduino Uno PN532.cpp.o:In function PN532::example()' PN532.cpp:undefined reference to des3_set2key_dec' PN532.cpp:undefined reference to des3_set2key_enc' PN532.cpp:undefined reference to des3_crypt_cbc Error creating .elf

in which des3_set2key_dec, des3_set2key_enc, des3_cypt_cbc are functions that are implemented in des.c file and defined in des.h file, and in PN532.cpp file I also include des.h file, and I am sure that I include the correct file since I can use struct defined from that file.

I don't know what is wrong here? I search on Google and it talks about linker, like two files generate different .o file, and they should be linked together, but I am not sure I am in that case

alk
  • 69,737
  • 10
  • 105
  • 255
Bao Doan
  • 87
  • 1
  • 2
  • 13

2 Answers2

2

Yes, you are in that situation. If you have source in more than one .c or .cpp file then you need to compile all of them and link all the resulting .o files.

Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
1

You have to have all the object files before the linker does the linking and makes the executable. If you are using gcc,

gcc -o executablename filename1.c filename2.c filename3.c 

will compile all the files and will do the linking, which will result in a final executable named "executablename".

DesirePRG
  • 6,122
  • 15
  • 69
  • 114
  • I am using Visual Studio 2012, how can I do that? – Bao Doan Apr 27 '14 at 11:57
  • if all your files are under the same project,Visual Studio does the compiling and linking automatically when you build the project. – DesirePRG Apr 27 '14 at 17:11
  • Sometimes the functions you have declared may not have been implemented. Check your source code just to make sure. – DesirePRG Apr 27 '14 at 17:12
  • I thought that when I `include "des.h"`, the compiler will understand? I also try to add the `des.c` and `des.h` into the project but no thing happens – Bao Doan Apr 28 '14 at 03:37
  • yes headers(.h files) are where your declarations should be in. in .h files you don't define the functions. the definitions should be in the corresponding .c file. http://www.cplusplus.com/forum/articles/10627/ – DesirePRG Apr 28 '14 at 14:30
  • @BaoDoan Then please tag it appropriately that you are in visual studio – UpAndAdam May 02 '14 at 14:23