debug C for UNIX API on Windows 7 with Cygwin? - c

I am just learning about Cygwin, and it appears to make possible to write C code against the UNIX API, and then have it run on Windows, provided you build it in the Cygwin environment.
I have gotten accustomed to the Visual Studio IDE and debugging tools, so wanted to ask: is it somehow possible to write and build C in Windows, and then debug it with Visual Studio, with the help of Cygwin?

No, because the VS debugging tools (for the most part) depend heavily on it being compiled using the MS C compiler, rather than GCC.
So if you manage to bootload it in, you won't get any of the more useful debugging features VS offers.
The closest alternative to Visual Studio that supports GCC is Eclipse.

Visual Studio isn't an option for your case because the VS collection of tools are designed to work with code compiled using the VS C compiler and not GCC. In lieu of Visual Studio, I suggest Codelite. It's designed specifically as a cross-platform IDE that will be familiar to developers that have migrated from Visual Studio. It will of course handle GCC or Clang.
In comparison to CodeBlocks (another potential IDE you can use), Codelite has a large number of features that are slightly improved, but it does have a few that are worth mentioning individually.
Clang driven code-completion and code tagging. This is separate from the compiler, so even when compiling with GCC the IDE can provide you with Clang-based features. As a word of caution, Clang supported features are not yet entirely implemented. For instance, Clang code suggestions aren't present, and code-completion doesn't yet work for Objective-C.
Partial support for Objective-C out of the box. CodeBlocks needs to be properly setup to correctly handle Objective-C projects, while Codelite can handle them without any modifications. I say partial support for Objective-C because of the aforementioned missing code-completion for Objective-C methods and classes.
Much higher quality build error output window; catalogues all build errors and warnings by message, file and project. The only thing I can directly compare it to is the build error output window in Xcode.
My suggestion is to try both IDEs and decide on which will better suit your needs.

It is actually possible to debug UNIX apps with Visual Studio. See Utilities and SDK for Subsystem for UNIX-based Applications.

Related

How to compile and execute C program on Visual Studio 2012 for Windows 8?

I was looking for a C compiler for Windows 8 and then came to know that I can compile C programs on Visual Studio.
Microsoft offers a walkthrough for the same, but I don't like it since it includes writing program in text editor and use of command prompt frequently, I am looking for more like a Turbo C++ interface.
Is there anyway I can run and compile programs directly in Visual Studio 2012 for windows 8 itself?
Or if that's not possible, what alternatives I have for windows 8?
From the page you posted:
By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code.
Now create any C++ project type you want and when you add the files, ensure they end in .c and you are done.
Since you asked for alternatives (not clear if you meant even alternative IDEs and/or compilers):
You could try the free Code::Blocks IDE which has support for MINGW, which includes a port of GCC (Gnu Compiler Collections) for Windows. An alternative, and sometimes easier to install, port of GCC based on MINGW is TDM-GCC. Code::Blocks can also be configured to work with other toolchains.
An advantage of using GCC is that it is the default compiler for Linux systems, so if you will happen to code for Linux too, you could "reuse" your knowledge of the GCC compiler you used on Windows.
Another alternative IDE could be eclipse, with its CDT extension, aimed at C/C++ development (can be configured to work with GCC or with many other toolchains). Much heavier than Code::Blocks, but with much more features.
you can use visual studio as TURBO C++
But here
if you want to compile single file
create program.c
file->new->c++file->open
then write c code and save it with extension .c
Now you need to create new project
and file->new->project
add program.c to this project.
and compile the project By using build->compile. before that change compile as with the
project->properties.
The last time I used Turbo C++ (in the early 90s), it was an IDE just like Visual Studio.
Both Turbo C++ and Visual Studio offer command line tools.
From the start menu, find the Visual Studio tools menu, there should be a command line shortcut there that allows you access to the command line (cl.exe) tools.
If you have makefiles, then you can use nmake rather than make.

Compiling and Distributing C Programs

I just finished a semester up of C programming for a class I'm in, and it has left me with some questions that I was hoping to get answered.
During my class we have been using GCC to compile C programs. This is all good and well, but I have a question about compiling.
What if I wanted to build a C program on Windows? There is no GCC. Is that what Microsoft Visual Studio is for?
Also, what if I wanted to compile a program and distribute it? What would I compile to distribute to other Window's users?
In summary, I know how to write C programs, but I just don't get how you would make a program to give to someone who doesn't have a C compiler and is basically computer dumb.
Thanks in advance,
Ryan
Generally you will need to do two things:
Compile your program into a stand-alone executable or binary.
a. On Windows this would be a win32 executable.
b. On Linux this would be an elf binary.
Create an installer package for your program.
a. On Windows you might use NSIS, Microsoft MSI, or InstallShield.
b. On Linux you would do well to use a packager for the distribution you want to target.
Anecodtally, it is very easy to utilize Eclipse CDT and NSIS to develop C and C++ software on Windows without needing to pay any license fees.
Eclipse CDT: http://eclipse.org/cdt/
Starter Guide: http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx
NSIS: http://nsis.sourceforge.net/Main_Page
Note that if you use Visual Studio then you will also need to compile in release mode and distribute the Visual Studio CRT or .NET runtime(s). It depends upon how you link to the standard library provided by your compiler.
you can get GCC for windows....
but, Visual Studio is probably a better choice.
Once you have built it, you can use something like Wix or InnoSetup to make an install program for it.

Most Common C / C++ Compiler for NetBeans and Windows

What is the most commonly used (simplest) C / C++ compiler used on Windows when using the NetBeans IDE (6.7)?
I want to write (mostly) simple C programs. I have Cygwin installed but for some reason NetBeans doesn't like it. I'm getting a error from it and before I try to figure this out, I thought I should find and (if needed) configure a more popular one.
makeinfo: --fill-column arg must be numeric, not
nbproject/Makefile-Debug.mk'.
Trymakeinfo --help' for more information.
I believe I'm getting this error because I don't have make installed.
I've also found this stackoverflow post (C/C++ Compiler for windows) but and that suggests to use MinGW compiler tools.
What is the difference between MinGW and Cygwin? Which is better or preferred? and are there any other options?
The difference between Cygwin and MinGW is the the Cygwin tools (and the executables generated) rely on the cygwin DLL that provides a POSIX-like layer for the application.
MinGW are native Win32 tools (in that they do not require the presence of the Cygwin DLL) that produce native Win32 executables that do not need the Cygwin DLL.
My personal preference is for MinGW, but if you're going to be building programs that have a Unix heritage, the Cygwin toolset will likely help you build the program to run on Windows more than the MinGW toolset will.
I'm not sure what the licensing implications of linking to the Cygwin DLL are (I forget if it's GPL or LGPL).
Here is a good post I just found for getting cygwin and Netbeans working together.
Configuring cygwin with netbeans in Windows
And just so you know, cygwin and MinGW are by far the two most popular open source solutions for C/C++ on windows. Other popular compilers exist, but are not free (Borland C++, Microsoft Visual C++, etc)

Good IDE/compiler for simple C dll's

I'm trying to disassemble a C/C++ DLL, and have made some progress, but I would like to create my own C DLL with the same function the original exports, and compare disassemblies.
Visual Studio adds to much crap, and when I remove the crap and build my project, the expected DLL is missing.
I need a lightweight, preferably IDE, tool to edit and build very simple C libraries.
Take a look at Code::Blocks
I need a lightweight, preferably IDE, tool to edit and build very simple C libraries.
I have found that one of the best ways to do integrated C-only Win32 development is using the freely available Lcc Win32 Compiler which comes with a built-in IDE, including resource editor.
In fact, it is really very lightweight and can be run from a USB stick with some manual tweaking.
It's indeed a really small download of just 6 mb and you can even download an optional Win32 API help file which is really useful while doing development.
The compiler also comes with a C tutorial, as well as good user documentation detailing how to use the integrated Win32 resource editor "wedit", there's also an advanced manual about more complex development tasks.
Dev-C++ is a nice and fast IDE which works well with MingW.
But it's all been asked and answered before ...
MinGW adds its own crap. Install your VC express properly and save yourself a lifetime of trouble.
Btw, you don't need to use Visual Studio for its compiler or vice versa. The oddity of missing a build dll is probably because you are not looking at the right path.
If you are building C DLLs you really would benefit from its command line toolset and utilities, sdks, easy config etc. MS lock-in proprietary extensions are widely used (in context of you trying to emulate another dll), and last thing you need is chasing cross compiler issues..
GCC + any text editor such as VIM is a very light alternative.
For Windows Development, all you need is inside MinGW
Edit: If you are in dire need of an IDE you can also use the MinGW tools from Eclipse with the CDT plugin. Although it adds weight to the solution because of the installation of Eclipse, this is what I really use to build my small DLLs (JNI wrappers in my case).
You can setup your small and direct makefiles or let Eclipse do it automatically for you and concentrate only on the source files (*.h, *.c).
The best part of using this approach instead other IDE is that you do not need Eclipse to further build the DLL, since the underlying project files generated are standard ones directly usable by integrated dev inside MinGW (or any Unix distro) such as make, configure, automake, and so on.
I'll second the vote for Code::Blocks, it's what I use (despite having VS 2008 installed as well). It is very simple and lightweight but has basically all the features you'd expect out of an IDE. It comes with several predefined project templates for all kinds of C and C++ development, including templates for DLLs.
Download the version that includes MinGW and you get a complete lightweight IDE ready to start compiling. You can also easily configure it to use the Visual Studio compiler instead of gcc if you prefer.
try Open Watcom. A cross-platform product, well-supported by the community, lets you develop in DOS, Windows, OS/2 etc for a lot of platforms. Version 1.8 was released recently. Has a light-weight IDE indeed

C compiler for Windows? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm fine working on Linux using gcc as my C compiler but would like a Windows solution. Any ideas? I've looked at Dev-C++ from Bloodshed but looking for more options.
You can use GCC on Windows by downloading MingW (discontinued) or its successor Mingw-w64.
You can get Visual C++ Express Edition straight from Microsoft, if you want something targeting Win32. Otherwise MinGW or lcc, as suggested elsewhere.
GCC is ubiquitous. It is trusted and well understood by thousands of folks across dozens of communities.
Visual Studio is perhaps the best IDE ever developed. It has a great compiler underneath it. But it is strictly Windows-only.
If you're just playing, get GCC --it's free. If you're concerned about multiple platfroms, it's GCC. If you're talking serious Windows development, get Visual Studio.
You could always just use gcc via cygwin.
There is another free C compiler for Windows: Pelles C.
Pelles C is a complete development kit for Windows and Windows Mobile. It contains among other things an optimizing C compiler, a macro assembler, a linker, a resource compiler, a message compiler, a make utility and install builders for both Windows and Windows Mobile.
It also contains an integrated development environment (IDE) with project management, debugger, source code editor and resource editors for dialogs, menus, string tables, accelerator tables, bitmaps, icons, cursors, animated cursors, animation videos (AVI's without sound), versions and XP manifests.
URL: http://www.smorgasbordet.com/pellesc/
I personally have been looking into using MinGW (what Bloodshed uses) with the Code Blocks IDE.
I am also considering using the Digital Mars C/C++ compiler.
Both seem to be well regarded.
GCC is not technically a linux specific compiler. Its a standards compliant c/c++ compiler, and I use it for windows programs on a daily basis. Its probably best that you use it until you become more comfortable with something else.
I recommend that you use the MinGW distribution of GCC. That will compile your programs natively for windows, using a standard library, etc.
If you're looking for an IDE, I have two recommendations. Visual Studio is the Microsoft version, and although it has its issues, it is an excellent IDE for working with the code. However, if you're looking for something a bit more lightweight, CodeBlocks is also rather good, and has the added benefit of being able to use basically any compiler you have installed (including several forms of GCC and the Microsoft Compiler that comes with Visual Studio) and being able to open project files fro other IDEs. Plus, it runs on linux too, so you could make that transition even easier on yourself.
I personally prefer GCC, but that's just me. If you really want the Microsoft Solution, VS is the way to go.
You may try Code::Blocks, which is better IDE and comes with MinGW GCC! I have used it and its just too good a freeware IDE for C/C++.
MinGW would be a direct translation off gcc for windows, or you might want to check out LCC, vanilla c (more or less) with an IDE. Pelles C seems to be based off lcc and has a somewhat nicer IDE, though I haven't used it personally. Of course there is always the Express Edition of MSVC which is free, but that's your call.
Most universities give you access to Microsoft Dreamspark.
If you're using GCC/Linux in class, just install Ubuntu. Windows is a terrible platform for C development.
Be careful to use a C compiler, not C++ if you're actually doing C. While most programs in C will work using a C++ compiler there are enough differences that there can be problems. I would agree with the people who suggest using gcc via cygwin.
EDIT:
http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B shows some of the major differences
http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite
GCC works fine. Note that MSVC is not necessarily a valid solution because it does not support C99.
I'm late to this party, but for any future C folks on Windows, Visual Studio targets C90 instead of C99, which is what you'd get on *nix. I am currently targeting C99 on Windows by using Sublime Text 2 in tandem with Cygwin.
Cygwin offers full GCC support on Windows; also, the free Microsoft Visual C++ Express Edition supports 'legacy' C projects just fine.
Visual C++ Express is a fine and free IDE for Windows which comes with a compiler.
If you are more comfortable with commandline solutions in general and gcc in particular, MinGW or Cygwin might be more up you alley. They are also both free.
There have been a few comments pointing out that C is not C++. While that's true, also true that any C++ compiler will also compile C - usually the compiler mode will be automatically selected based on the filename extension, but every compiler also has an option to force C or C++ mode regardless of the filename.
So choose the free C++ compiler that you're most comfortable with gcc, VC++ Express, Digital Mars, whatever. Use the IDE you like best emacs, vim, VC++ Express, Code::Blocks, Bloodshed - again whatever.
Any of these tools will be more than adequate for learning. Personally, since you're asking about Windows, I'd choose VC++ Express - it's a great IDE, it's free, and it'll compile C programs just fine.
It comes down to what you're using in class.
If the labs and the assignments are in linux, then you probably want a MinGW solution. If they're in windows, get Visual Studio Express.
Can't you get a free version of Visual Studio Student Addition from your school? Most Universities have programs to give free software to students.
You mean Bloodshed's Dev-C++? It's a nice visual IDE for C++ which uses MinGW's gcc for Windows as the back-the-scenes compiler. The project's been abandoned for a while (in my opinion, using Delphi to develop a C++ IDE is a very stupid thing to do to draw developers' attention), however there's nothing that stops you from using it and updating the version of MinGW's gcc it uses to the latest one - besides it's GPL-licensed.
I use either BloodShed's DEV C++, CygWin, or Visual C++ Express. All of which are free and work well. I have found that for me, DEV C++ worked the best and was the least quirky. Each compiler has it's own quirks and deifferences, you need to try out a few and find the one with which you are most comfortable. I also liked the fact that DEV C++ allowed me to change the fonts that are used in the editor. I like Proggy Programming fonts!
Must Windows C++ compilers will work.
Also, check out MinGW.

Resources