How to make linux command line program work on Windows?

I am starting to program and I am working in C / C ++ in Ubuntu. When I say something to cin / cout / cerr or printf / scanf or take arguments from the command line, all this comes from the linux terminal in Ubuntu.

Now, if I want to run these same programs (very simple programs, entry level) and run them on Windows, how can I launch them from the Windows command line? The previous course I took made us download cygwin to simulate the linux command line on Windows, but what if I just want to run the program from a regular Windows command line? Is this possible and is a software modification required?

+3
source share
6 answers

Windows Linux.

Ubuntu :

sudo apt-get install wine mingw32 mingw32-binutils mingw32-runtime

...

i586-mingw32msvc-g++ -o myProgram.exe myProgram.cpp

, ? Google "- ubuntu", .

+6

. cmd () , Linux.

, program, Linux :

./program --option1 -o2 file1 file2

Windows .exe, cmd :

program.exe --option1 -o2 file1 file2

, cmd Windows. , Linux, , .


cin/cout/cerr printf/scanf/fprintf(stderr, ...) C stdin, stdout stderr, Linux, . Windows (cmd) / , Linux. - .

+4

cin cout, printf scanf Windows , Linux. ( , cerr , 100%. , .) , Windows ( , *.txt) ; .

, , Linux GCC, , , .

... ... . Cygwin Linux. Linux.

+1

, - , Linux, Windows, Windows.

GCC Windows, TDM-GCC. MinGW , , , . Windows, .

-, - . , , Makefiles. , <target>.out linux, Makefile <target>.exe, . Makefile gcc <file.c>, a.exe ( a.out Linux).

0

, , UNIX Windows:

#include <stdio.h>
int main()
{
    printf("Hi\n");
    return 0;
}

UNIX, .

/usr/home/bobby# gcc main.c
/usr/home/bobby# ./a.out
Hi
/usr/home/bobby#

Windows /. - Cygwin, Windows SDK Visual studio (, ).

Start -> Run -> cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
C:\Windows\system32>cd c:\bobby
C:\bobby>cl main.c
C:\bobby>main.exe
Hi
C:\bobby>
0

C , . Ubuntu ELF, Windows PE.

, ELF PE, / , . , , , . . (Linux.so, windows.dll). , (Linux.a, Windows.lib). - .

.. .

. , .. main().

, main, .., . , Linux Windows.

cygwin, , .. . ELF.

Windows, Windows. , .

ELF PE, , .. .. , -. , stderr, stdout stdin. C .

It is like driving a diesel vs gasoline car. Much is the same thing, but under the hood is a completely different matter.

Keep in mind that, for example, signals are handled differently in Windows.

0
source

All Articles