Author Topic: Cross Compile for linux in windows using cygwin  (Read 12515 times)

Offline adityagameprogrammer

  • Single posting newcomer
  • *
  • Posts: 8
Cross Compile for linux in windows using cygwin
« on: April 18, 2011, 10:58:40 am »
with the full cygwin install i.e the cross compile tools. To get the executable file for linux it is a simple matter of invoking the cross compiler in cygwin like

Code
gcc-linux -o output input.c

How can we set this up in codeblocks environment?

to use the cygwin gcc we simply have to locate to the exact version of gcc which we want to use and set it in toolchain executables
like for
Code
cygwin c++ compiler C:\cygwin\bin\g++-4.exe
.

But the cross compile tools have the linux compiler as gcc-linux which is not an exe file

So how do we set this up with codeblocks?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Cross Compile for linux in windows using cygwin
« Reply #1 on: April 18, 2011, 11:12:33 am »
So how do we set this up with codeblocks?
If it is not a exe file it requires a wrapper tool to run on Windows, like e.g. the bash.

So what you need to do is to call the same wrapper instead of the compiler directly. You could e.g. setup a batch file for this purpose, if possible.

How does Cygwin call this file? Could it be that it is actually a proper executable but the extension is missing? If so, just make a copy of this/these file(s) and add the extension.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline adityagameprogrammer

  • Single posting newcomer
  • *
  • Posts: 8
Re: Cross Compile for linux in windows using cygwin
« Reply #2 on: April 18, 2011, 12:27:56 pm »
@Morten
you are right about the path's aspect. i have checked the path of the files being called and i nagivated to the exe to this folder.
Code
C:\cygwin\opt\crosstool\i686-unknown-linux-gnu\gcc-2.95.3-glibc-2.1.3\bin
and set the compiler tool chain to the exes in this folder. i.e
Code
cpp.exe
gcov.exe
gdb.exe
i686-unknown-linux-gnu-addr2line.exe
i686-unknown-linux-gnu-ar.exe
i686-unknown-linux-gnu-as.exe
i686-unknown-linux-gnu-c++.exe
i686-unknown-linux-gnu-c++filt.exe
i686-unknown-linux-gnu-g++.exe
i686-unknown-linux-gnu-gcc.exe
i686-unknown-linux-gnu-gprof.exe
i686-unknown-linux-gnu-ld.exe
i686-unknown-linux-gnu-nm.exe
i686-unknown-linux-gnu-objcopy.exe
i686-unknown-linux-gnu-objdump.exe
i686-unknown-linux-gnu-protoize.exe
i686-unknown-linux-gnu-ranlib.exe
i686-unknown-linux-gnu-readelf.exe
i686-unknown-linux-gnu-size.exe
i686-unknown-linux-gnu-strings.exe
i686-unknown-linux-gnu-strip.exe
i686-unknown-linux-gnu-unprotoize.exe
make.exe
windres.exe

But the build fails.
Code
 
-------------- Build: Debug in greet ---------------

[ 50.0%] Compiling: main.c
Execution of 'i686-unknown-linux-gnu-gcc.exe -Wall  -g     -c D:/Aditya/cppnix/greet/main.c -o obj/Debug/main.o' in 'D:\Aditya\cppnix\greet' failed.
Nothing to be done.

I did try with the  make,windres and gdb from the mingw folders. and only the compilers pointing towards crosscompile exes. even that did not work.
I have both mingw and cygwin set up.
« Last Edit: April 18, 2011, 12:30:58 pm by adityagameprogrammer »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Cross Compile for linux in windows using cygwin
« Reply #3 on: April 18, 2011, 12:48:38 pm »
you are right about the path's aspect. i have checked the path of the files being called and i nagivated to the exe to this folder.
Code
C:\cygwin\opt\crosstool\i686-unknown-linux-gnu\gcc-2.95.3-glibc-2.1.3\bin
and set the compiler tool chain to the exes in this folder. i.e
Code
Execution of 'i686-unknown-linux-gnu-gcc.exe -Wall  -g     -c D:/Aditya/cppnix/greet/main.c -o obj/Debug/main.o' in 'D:\Aditya\cppnix\greet' failed.
This cannot work, as the toolchain path is most likely unknown. You can (however), add the path to these executables into the toolchain options.

Settings -> compiler -> Toolchain executables -> tab "Additional paths", add C:\cygwin\opt\crosstool\i686-unknown-linux-gnu\gcc-2.95.3-glibc-2.1.3\bin there, maybe others are needed, too.

However, I doubt this is the right way. I still believe Cygwin uses a wrapper (e.g. calling the default gcc with certain options) that actually invokes these cross compile tools.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ