Author Topic: "undefined reference" error with basic code  (Read 3914 times)

Offline geohei

  • Single posting newcomer
  • *
  • Posts: 7
"undefined reference" error with basic code
« on: December 11, 2019, 12:40:41 pm »
Hi.

This is driving me nuts!
I'm not sure if this is Code::Blocks related !!!
If not, just tell me, and I dig further (since this is no general programming forum) !!!

Code
#include <stdio.h>
#include <stdlib.h>
#include <openssl/des.h>

DES_cblock Key1 = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };
DES_cblock Key2 = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 };
DES_cblock Key3 = { 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33 };
DES_key_schedule SchKey1,SchKey2,SchKey3;

int main() {

    printf("key check = %i\n", DES_set_key_checked(&Key1, &SchKey1));
    return 0;

}

openssl and libssl-dev are installed!

I get ...

Code
||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
obj/Debug/main.o||In function `main':|
/home/geohei/Desktop/programming/test/main.c|68|undefined reference to `DES_set_key_checked'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

What do I miss in Code::Blocks (if related)?
« Last Edit: December 11, 2019, 02:14:28 pm by geohei »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: "undefined reference" error with basic code
« Reply #1 on: December 11, 2019, 04:12:40 pm »
You should link with the library containing DES_set_key_checked(), probably called libdes.a

Offline geohei

  • Single posting newcomer
  • *
  • Posts: 7
Re: "undefined reference" error with basic code
« Reply #2 on: December 12, 2019, 01:46:11 pm »
I hardly dare to say what it was ...
I added -lcrypt i.s.o. -lcrypto to the linker option.
Shame ...