我创建了一个使用libmcrypt的C程序。我在CentOS机器中编译了很多次,但是现在,为了在Ubuntu中做同样的事情,我得到了以下内容:
/tmp/ccM2ugbq.o: In function `encrypt':
util.c:(.text+0xa1): undefined reference to `mcrypt_module_open'
util.c:(.text+0xc6): undefined reference to `mcrypt_enc_get_iv_size'
util.c:(.text+0x134): undefined reference to `mcrypt_generic_init'
util.c:(.text+0x1dc): undefined reference to `mcrypt_generic'
util.c:(.text+0x1fa): undefined reference to `mcrypt_module_close'
/tmp/ccM2ugbq.o: In function `decrypt':
util.c:(.text+0x288): undefined reference to `mcrypt_module_open'
util.c:(.text+0x296): undefined reference to `mcrypt_enc_get_iv_size'
util.c:(.text+0x304): undefined reference to `mcrypt_generic_init'
util.c:(.text+0x375): undefined reference to `mdecrypt_generic'
util.c:(.text+0x380): undefined reference to `mcrypt_module_close'
,尽管我已经安装了libmcrypt并在编译时正确地扩展了标志(-I/usr/include -L/usr/lib -lmcrypt)
有人能指导我如何使用libmcrypt正确地完成编译工作吗?
编辑:手册页上写着:根据安装的不同,编译为"cc prin.c -lmcrypt“或"cc pr.c -lmcrypt -lltdl”。我还安装了libltdl-dev,但它不起作用。
编辑1:系统信息:版本(运行uname -r
):
3.5.0-25-generic
发布(运行lsb_release -a
):
没有LSB模块可用。 发行商ID: Ubuntu 描述: Ubuntu 12.10 释放: 12.10 代号: quantal
编辑2:
因为@teppic要求我显示编译命令,所以我解决了我的问题,但我需要一些解释。贝娄,我将详细介绍这个主题:
我使用并失败的命令:
cc -Wall -i./path/to/包括-lmcrypt ./a_file.c ./-lmcrypt/其他/file.c./若干/其他/files.c ./main/file.c ./main/file.c -I/some/include/path -lother_lib -o ./bin/out
在那之后,我只把-lmcrypt
放在命令的末尾,并从一开始就删除了它,它起了作用。在我的第一个问题中,我告诉过您,我以前确实用CentOS编译过它,而且一切都很好。这是正确的,即使在CentOS中编译命令是前一个命令(可能有些文件的顺序不同或某些库)。
有人能解释一下旗帜顺序如何影响编译的成败吗?
发布于 2013-03-12 10:27:56
通常,您应该将库依赖项放在命令行中引用它的源文件之后。在gcc的老版本中,情况并不总是如此。
发布于 2013-03-12 07:22:20
( 1)尝试安装libmcrypt dev 2)使用" Locate“命令定位libmcrypt的路径(如果不在标准库路径中,则尝试将路径添加到LD_LIBRARY_PATH环境变量4),如果没有任何帮助,则使用"yum install mcrypt-devel”重新安装。
https://stackoverflow.com/questions/15355114
复制相似问题