如何从 windows g++ 进行交叉编译cygwin获取linux可执行文件
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您认为需要 makefile 是错误的。任何建筑商都可以。重要的一点是,您必须告诉构建器:
g++linux
而不是g++
(或mingw-g++
或其他)它正在调用)通常,makefile 会调用 C 源代码的
CC
和 C++ 源代码的CXX
中给出的编译器,并向它们传递CFLAGS
和CXXFLAGS
的内容。 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:
g++linux
instead ofg++
(ormingw-g++
or whatever it's calling)Normally makefiles call the compiler given in
CC
for C sources andCXX
for C++ sources and passes them content ofCFLAGS
andCXXFLAGS
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.确保您在 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
为了交叉编译,您必须使用 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.
实际上,您必须重命名 /bin/g++-linux-4.1 和 /bin/gcc-linux-4.1
Actually you must rename /bin/g++-linux-4.1 and /bin/gcc-linux-4.1
如果您想从 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.