2

我安装了polarssl:

  1. 制作
  2. 须藤使安装

试图编译非常简单的文件,名为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;
}

像这样编译它:

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

但它告诉我:

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

什么问题,如何解决?我 100% 知道 polarssl 文件在/usr/local/include/polarssl/

4

2 回答 2

4

编译器将尝试按照对象或文件的呈现顺序完成链接。在这种情况下,由于您首先放置-lpolarssl,因此该库中不需要未解析的符号,因此没有任何链接。

放在-lpolarssl最后让编译器从该库的源文件中解析未解析的符号。

于 2013-06-27T17:13:36.790 回答
2

包括很好。

但是链接是错误的。尝试将-lpolarssl最后一个放在链接器命令中。

然后添加一个-Lif libpolarssl.a is not found by the linker 以将其指向正确的位置。

于 2013-06-27T17:11:58.553 回答