如何从 windows g++ 进行交叉编译cygwin获取linux可执行文件

发布于 2024-11-01 20:28:13 字数 1115 浏览 2 评论 0原文

我在 Windows 系统上更新了 cygwin-full install 、mingw 、codeblocks 。 我有一个 C++ 程序,它根据输入执行 xml 生成。

据我了解,我们使用 makefile 为 UNIX 构建可执行文件。 makefiles 是典型的项目文件。 因此我使用插件 cbp2make.exe 来获取 cbp 项目文件的 makefile。我尝试在 cygwin 中执行 make 。希望得到一个linux可执行文件。但这显然是错误的。

典型的测试 C++ 测试程序 test.c 将使用 gcc 交叉编译选项在 cygwin 中进行编译。

g++-linux -o test test.c

这将为我们提供 linux 可执行文件测试,或者如果未指定名称,它将提供 a.out

对于不包含头文件的简单 C++ 程序来说,这一切都很好。

我知道当我们处理带有大量外部库文件的 C++ 文件时,简单的 g++ -o ourprojfile.exe ourprojectfile.cpp 不起作用,因此我们需要使用 make 文件。 问题 1:我的假设是错误的吗?*

问题 2:我们如何设置交叉编译以直接从代码块获取 Linux 可执行文件。


更新:我的问题end 似乎缺少依赖的 cpp 文件,我假设我将其包含在主文件中。 解决方案是将它们包含在主文件中或简单地编写句柄,如下所示

g++-linux myprog_linux main.cpp first.cpp second.cpp third.cpp 

现在的问题是在我获得 Linux 可执行文件之后。 当我尝试在 Linux 机器上运行它时,我收到错误,

 /usr/local/folder/myfile/my_prog_nix: error while loading shared libraries: 
libstdc++.so.5: cannot open shared object file: No such file or directory

我需要哪种链接才能清除此错误?

I have an updated cygwin-full install ,mingw ,codeblocks on a windows system.
i have a c++ program which performs xml generation based on input.

I understand to build an executable file for unix we use makefiles. makefiles being typical project files .
Hence i used the plugin cbp2make.exe to get the makefile for the cbp project file. and i tried to execute make in cygwin. hoping to get a linux executable file. but this was clearly wrong.

a typical test c++ test program test.c would be compiled in cygwin using gcc cross compile options like.

g++-linux -o test test.c

this would give us the linux executable file test or if no name is specified it would give an a.out

This is all well and good for a simple c++ program with no included header files.

I understand when we are dealing with c++ files with lot of external library files a simple g++ -o ourprojfile.exe ourprojectfile.cpp does not work hence we would need to use make files. Question 1 : Am i wrong in assuming this ?*

Question 2: how can we setup cross compile to get a linux executable file directly from codeblocks.


Update : the problem at my end seems to be missing dependent cpp files which i assumed i included in the main file.
The solution was to include them in the main file or simply write handle like so

g++-linux myprog_linux main.cpp first.cpp second.cpp third.cpp 

The problem now is after i get the Linux executable file.
when i try to run it on linux machine i get the error of a

 /usr/local/folder/myfile/my_prog_nix: error while loading shared libraries: 
libstdc++.so.5: cannot open shared object file: No such file or directory

what sort of linking do i need to do clear this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

余厌 2024-11-08 20:28:13

您认为需要 makefile 是错误的。任何建筑商都可以。重要的一点是,您必须告诉构建器:

  • 调用 g++linux 而不是 g++ (或 mingw-g++ 或其他)它正在调用)
  • 设置正确的路径来查找包含和库。编译器会知道在哪里查找它自己附带的系统库,所以你只需要处理你拥有的任何额外的东西。

通常,makefile 会调用 C 源代码的 CC 和 C++ 源代码的 CXX 中给出的编译器,并向它们传递 CFLAGSCXXFLAGS 的内容。 code> 分别作为附加参数。但是您可能可以告诉 CodeBlocks(但我从未使用过它,所以我不知道)调用不同的编译器并避免所有 make 业务。

You are wrong assuming that you need makefile. Any builder will do. The important point is, that you have to tell the builder to:

  • Call g++linux instead of g++ (or mingw-g++ or whatever it's calling)
  • Set proper path to look for includes and libraries. The compiler will know where to look up system libraries that came with it on it's own, so you just have to deal with any extra stuff you have.

Normally makefiles call the compiler given in CC for C sources and CXX for C++ sources and passes them content of CFLAGS and CXXFLAGS as additional arguments respectively. But you can probably just tell CodeBlocks (but I never used it, so I don't know) to call different compiler and avoid all the make business.

溺孤伤于心 2024-11-08 20:28:13

确保您在 Cygwin 中安装了 Cygwin 的 GCC 交叉编译器:

http://sourceforge.net /projects/metamod-p/files/

解压到 Cygwin 根目录,然后使用以下命令从 Cygwin 进行编译:
g++-linux
或者
g++-linux-x86_64

Make sure you have the GCC cross-compiler for Cygwin installed in Cygwin:

http://sourceforge.net/projects/metamod-p/files/

untar into Cygwin root, then compile from Cygwin using:
g++-linux
or
g++-linux-x86_64

忘羡 2024-11-08 20:28:13

为了交叉编译,您必须使用 Linux 代码生成器获取(或构建)gcc 的自定义程序集。由于这不是一项简单的任务,因此最好将源代码移至 Linux 机器并在那里进行本机构建。

In order to cross-compile you have to get (or build) custom assembly of gcc, with linux code generator. Since it's not a trivial task it's better just to move sources to linux machine and do a native build there.

浅笑轻吟梦一曲 2024-11-08 20:28:13

<块引用>

解压到 Cygwin 根目录,然后使用 g++-linux 或 g++-linux-x86_64 从 Cygwin 进行编译

实际上,您必须重命名 /bin/g++-linux-4.1 和 /bin/gcc-linux-4.1

untar into Cygwin root, then compile from Cygwin using: g++-linux or g++-linux-x86_64

Actually you must rename /bin/g++-linux-4.1 and /bin/gcc-linux-4.1

苯莒 2024-11-08 20:28:13

如果您想从 Windows 构建 UNIX,我认为您使用了错误的编译器。
mingw-w64 有一个 ubuntu-natty 目标编译器(11.04 和 64 位)和一个 BSD 目标编译器,

如果您想将主机编译为 windows x64,将目标编译为这 2 个操作系统,并以 2 种处理器作为目标,你想要 mingw-w64,个人构建,vityan。

mingw-w64 项目位于 http://sourceforge.net/projects/mingw-w64/ (由于 sourceforge.net 上的 mingw-w64 项目正在转移到 mingw-w64.org,我建议使用 mingw-w64.org )

https://sourceforge.net/projects /mingw-w64/files/Toolchains%20targetting%20NonWin/vityan/

在下载之前您可能应该有一个 sourceforge 帐户(您也许可以将 https 更改为 http )。

cygwin 是移植到 Windows 的 UNIX 工具,我认为编译器实际上来自自动化构建领域的 mingw-w64。
cygwin 是 Windows 目标。其目的是为开发者提供一个类似于Windows的UNIX环境。

I think you are using the wrong compiler if you want to build for UNIX from windows.
mingw-w64 has an ubuntu-natty target compiler (11.04, and 64-bit ) and a BSD target compiler

if you want to compile with your host as windows x64 and your target as these 2 OS's with 2 flavors of processors as a target, you want mingw-w64, personal builds, vityan.

the mingw-w64 project is at http://sourceforge.net/projects/mingw-w64/ (Since the mingw-w64 project on sourceforge.net is moving to mingw-w64.org i suggest to use mingw-w64.org)

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20NonWin/vityan/

you should have a sourceforge account before downloading probably (you might be able to change the https to an http maybe).

cygwin is UNIX tools ported to windows and the compiler I think is actually from mingw-w64 in the automated builds area.
cygwin is windows target. its purpose is to provide a UNIX-like environment for windows for developers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文