I was given the task to deal with cross-compiling C and C ++ applications from under Windows for Linux.

I tried using cygwin for this purpose. Installed this shell, launched it. Installed the cygwin-gcc-3.3.6-glibc-2.3.2-linux compiler (the old truth). And I tried to compile the usual HelloWorld from it and run it under Linux, everything turned out.

But the task is to run a cross-compiler from our Windows application that will compile some files. How can this be implemented? Just in this case, you have to run Cygwin, and already from it gcc-linux or g ++ - linux. So far I do not see ways to run from our Windows application Cygwin and further already in it start the compiler.

Maybe there are some other ways out of the situation? How can you customize a separate Windows compiler at all, which will compile binaries for Linux?

  • one
    Maybe this will help - ru.wikipedia.org/wiki/MinGW - Anton Shevtsov
  • Well, I read it and I have it installed. I still can not find on the Internet about how to really compile on it - G71

3 answers 3

  1. Install cygwin.
  2. Create a script that starts the assembly.
  3. Call the script from the application.

In script (cmd file)

set CYGWIN_BIN=c:\cygwin\bin CYGWIN_BIN\gcc.exe ... 

In the application

 CreateProcess(...) 

And there is such a tool for cross-compilations: crosstool-ng .

  • hmm, thanks a lot for a good answer! I will work on the first option, thanks for the tips :) crosstool-ng later I'll see - G71
  • I compiled the compiler I needed under Gywin. And you can’t tell me in more detail how to launch Cygwin for me from my windows application, and then, as it were, automatically register in bash Cywin what you need to compile - G71
  • and even better: SET CYGWIN_HOME = C: \ cygwin PATH =% CYGWIN_HOME% \ bin;% PATH%; echo abcd | grep -va - jmu

But doesn’t cycwin gcc.exe need cygwin .dll? In my opinion, bash loads them when the cygwn window starts.

At least I (Windows-XP) did not succeed in flying. c: \ cygwin \ bin \ gcc tc from cmd required cygwin1.dll

You need to figure out cygwin initialization, dll loading.

And so it happened:

c: \ cygwin \ bin \ bash -c "gcc tc"

Only I am absolutely not sure that the resulting module will work in Linux.

  • one
    The resulting module will not work under Linux. Only if you do not run it under wine. To run under Linux you need to recompile - i.e. so that the format of the executable file was a.out or ELF and Linux libraries were linked. Regarding cygwin1.dll - rightly so. But dependencies on libraries are easy to see with Dependency Viewer. And if you put all the libraries it needs next to the program, then it will work in any Windows =) even on the one that Cygwin does not cost - gecube
  • the point is that I need a cross compiler, I took it from here: kegel.com/crosstool I compiled the compiler I needed, compiled it for Cygwin and got a binary that DOES NOT START under Cygwin and works fine under Linux without add. Libraries - G71

If I understand the question correctly, then you can use pipes to feed commands to cygwin for g ++ - linux through them.