在 Debian 64 位上编译和链接 32 位应用程序 [英] Compiling and linking a 32 bit application on Debian 64 bit

查看:37
本文介绍了在 Debian 64 位上编译和链接 32 位应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在我的 Debian 64 位上编译和链接 32 位应用程序,但它在链接时失败.

I am currently trying to compile and link a 32 bit application on my Debian 64 bit, but it fails at link time.

我使用(在我的 Makefile 中)编译的命令是:

The command I'm using (in my Makefile) to compile is:

gcc -Os -m32 -Wall -g -c $< -o $@

这似乎有效.

然后我用以下命令链接:

Then I link with the following command:

gcc -m32 -lcurses $^ -o $@

这失败并给出以下错误:

This fails and gives the following errors:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libcurses.so when searching for -lcurses
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libcurses.a when searching for -lcurses
/usr/bin/ld: skipping incompatible /usr/lib/libcurses.so when searching for -lcurses
/usr/bin/ld: skipping incompatible /usr/lib/libcurses.a when searching for -lcurses
/usr/bin/ld: cannot find -lcurses
collect2: ld returned 1 exit status    

到目前为止我尝试过的(我在网上其他地方找到的通常解决方案)是:

What I've tried so far (usual solutions that I found elsewhere on the web) is:

  • 安装 gcc-multilib
  • 安装 lib32ncurses5lib32ncurses6dev
  • 在链接命令中添加选项-L/usr/lib32

遗憾的是,到目前为止,这些都没有奏效.我的想法不多了.我最后的手段是使用 32 位系统,但如果可能的话,我想避免这种情况.

Sadly, none of these has worked so far. I am running out of ideas. My last resort would be using a 32 bit system, but I'd like to avoid that if possible.

推荐答案

有两个问题:

  1. 您的链接命令不正确:链接行上的库顺序很重要.命令应该是:gcc -m32 $^ -o $@ -lcurses
  2. 既然你想链接到 ncurses,那么最后一个参数是 -lncurses.
  1. Your link command is incorrect: the order of libraries on the link line matters. The command should be: gcc -m32 $^ -o $@ -lcurses
  2. Since you want to link against ncurses, make the last argument -lncurses.

这篇关于在 Debian 64 位上编译和链接 32 位应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆