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 thi开发者_如何学JAVAs?
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 ofg++
(ormingw-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.
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
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.
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
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.
精彩评论