1

I am trying to make a program that uses mbedtls but I am having trouble getting the gcc command to work properly.

main.c
thpool.c
thpool.h

mbedtls[Folder]
    all the .h files of mbedtls
library[Folder]
    all the .c and .o files of mbedtls

I current compile this program with the command..

gcc main.c thpool.c -pthread -o main

But since I have added a mbedtls function and code, it gives me the error..

/usr/bin/ld: /tmp/ccNV32fk.o: in function `p': main.c:(.text+0x105): undefined reference to `mbedtls_aes_setkey_enc' collect2: error: ld returned 1 exit status

I am unsure how to link these other files correctly.

Doritos
  • 403
  • 3
  • 16
  • If that command you are showing runs correctly this means that you *do not* need to link other files. Either you are explaining it wrong or you missed something. – Marco Bonelli Jan 13 '20 at 18:18
  • sorry forgot some information. updated post. – Doritos Jan 13 '20 at 18:22
  • You're not actually giving `gcc` any information about accessing mbedtls. The most straightforward way is to compile `mbedtls` (or download a package with your distro) and link against with `-lmbedtls`. – Dan Fego Jan 13 '20 at 18:25
  • 1
    You probably also need the files in the `library` folder and the headers in the `mbedtls` folder. `gcc -o main -lpthread -I mbedtls main.c thpool.c library/*.c` or something similar. Not sure why you also have `.o` files in that `library` folder. Where are those from? What are you trying to do exactly with those? This is all pretty confusing. As @DanFego says, the easiest way is to install `libmbedtls-dev` and just add `-lmbedtls`. – Marco Bonelli Jan 13 '20 at 18:29
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – KamilCuk Jan 13 '20 at 18:33
  • On my system, `mbedtls_aes_setkey_enc` is not part of the libmbedtls.so, but of libmbedcrypto.so. Therefore, the compiler flag `-lmbedcrypto` is needed. – f9c69e9781fa194211448473495534 Sep 01 '20 at 18:20

0 Answers0