问题描述
主要明显错误"Undefined symbols for architecture x86_64
"
操作系统是Mac OSX.已从安装了多个程序他们的来源.安装后发现了问题:
The Operating System is Mac OS X. Have installed multiple programs fromtheir sources. Noticed the problem after having installed:
-
binutils
v2.25 , -
libtool
v2.4.6 , -
glib
v2.45.2 ,或 -
pkgconfig
v0.28
binutils
v2.25,libtool
v2.4.6,glib
v2.45.2, ORpkgconfig
v0.28
在安装上述任何文件之前,请重新编译libiconv
和gettext
不会产生任何错误,并且都已成功安装了多次.
Before installing any of the above, recompiling libiconv
and gettext
produced no errors and both successfully installed multiple times.
pkg-config --list-all
不显示libiconv
或gettext
(如果有任何重要意义的话)
pkg-config --list-all
does not display libiconv
nor gettext
(if that at all means anything significant)
libiconv
和gettext
是它们各自站点的直接副本.
libiconv
and gettext
are direct copies from theiy're respective sites.
http://www.gnu.org/software/libiconv/#downloading
iconv --version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.
http://ftp.gnu.org/pub/gnu/gettext/
gettext --version
gettext (GNU gettext-runtime) 0.19.5.1
Copyright (C) 1995-1997, 2000-2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Ulrich Drepper.
libiconv
v1.14
尝试在简单的.c
文件中使用libiconv
:
libiconv
v1.14
Trying to use libiconv
in a simple .c
file:
#include <iconv.h>
// works: gcc -m32 -I/usr/local/include -liconv -o test-iconv.exe test-iconv.c
// does NOT work: gcc -I/usr/local/include -liconv -o test-iconv.exe test-iconv.c
int main(int argc, char **argv) {
iconv_t conv = iconv_open("ISO8859-1", "UTF-8");
if (conv != (iconv_t) -1) {
return 0;
}
return 1;
}
如果我没有为gcc
指定-m32
,那么我会收到以下错误:
If I do not specify -m32
for gcc
then I received the following error:
$ gcc -I/usr/local/include -liconv -o test-iconv.exe test-iconv.c
Undefined symbols for architecture x86_64:
"_libiconv_open", referenced from:
_main in ccr9tTic.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
尝试重新编译libiconv
Attempting to recompile libiconv
libiconv-1.14 $ make distclean; ./configure --enable-extra-encodings \
--with-libiconv-prefix=/usr/local/include; make V=1
...
...
...
gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I.. -I../lib -I../intl \
-DDEPENDS_ON_LIBICONV=1 -D DEPENDS_ON_LIBINTL=1 -I/usr/local/include \
-g -O2 -c strerror-override.c
rm -f libicrt.a
ar cru libicrt.a allocator.o areadlink.o careadlinkat.o malloca.o progname.o \
safe-read.o width.o xmalloc.o xstrdup.o xreadlink.o canonicalize-lgpl.o \
error.o lstat.o readlink.o stat.o strerror.o strerror-override.o
ranlib libicrt.a
cd src && make all
gcc -c -I. -I. -I.. -I../include -I./../include -I../srclib -I./../srclib \
-I../lib -g -O2 -I/usr/local/include -DINSTALLDIR=\"/usr/local/bin\" \
-DLOCALEDIR=\"/usr/local/share/locale\" ./iconv_no_i18n.c
/bin/sh ../libtool --mode=link gcc -g -O2 iconv_no_i18n.o \
../srclib/libicrt.a ../lib/libiconv.la -o iconv_no_i18n
libtool: link: gcc -g -O2 iconv_no_i18n.o -o .libs/iconv_no_i18n \
../srclib/libicrt.a ../lib/.libs/libiconv.dylib
ld: warning: ignoring file ../srclib/libicrt.a, file was built for archive
which is not the architecture being linked (x86_64): ../srclib/libicrt.a
Undefined symbols for architecture x86_64:
"_program_name", referenced from:
_main in iconv_no_i18n.o
_usage in iconv_no_i18n.o
_error in iconv_no_i18n.o
"_rpl_strerror", referenced from:
_error in iconv_no_i18n.o
"_safe_read", referenced from:
_convert in iconv_no_i18n.o
"_set_program_name", referenced from:
_main in iconv_no_i18n.o
"_uc_width", referenced from:
_update_line_column in iconv_no_i18n.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [iconv_no_i18n] Error 1
make: *** [all] Error 2
来自lipo
的信息:
architecture being linked (x86_64): ../srclib/libicrt.a
Information from lipo
:
architecture being linked (x86_64): ../srclib/libicrt.a
libiconv-1.14 $ lipo -info srclib/libicrt.a
input file srclib/libicrt.a is not a fat file
Non-fat file: srclib/libicrt.a is architecture: x86_64
gettext
v0.19.5.1
gettext
v0.19.5.1
gettext-0.19.5.1 $ make distclean; ./configure; make V=1
...
...
...
libtool: link: ( cd ".libs" && rm -f "libgnu.la" && ln -s "../libgnu.la" \
"libgnu.la" )
Making all in src
gcc -DLOCALEDIR=\"/usr/local/share/locale\" -DHAVE_CONFIG_H -I. -I.. -I. \
-I. -I.. -I../intl -I./../intl -I../gnulib-lib -I./../gnulib-lib \
-I/usr/local/include -DINSTALLDIR=\"/usr/local/bin\" -g -O2 -c -o \
gettext-gettext.o `test -f 'gettext.c' || echo './'`gettext.c
/bin/sh ../libtool --tag=CC --mode=link gcc \
-DINSTALLDIR=\"/usr/local/bin\" -g -O2 -o gettext gettext-gettext.o \
../gnulib-lib/libgrt.a ../intl/libintl.la -L/usr/local/lib -liconv \
-R/usr/local/lib -Wl,-framework -Wl,CoreFoundation -L/usr/local/lib \
-liconv -R/usr/local/lib
libtool: link: gcc -DINSTALLDIR=\"/usr/local/bin\" -g -O2 -o .libs/gettext \
gettext-gettext.o -Wl,-framework -Wl,CoreFoundation \
../gnulib-lib/libgrt.a ../intl/.libs/libintl.dylib -L/usr/local/lib \
-lc /usr/local/lib/libiconv.dylib
ld: warning: ignoring file ../gnulib-lib/libgrt.a, file was built for archive
which is not the architecture being linked (x86_64): ../gnulib-lib/libgrt.a
Undefined symbols for architecture x86_64:
"_close_stdout", referenced from:
_main in gettext-gettext.o
"_error", referenced from:
_main in gettext-gettext.o
"_gnu_basename", referenced from:
_main in gettext-gettext.o "_program_name", referenced from:
_main in gettext-gettext.o
_usage in gettext-gettext.o
"_proper_name", referenced from:
_main in gettext-gettext.o
"_rpl_getopt_long", referenced from:
_main in gettext-gettext.o
"_rpl_optarg", referenced from:
_main in gettext-gettext.o
"_rpl_optind", referenced from:
_main in gettext-gettext.o
"_set_program_name", referenced from:
_main in gettext-gettext.o
"_xmalloc", referenced from:
_expand_escape in gettext-gettext.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[4]: *** [gettext] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
来自lipo
的信息 architecture being linked (x86_64): ../gnulib-lib/libgrt.a
Information from lipo
architecture being linked (x86_64): ../gnulib-lib/libgrt.a
gettext-0.19.5.1 $ lipo -info gettext-runtime/gnulib-lib/libgrt.a
input file gettext-runtime/gnulib-lib/libgrt.a is not a fat file
Non-fat file: gettext-runtime/gnulib-lib/libgrt.a is architecture: x86_64
推荐答案
可能是您安装了gcc和ar的替代版本,并且它们位于标准位置(/usr/bin)之前的路径中.
It could be that you have alternative versions of gcc and ar installed and that they are in your path before the standard locations (/usr/bin).
过去我也遇到过同样的问题,这篇文章帮助我进行了故障排除和修复: https://www.unix.com/programming/253809-linker-errors-linking-files-os-x.html
I've had the same problem in the past and this post helped me troubleshoot and fix: https://www.unix.com/programming/253809-linker-errors-linking-files-os-x.html
这篇关于重新编译libiconv,在成功安装后出现gettext未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!