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

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

问题描述

我正在尝试在Debian 64位上编译和链接一个32位应用程序,但是在链接时无效。



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



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



这似乎有效。



然后我链接以下命令:



gcc -m32 -lcurses $ ^ -o $ @



此失败并提供以下错误:

  / usr / bin / ld:跳过不兼容/ usr / lib / gcc / x86_64-linux-gnu / 4.4.5 /../../../ libcurses.so在搜索-lcurses 
/ usr / bin / ld时跳过不兼容/ usr / lib /gcc/x86_64-linux-gnu/4.4.5/../../../libcurses.a在搜索-lcurses
/ usr / bin / ld时:跳过不兼容/ usr / lib / libcurses。所以当搜索-lcurses
/ usr / bin / ld时:在搜索-lcurses
/ usr / bin / ld时跳过不兼容的/usr/lib/libcurses.a:找不到-lcurses
collect2:ld返回1退出状态

我迄今为止所尝试的(我找到的常见解决方案网络上的其他地方是:




  • 安装 gcc-multilib

  • 安装 lib32ncurses5 lib32ncurses6dev

  • 将选项 -L / usr / lib32 添加到链接命令



令人遗憾的是,这些都没有工作到目前为止。
任何帮助将非常受赞赏,因为我的想法不足。我最后的手段是使用32位系统,但如果可能,我想避免这种情况。

解决方案

问题:


  1. 您的链接命令不正确:链接行上的库的顺序事项。命令应该是: gcc -m32 $ ^ -o $ @ -lcurses

  2. 因为你想再次链接ncurses ,最后一个参数 -lncurses


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

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

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

This seems to work.

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:

  • installing gcc-multilib
  • installing lib32ncurses5 and lib32ncurses6dev
  • adding the option -L/usr/lib32 to the link command

Sadly, none of these has worked so far. Any help would be really appreciated, as 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.

解决方案

There are two problems:

  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 agains ncurses, make the last argument -lncurses.

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

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