Question

I installed polarssl:

  1. make
  2. sudo make install

tried to compile very simple file, named test.c:

#include <stdio.h>
#include "polarssl/md5.h"

int main(int argc, char * argv[])
{
  int i;
  for (i=1;i<1;i++)
  {
    char res[16];
    if (md5_file("file.txt",res) == 0)
    {
      int count;
      for (count=0;count<16;count++)
        printf("%02x",res[count]);
      printf("n");
    }
  }
  return 0;
}

Compiled it like this:

gcc -lpolarssl test.c -I /usr/local/include/polarssl/

but it shows me:

/tmp/cczptlsk.o: In function `main':
test.c:(.text+0x36): undefined reference to `md5_file'
collect2: ld returned 1 exit status

whats the problem, how to fix it? I know for 100% that polarssl files are in /usr/local/include/polarssl/

Was it helpful?

Solution

The compiler will attempt to complete linkage in the order the objects or files are presented. In this case, since you had put -lpolarssl first, there were no unresolved symbols needed from that library, so nothing got linked in.

Putting -lpolarssl last lets the compiler resolve unresolved symbols from your source file from that library.

OTHER TIPS

Includes are fine.

But linking is wrong. Try to put the -lpolarssl last in the linker command.

Then add a -L if libpolarssl.a is not found by the linker to point it to the right location.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top