如何交叉编译从windows g ++ cygwin获取linux可执行文件 [英] How to cross compile from windows g++ cygwin to get linux executable file

查看:446
本文介绍了如何交叉编译从windows g ++ cygwin获取linux可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows系统上有一个更新的cygwin完全安装,mingw,codeblocks。
我有一个基于输入执行xml生成的c ++程序。

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.

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

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.

一个典型的测试c ++测试程序 test.c 会使用gcc交叉编译选项。

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

这将给我们linux可执行文件测试,或者如果没有指定名称,它会给出一个a.out

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

这对于一个没有包含头文件的简单的c ++程序是很好的。

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

我理解当我们处理带有许多外部库的c ++文件文件一个简单的 g ++ -o ourprojfile.exe ourprojectfile.cpp 不工作,因此我们需要使用make文件。 问题1:假设这是错误的吗?*

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 ?*

问题2:我们如何设置交叉编译获取一个linux可执行文件

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

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

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 

现在的问题是,我得到Linux可执行文件。
当我试图运行它在linux机器上我得到的错误

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

$

推荐答案

你错了吗?b
$ b

假设你需要makefile。任何建设者都会做。重要的是,你必须告诉构建器:

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 而不是 g ++ (或 mingw-g ++ b
  • 设置正确的路径以查找包含和库。编译器将知道在哪里查找它自带的系统库,所以你只需要处理任何额外的东西你有。

  • 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.

通常,makefiles调用C $ source中 CC 中给出的编译器,并为C ++源调用 CXX CFLAGS CXXFLAGS 作为附加参数。但你可能只是告诉CodeBlocks(但我从来没有使用它,所以我不知道)调用不同的编译器,并避免所有的生意。

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.

这篇关于如何交叉编译从windows g ++ cygwin获取linux可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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