0

我使用以下命令在我的系统上安装了 libmcrypt:-

avinash@ak-pc:~/Documents/network_lab/tut7$ cd libmcrypt-2.5.8
avinash@ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ ./configure --prefix=/usr --disable-posix-threads
avinash@ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ make
avinash@ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ sudo make install

结果,标头转到 /usr/include,而库转到 /usr/lib。现在,当我将 <mcrypt.h> 包含到 .cpp 文件中并使用 libmcrypt 提供的函数时,编译器会宣布

/tmp/ccCot4nH.o: In function `main':
q3.cpp:(.text+0x64): undefined reference to `mcrypt_module_open'
q3.cpp:(.text+0xb9): undefined reference to `mcrypt_generic_init'
q3.cpp:(.text+0xd6): undefined reference to `mcrypt_generic'
q3.cpp:(.text+0x110): undefined reference to `mdecrypt_generic'
q3.cpp:(.text+0x13a): undefined reference to `mcrypt_generic_deinit'
q3.cpp:(.text+0x147): undefined reference to `mcrypt_module_close'
collect2: ld returned 1 exit status

谁能告诉我问题出在哪里?安装过程有问题吗?

4

1 回答 1

2

包含库的头文件仅提供声明,以便编译器了解函数签名和全局变量类型,但您还需要向链接器指示您的程序要动态链接的库。

对于大多数编译器,使用-l标志后跟库名称,不带lib前缀。例如,您的链接命令可能如下所示:

g++ -o myprogram obj1.o obj2.o ... obj.o -lmcrypt
于 2013-10-24T07:39:14.107 回答