Linux gcc编译error:"collect2: ld returned 1 exit status"

在Linux环境下编一个工程,无论怎么编译总是出现错误,提示如下:
bmeta_info.cpp:4280: undefined reference to `crypt’
collect2: ld returned 1 exit status

网上查的资料表示:

Undefined reference to 错误:这类错误是在连接过程中出现的,可能有两种原因∶一是使用者自己定义的函数或者全局变量所在源代码文件,没有被编译、连接,或者干脆还没有定义,这 需要使用者根据实际情况修改源程序,给出全局变量或者函数的定义体;二是未定义的符号是一个标准的库函数,在源程序中使用了该库函数,而连接过程中还没有 给定相应的函数库的名称,或者是该档案库的目录名称有问题

使用 man crypt命令后从中找到如下信息:

GNU EXTENSION
       The glibc2 version of this function has the following additional features.  If salt is a character string starting with the three characters "$1$" followed by at most eight characters, and optionally terminated by "$", then instead of using  the  DES  machine, the  glibc crypt function uses an MD5-based algorithm, and outputs up to 34 bytes, namely "$1$<string>$", where "<string>" stands for the up to 8 characters following "$1$" in the salt, followed by 22 bytes chosen from the set [a–zA–Z0–9./].  The entire key is significant here (instead of only the first 8 bytes).
       Programs using this function must be linked with -lcrypt.

最重要的是最后一句”Programs using this function must be linked with -lcrypt.”,即链接需要加入-lctypt
解决方法:g++ -lcrypt XXXX

【参考:http://blog.sina.com.cn/s/blog_64c238860100wzoo.html

系统: CentOS6.5 ,Python3.6 安装 mysqlclient 时候 报错:error: command 'gcc' failed with exit status 1 以下是错误信息: Collecting mysqlclient Using cached mysqlclient-1.3.10.tar.gz Installing collected packages: mysqlclient Running setup.py install for mysqlclient ... error Complete output from command /usr/local/python3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-t3olsi0s/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-oqq8k4wv-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build/lib.linux-x86_64-3.6 copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.6 creating build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb creating build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.linux-x86_64-3.6 gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,3,10,'final',0) -D__version__=1.3.10 -I/usr/include/mysql -I/usr/local/python3/include/python3.6m -c _mysql.c -o build/temp.linux-x86_64-3.6/_mysql.o -g -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing In file included from /usr/local/python3/include/python3.6m/Python.h:8, from _mysql.c:40: /usr/local/python3/include/python3.6m/pyconfig.h:600:1: warning: "HAVE_MBRTOWC" redefined In file included from _mysql.c:29: /usr/include/mysql/my_config.h:439:1: warning: this is the location of the previous definition gcc -pthread -shared build/temp.linux-x86_64-3.6/_mysql.o -L/usr/lib64 -lmysqlclient -lpthread -lm -lrt -ldl -o build/lib.linux-x86_64-3.6/_mysql.cpython-36m-x86_64-linux-gnu.so /usr/bin/ld: cannot find -lmysqlclient collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 ---------------------------------------- Command "/usr/local/python3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-t3olsi0s/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-oqq8k4wv-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-t3olsi0s/mysqlclient/ 按照别的帖子 yum install 了 python-devel了还是一样..而且 安装的python-devel的version 是2.6.6的 跟我的Python版本不符,但是yum仓库里又没有 3.6的 python-devel 如何解决?菜鸡求助...
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页