I have a program that is writen in C++, and I'm trying to set up the cygwin interface in order to save it to the correct path, compile it using the correct commands, and send the output to the screen. I want to understand how to achieve the connectivity to cygwin. As of yesterday, I downloaded it to... c:\cygwin, and I have a shortcut to the "terminal" on my desktop. Can someone guide me? I never could understand the linking, etc., but I managed to compile my program using an "online c++ compiler". If I want to send my output to a file... the online stuff won't help me. TIA, Bill

I donated $5 to daniweb.

cygwin is a bash environment for Windows. This means that you have to navigate it like you navigate a bash terminal environment (i.e., Linux/Unix). Here is some introductory material on that.

To access the hard drives like C:, D:, etc.. in cygwin, you have to go to the directories /cygdrive/c, /cygdrive/d, etc... As so:

$ cd /cygdrive/c

Once you navigate to the directory in which you have your C++ source file(s), you can compile it like this:

$ gcc -Wall my_source.cpp -o my_program.exe

where "my_source.cpp" is the source file, and "my_program.exe" is the executable's name as you want the compiler to generate it (i.e., the -o is for "output" option). The command literally means, "compile with all warnings the source file 'my_source.cpp' and produce as output the executable 'my_program.exe'".

You can also check out this instruction video.

commented: Always Informative +11

thank you very much. I'll try it out! thx.

I tried that... and got this error:

Owner@YOUR-CD90759025 /cygdrive/c
$ gcc -Wall cambio1.cpp -o cambio1.exe
-bash: gcc: command not found

I know that I downloaded my cygwin in the folder c:/cygwin/(subfolders loaded)

do I have to download the gcc separately???
hmmm.
Bill

I think I that the bash environment is very much like the ++ (shell) environment that I used on a mainframe in high school in 1985. Am I right??? Bill

Yeah, the environment is basically just your old Unix shell environment.

do I have to download the gcc separately???

Yes, kind of. Cygwin uses a package management system (similar to other Unix variants like Linux or Mac OSX). If you re-run the setup.exe (like you did when installing it), you have to "next" to the package listing. In the package listings, you have to find "GCC" (or GNU Compiler Collection), and possibly also g++. The same goes for any additional packages you might want to have, like make, cmake, etc..

you are right! I saw it on a website. I forgot to expand the list(as they said) to add the following:

Step 6 (b): Select gcc, gdb, and make:

I'll try that... and see where it leads me.

I've been running Cygwin for many years, and doing serious cross-platform development in that environment. Most of the GNU and Linux tools are available for download and installation via the Cygwin installation tool, including the compiler/development suite and all the tools that come with that. When you run an application built in Cygwin, it will also use some dynamic interface libraries (Windows DLL's) that get installed with Cygwin. If you want more native applications, but built with a GCC compiler, then look into MingW. That doesn't require the Cygwin runtime libraries and applications built with it can be copied and run on just about any compatible Windows system.

I just want to compile a C++ program. I think that I just downloaded the entire cygwin "devel" package... just to be able to compile a very small program. Overkill!!! thanks for the advice. MingW will be my next attempt... if this cygwin stuff doesn't work. it's a WIP.

the easiest path to just get something compiled is probably to install codeblocks (with MinGW). Open your source file in CodeBlocks and hit the compile button.

yep. yep. that's the way to go... thanks, mikey!

If you got the answer to your question, can you please mark it as Solved? (Button at top and bottom of page). Thanks! :)

i want to go to directory C:\appfog
how can i do that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.