为什么我的交叉编译失败? [英] Why does my cross-compiling fail?

查看:202
本文介绍了为什么我的交叉编译失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Linux编程的新手,我正在尝试编译一个包含GTK +库的c文件。我的文件名为 test.c ,应该在Windows计算机上运行。我正在使用以下命令:

I'm new to Linux programming and I'm trying to compile a c file including the GTK+ library. My file is called test.c and it's supposed to run on Windows computers. I'm using the command:

i586-mingw32msvc-gcc `pkg-config --cflags gtk+-3.0` -o test test.c `pkg-config --libs gtk+-3.0`

我遇到了一个严重的错误,我试图找出自己出了什么问题,但没有弄明白这里发生了什么。

I get an awful error, I tried to figure out what went wrong by myself but didn't manage to understand what's going on here.

这是输出:

推荐答案

您几乎可以确定正在运行 pkg-config 与主机元数据文件一起使用,这样的输出可能会使您的交叉编译器,erm,交叉。

You're almost certainly running pkg-config with the host metadata files, such output will likely make your cross-compiler, erm, cross.

尝试本教程,它说明了如何执行所需的操作,首先下载所需的GTK + -3.0 win32二进制文件,然后设置Linux环境,以使 pkg-config 拾取目标元数据文件:

Try this tutorial, it explains how to do what you want starting with downloading the required GTK+-3.0 win32 binaries, and setting up your linux environment so that pkg-config picks up the target metadata files:

http://www.tarnyko.net/en/?q=node/45

pkg-config 为一个程序提供了一种直接的方法来确定编译器和链接器的要求,以及该程序使用的库的任何依赖库。它还使 autoconf (和用户)更容易确定特定软件包的存在,版本和依赖关系。您的示例正在使用:

The job of pkg-config is to provide a straightforward way for one program to determine the compiler and linker requirements, and any dependent libraries for a library it uses. It also makes it easier for autoconf (and the user) to determine the presence, version and dependencies of specific packages. Your examples are using:

pkg-config --cflags gtk+-3.0
pkg-config --libs gtk+-3.0

这些将输出使用gtk + -3.0的程序所需的编译器和库标志。假设您在系统上安装了本机版本,则默认输出仅适用于您的系统类型(路径,库名称,从属库等)。

Those will output the compiler and library flags that a program using gtk+-3.0 needs. Assuming you have a native version installed on your system, the default output will be suitable only for your type of system (paths, library names, dependent libraries etc).

交叉编译的诀窍是拥有一个单独的源树,.pc(pkg-config元数据),库和头文件(针对每个目标体系结构) )。在配置/编译过程中运行 pkg-config 时,可以像上面的教程中那样设置 PKG_CONFIG_PATH 以便进行选择针对目标体系结构的正确 .pc 文件。

The trick with cross-compiling is to have a separate tree of source, .pc (pkg-config meta-data), libraries and header files (for each targeted architecture). When you run pkg-config during configure/compile, you can set PKG_CONFIG_PATH as in the tutorial above so it picks up the correct .pc files for the targeted architecture.

这里有一个小熊陷阱: PKG_CONFIG_PATH 添加到搜索路径,因此如果您尚未在目标树中安装所需的软件,但是安装了本机版本,它仍然可以使用错误的软件包详细信息。通常,应设置 PKG_CONFIG_LIBDIR ,这将替换默认路径(通常为 / usr / lib / pkgconfig )。这样,当您交叉编译使用autoconf(配置脚本)的更精巧的东西时,您(希望)可以对丢失的软件包进行明智的诊断,而不是让轮子从中间掉下来

There's a little bear trap here though: PKG_CONFIG_PATH adds to the start of the search path, so it can still fall back to the wrong package details if you have not installed the required software into your target tree, but you have a "native" version installed. You should usually set PKG_CONFIG_LIBDIR instead, this replaces the default path (typically /usr/lib/pkgconfig). That way when you cross-compile something more elaborate that uses autoconf (configure scripts) you (hopefully) get a sensible diagnostic about missing packages, rather than having the wheels come off mid-way through the compile.

例如,我可以使用它列出 just 我在一棵交叉编译树中拥有的OpenWRT MIPS软件包:

For example, I can use this to list just the OpenWRT MIPS packages I have in one cross-compile tree:

WRTROOT=/openwrt/staging_dir/target-mips_r2_uClibc-0.9.32/
PKG_CONFIG_PATH=  PKG_CONFIG_LIBDIR=${WRTROOT}/usr/lib/pkgconfig pkg-config --list-all

未设置 PKG_CONFIG_PATH 阻止它在我的 / usr / local 中查找其他软件包,设置 PKG_CONFIG_LIBDIR 表示它将找不到本机系统。

Unsetting PKG_CONFIG_PATH prevents it finding extra packages in my /usr/local, setting PKG_CONFIG_LIBDIR means it won't find the native system ones.

这篇关于为什么我的交叉编译失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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