我在 64 位 Ubuntu 中编译 32 位 ELF 时遇到了问题。这是 GCC 编译器生成的错误消息:
cheap-laptop@my-machine:~/DEV-DIR$ gcc -m32 test.c -o test
In file included from /usr/include/stdio.h:27:0,
from test.c:1:
/usr/include/features.h:374:25: fatal error: sys/cdefs.h: No such file or directory
# include <sys/cdefs.h>
^
compilation terminated.
我在Google上搜索了这个问题,发现libc6-dev-i386
必须先安装。
我安装了它,但没有成功,仍然出现同样的错误。所以我再次使用 Google,找到了这个关联。
它建议删除 purgelibc6-dev
并使用 重新安装apt-get
。然后,出现了一些消息,如下所示:-
cheap-laptop@my-machine:~/DEV-DIR$ sudo apt-get purge libc6-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gir1.2-gee-0.8 gir1.2-gtk-2.0 icu-devtools libboost-atomic1.54.0
libboost-chrono1.54.0 libboost-context1.54.0 libboost-filesystem1.54.0
libboost-graph-parallel1.54.0 libboost-graph1.54.0 libboost-iostreams1.54.0
libboost-locale1.54.0 libboost-log1.54.0 libboost-math1.54.0
libboost-mpi-python1.54.0 libboost-mpi1.54.0 libboost-program-options1.54.0
libboost-python1.54.0 libboost-random1.54.0 libboost-regex1.54.0
libboost-serialization1.54.0 libboost-signals1.54.0 libboost-test1.54.0
libboost-thread1.54.0 libboost-timer1.54.0 libboost-tools-dev
libboost-wave1.54.0 libboost1.54-tools-dev libcairo-script-interpreter2
libdbus-1-dev libgnutlsxx27 libgpg-error-dev libgssrpc4 libharfbuzz-dev
libharfbuzz-gobject0 libibverbs-dev libice-dev libidn11-dev
libkadm5clnt-mit9 libkadm5srv-mit9 libkdb5-7 libp11-kit-dev libpcrecpp0
libpixman-1-dev libpthread-stubs0-dev libsm-dev libssl-doc libtasn1-6-dev
libtinfo-dev libvala-0.22-0 libx11-dev libxau-dev libxcb-render0-dev
libxcb-shm0-dev libxcb1-dev libxcomposite-dev libxcursor-dev libxdamage-dev
libxdmcp-dev libxext-dev libxfixes-dev libxi-dev libxinerama-dev
libxml2-utils libxrandr-dev libxrender-dev mpi-default-bin valac-0.22-vapi
x11proto-composite-dev x11proto-randr-dev x11proto-render-dev
x11proto-xinerama-dev
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
comerr-dev* gcc-4.9-multilib* gcc-multilib* krb5-multidev* libatk1.0-dev*
libboost-all-dev* libboost-atomic-dev* libboost-atomic1.54-dev*
libboost-chrono-dev* libboost-chrono1.54-dev* libboost-context-dev*
libboost-context1.54-dev* libboost-coroutine-dev*
libboost-coroutine1.54-dev* libboost-date-time-dev*
libboost-date-time1.54-dev* libboost-dev* libboost-exception-dev*
libboost-exception1.54-dev* libboost-filesystem-dev*
libboost-filesystem1.54-dev* libboost-graph-dev*
libboost-graph-parallel-dev* libboost-graph-parallel1.54-dev*
libboost-graph1.54-dev* libboost-iostreams-dev* libboost-iostreams1.54-dev*
libboost-locale-dev* libboost-locale1.54-dev* libboost-log-dev*
libboost-log1.54-dev* libboost-math-dev* libboost-math1.54-dev*
libboost-mpi-dev* libboost-mpi-python-dev* libboost-mpi-python1.54-dev*
libboost-mpi1.54-dev* libboost-program-options-dev*
libboost-program-options1.54-dev* libboost-python-dev*
libboost-python1.54-dev* libboost-random-dev* libboost-random1.54-dev*
libboost-regex-dev* libboost-regex1.54-dev* libboost-serialization-dev*
libboost-serialization1.54-dev* libboost-signals-dev*
libboost-signals1.54-dev* libboost-system-dev* libboost-system1.54-dev*
libboost-test-dev* libboost-test1.54-dev* libboost-thread-dev*
libboost-thread1.54-dev* libboost-timer-dev* libboost-timer1.54-dev*
libboost-wave-dev* libboost-wave1.54-dev* libboost1.54-dev* libc6-dev*
libc6-dev-i386* libc6-dev-x32* libcairo2-dev* libcurl4-openssl-dev*
libdbus-glib-1-dev* libdbusmenu-glib-dev* libdee-dev* libexpat1-dev*
libfontconfig1-dev* libfreetype6-dev* libgcrypt11-dev* libgdk-pixbuf2.0-dev*
libgee-0.8-dev* libglib2.0-dev* libgnutls-dev* libgpgme11-dev*
libgtk2.0-dev* libhwloc-dev* libicu-dev* libkrb5-dev* libncurses5-dev*
libncursesw5-dev* libnotify-dev* libopenmpi-dev* libpango1.0-dev*
libpcap-dev* libpcap0.8-dev* libpci-dev* libpcre3-dev* libpng12-dev*
libpython-dev* libpython2.7-dev* librtmp-dev* libsqlite3-dev* libssh-dev*
libssh2-1-dev* libssl-dev* libstdc++-4.8-dev* libunity-dev* libxft-dev*
mpi-default-dev* nvidia-331* python2.7-dev* uuid-dev* valac-0.22*
zlib1g-dev*
0 upgraded, 0 newly installed, 107 to remove and 0 not upgraded.
After this operation, 506 MB disk space will be freed.
Do you want to continue? [Y/n]
它想删除诸如libboost-*
、nvidia-331*
等重要软件包。为什么会发生这种情况?
答案1
软件包libc6-dev
是编译任何东西所必需的,因此大多数(如果不是全部)开发软件包libc6-dev
都依赖于该软件包。如果您删除,那么这些标头也会被删除(如果没有其他东西依赖于这些库并且已自动安装,则一些库本身也会被删除)。
删除并重新安装此软件包可能不会帮助您从 64 位 Ubuntu 编译 32 位程序,因为此软件包用于编译 64 位程序。相反,请确保已libc6-dev-i386
安装。如果您仍然收到错误,请创建新问题并在那里发布错误消息。
答案2
经过几分钟的搜索,我发现了这个回答在 Stack Overflow 网站内。
所以我的问题的解决方案是,只需install --reinstall [package-name]
在运行时使用参数apt-get
,它就会重新安装您想要的包而不会清除并重新下载,所以这里是解决我的问题的完整命令:
sudo apt-get install --reinstall libc6-dev-i386