【问题标题】:How do you include external libraries when you cross-compile c programs using mingw?使用 mingw 交叉编译 c 程序时如何包含外部库?
【发布时间】:2021-06-20 17:29:22
【问题描述】:

我正在使用 C 语言在 Linux 机器上使用 ncurses library 构建一个简单的命令行游戏,但我希望能够在 Windows 计算机上运行编译后的代码。为此,我在 Linux 中使用MinGW-w64 cross compiler 工具并将其编译为在 64 位 Windows 环境中运行。但是,当我尝试使用此命令进行编译时:

x86_64-w64-mingw32-gcc -o game.exe barebones.c -lncurses

我收到此错误:

barebones.c:2:10: fatal error: ncurses.h: No such file or directory
2 | #include <ncurses.h>
  |          ^~~~~~~~~~~
compilation terminated.

我在我的 Ubuntu 机器上安装了 ncurses,并且可以创建和运行相同的简单程序以在 Linux 上运行。我已经能够交叉编译和运行只使用默认库的简单程序。我想我一定是在编译命令中错误地列出了 ncurses 库,或者我无法理解其他表明这不起作用的帖子。

我使用的是 Windows 10 和 Ubuntu 21.04。

【问题讨论】:

  • 您是如何指定使用交叉编译器构建的 ncurses 的位置的?

标签: c gcc cross-compiling ncurses mingw-w64


【解决方案1】:

Debian 没有为 ncurses 提供交叉编译包。 (Ubuntu 没有以任何方式对 ncurses 进行任何添加或改进,只是重用来自 Debian 的软件包)。如果要交叉编译 ncurses,则必须以交叉编译的形式构建 ncurses。

出于开发目的,可以使用(源)packages 目录下的脚本构建 ncurses 包,例如,在下载 current source 之后:

tar xf ncurses-whatever.tgz
cd ncurses-whatever
cp -var packages/debian-mingw64 ./debian
dpkg-buildpackage

这是一个起点。您必须对 debian/control 文件中的电子邮件做点什么来安抚dpkg-buildpackage(教程离题)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多