C Programming with Cygwin and gdbtui - c

my question is regarding to the use of Cygwin and gdb. I was working on a school project but they want me to practice without the use of Visual Studio or similar compilers.
My questions is.. How would I be able to code C? Would this be on a text program or on Cygwin itself?
Thank you.

The Code::Blocks IDE may arguably be considered too close to Visual Studio, but until you learn the in's and out's of it, it's really just a place to write and compile code. You can keep to the spirit of the request by just using it as such rather than digging into its full capabilities.
If you really need to do it from scratch, use any text editor (eg: Notepad) and manually compile like this: http://ce.uml.edu/compile.htm

You can write program using any good text editor like this.
If you have cygwin installed on your system then you can just add c/c++ compiler (like gcc) to it and compile the program.
You always need not to use IDE for writing and compilation of programs.

Even though #Dinah does answer your question we still have not discussed about the way to use the gdb debugger .
Since you are starting out new i suggest you master debugging using a debugger like gdb . Believe me you will save tonnes of time figuring out what went wrong using print statements ( or any other equivalent mechanisms )
Here is a good place where you can start learn to use gdb
Have fun!

Related

C environment for learning the sufficiently hard way [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm new to C(coming from Java, so I'm not learning programming for the first time). I'm reading the book, "C Primer Plus". I've been searching around to understand the differences between compilers or environments to develop C programs on Windows.
I have installed MinGW and Visual Studio 2010. I have tested compiling a hello world on both environments. For MinGW, I'm considering Code::Blocks or vim. The multi compiler support on Code::Blocks sounds convenient, but I'm not at that level to comprehend how helpful this feature would be.
I'm willing to learn C the way I should be instead of being spoiled by letting the works done background hidden by IDE like Visual Studio. Once I improve my understanding, I don't mind switching to a more convenient environments.
The reason I feel uncomfortable with Visual Studio is that it doesn't support the standards as much as gcc. I have read an argument that VS is used widely in production and that this is just the way it is. Some people say just start writing C wherever which is what I don't want. I've seen some say experience the command prompt and see how the linking is done, etc.
This is from Wikipedia, but it says that Visual C++ shouldn't be used for compiling C. http://en.wikipedia.org/wiki/Visual_C%2B%2B#Issues
So here is what I need to make clear. It might be a few blocks.
My understanding is that Visual Studio is appropriate as long as I'm developing for Windows platform and also good for people who just want to start coding.
If I want to go with the more up-to-date standards and use gcc (which is used in Linux), I should go for MinGW. MinGW is the minimum gcc-like environment ported to Windows, so I can use the similar environment to Linux which benefits me for the standards better supported than VS. Also, this is supposed to help my program to be compiled more successfully on Linux and not exactly for compiling a program on Windows MinGW to run on Linux, right?
The portability we talk about is compiling a source code on each platform and not to compile a program on one particular platform to use the executed file on other platforms, correct?
Whilst Visual C++ isn't a C compiler, the Visual studio tools do allow compiing C code - the compiler under the Visual Studion is what is used to compile almost all of Microsofts C code (and there is A LOT of C code in a Microsoft Windows system, even if a fair chunk of the newer tools may be C, the basis for a lot of things is still C). You just have to ensure that you compile C as C, not as C++, since C++ has slightly different flavours of some things - some things that are allowed in C aren't in C++.
The way to do that is to call the file something.c, rather than something.cpp - it REALLY is that easy.
gcc is also a very competent compiler, absolutely no doubt about that. And using the tools in Code::Blocks etc will be a good way to learn.
I would actually say that Visual studio is definitely a smoother, slicker environment, and you can still use command-line tools like make to build things if you like - the compiler isn't part of the IDE, it's just a nicely integrated IDE. Learning a computer language should have as few obstacles as possoible. Making life hard for yourself is no help.
I personally use (x)emacs and gcc on Linux, but the first time I programmed in C, there wasn't even a proper standard for it, and computers typically had 8- or 16-bit processors - our school computer in 1985 had 2MB of ram and 3 disks of 64MB each (131000 something blocks of 512byte). That machine had 8 terminals in my school, 8 more terminals in another school, and the main school where the actual computer was had two rooms with, I think 16 terminals in each. So we sometimes shared the machine between 30 people!
You should choose whatever platform that feels the most comfortable to you, and wait with worrying about the complications of cross platform portability etc. Coming from Java you'll get your hands full with pointers and the like in the beginning, so focus on that instead of the environment.
If you have written Java in an Eclipse environment before, the CDT plugin for C/C++ might be the way to go. It does among others support the gcc tool chain.
Regards
If you're gonna compile for Windows, try CodeBlocks, Dev-CPP or Eclipse as they all use GCC i think. Essentially you want something that doesn't force you to make a new solution/include a new project / make a new file just so you could test a few functions out. You want to compile a single .c file and run it, and play in that format.
If you're gonna compile for Linux, try Geany, Eclipse or just use gcc. Might as well pick up makefiles while you're at it.
Apart from that, write C code, or look where some of those public native java calls end up. But don't look at the math package, you'll be disappointed.
EDIT: just noticed your portability. Yes, you need to recompile on every target, or use a cross-compiler.
But cross-compiling is not enough, one must write code for different platforms too, say in Windows you will use the Win API call CreateThreadA(), but in a linux-build you will probably use pthread_create(). You should get familiar with using
//some code
#ifdef __platform_windows
//windows code here
#endif
#ifdef __platform_linux
//linux code here
#endif
//crossplatform code

Create a C program in Windows

I want to create a small C program and I would like to use the Windows command prompt to compile and run it. Can anyone suggest to me how to install a C compiler that works with the command prompt and the way to use it? How do I install the compiler, compile the code and run the program?
Download Visual Studio Express 2010 C++. From the File menu, choose New, then Project. Under Project Types, expand the tree view to Visual C++ -> General, then choose the template for Empty Project. Give it a name and a location. Click OK. Type in some C code, then Build and Run it.
It's a fairly simple tool to use, so I'd recommend you just go ahead and try it out.
There's several compilers available for Windows. Two popular ones are Microsoft Visual C++ and MinGW.
Using Visual C++, you can compile a program like so:
cl /Femyprog.exe myprog.c
Using MinGW, you can compile a program like so:
gcc -o myprog.exe myprog.c
Most programmers don't use command prompts to compile very much any longer. We use IDE's instead, because they're a hell-of-a-lot more convenient. Having said that there's no reason why you can't use the command prompt to "manually" execute the compiler which underlies, say, Microsoft Visual Studio.
So... If I where you I'd start by downloading Visual Studio 2010 C++ Express Edition from Uncle Bills Funny Farm. Note that C++ IDE (and compiler, or course) supports the old ANSI-C language as well as C++... in fact C++ is a "superset" of ANSI-C.
Your other options are a bit limited on Windows. I believe that GCC: GNU's C++ Compiler works on Windows... but it's "got a few issues" which nobody is any particular hurry to fix, simply because by far the majority of the GNU boys are running Linux, and they sort-of look down on Windows as "an interesting experiment [which failed]".
Cheers. Keith.

How to program in C on Mac Leopard without XCode IDE?

I have just come to Mac world from Linux world and I love my way around in Mac environment. I want to write and practice simple C programs in mac and I was searching for the tools I require. Most (All) of the resources in the web ask me to use XCode as IDE to do programming in C on Mac. XCode, for my purpose seems to be an overkill. I am in no way interested in developing iPhone or Mac GUI application. All I want is
enter C programs using a text editor,
compile it ,
and get the output in a Console.
How can I do it ?
Thanks.
the 3 steps you give are simply the answer already:
use text editor of choice
use eg Terminal and compile on command line (simply using gcc, or cmake/make or so for more complex programs)
run program on console
Just use gcc.
Your could also use XCode to compile simple command line tools.
Start XCode
File -> New Project
Mac OS X -> Application -> Command Line tool
XCode has a really nice syntax highlighting and code completition and gdb integrated.
Follow on from PatrickS's answer - I didn't read the original question clearly, but personally - other than following a couple of ObjC tutorials - the only time I've used XCode is AS a C IDE.
The feedback on compile errors is neat (visually integrated into the IDE rather than having to match lines from the compiler output), and getting better (due to integration with the underlying clang project).

Is there an easier way to type and compile C on Mac OS X?

I've just started learning C on Mac OS X. I have downloaded Xcode too.
So far, I have been typing my apps into TextEdit, and then using the Terminal to locate my apps and compile them using gcc hello.c etc.
Is there an easier way (using Xcode perhaps?) to type my code into some form of IDE, and then automate the compiling with a 'compile and run' button or similiar? It seems a bit primitive and tedious using TextEdit and then switching to the Terminal to compile. However, I do not have much experience with lower level languages like C, so I'm unsure if it is even possible.
Thanks
Yes that is what XCode is for.
Look at the tutorial on the open screen of XCode (version 3.2.1 for OSX 10.6) This is for objective C but the tools are the same.
Or if the objective C is confusing choose a new project from XCode. File->New Project) choose command line tool as the project type and then choose type as C from the pop up menu
Xcode will definitely be easier, although for a "hello world"-type project like yours, its advantages may not be obvious. Install it, fire it up, and leave TextEdit behind ...
OTOH, you could edit your source code in vi or emacs (in Terminal), which would avoid having to flip between Terminal and TextEdit. BTW, this is the way development used to be done ...
Use XCode, you already have it. :)

Is there a compiler or IDE for C on Windows that's regarded as an industry standard? [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.
Taking advice from this post, I purchased a copy of 'The C Programming Language' and am happily reading my way through.
However, all the stuff I've written in the past has been interpreted, and I have no idea where to look for a good C compiler or an IDE (is there even one?). Google searches throw up a lot of results for C++ compilers, which I don't think is the same thing? Haha. I was wondering if there is a compiler or IDE for C that's regarded as an industry standard (kinda in the same way that Zend Studio is pretty much the IDE for PHP), or at least one that is generally considered to be a good quality product.
I'm surprised no-one's mentioned Pelles C. Great little C IDE for Windows; includes an LCC-based compiler. That said, NetBeans 6.5 has decent support for C and C++, and Code::Blocks is well worth a whirl.
Well, Visual Studio is the standard on Windows, and there are free versions available. However it does have a bunch of Microsoft specific extensions.
For learning though, developing console apps are pretty easy and also fairly close to the standard K&R style C.
However, way back in the day I used to use Watcom, which was also pretty good for the time. It's a lot more sparse than Visual Studio, but that can be an advantage for a beginner.
I believe it's also available for free these days at http://www.openwatcom.org/index.php/Main_Page
I'd probably recommend starting with that, if your main O/S is Windows.
Edit: new live url
Most people use Microsoft Visual Studio for development on Windows. You can get a free version here:
http://www.microsoft.com/express/download/.
Usually GCC is used on Unix, and is typically included with the OS.
C and C++ are very similar, but C++ allows classes. Most C++ compilers will compile C code.
I used DevC++ almost exclusively while I was in University for C\C++ programming. It comes bundled with the MinGW compiler. It's pretty easy to get set up and rolling. Other than this, my only other recommendation would be Visual Studio.
Almost all C++ compilers will compile C code.
I would recommend using Microsoft Visual Studio. There is a free version of it.
Most C programmers like to have their own editor and choose a compiler that fits their project. That is why you can download multiple different compilers for C and not so many built into IDE's directly.
It is easy to use editors like Editplus or even Notepad. Some of the fancier editors have syntax highlighting and can run commands in a command window for you.
IDE's usually support multiple languages as well. So when you are tired of C and want to move on to Python, Java, C++, some IDE's can help you do that. I would look into these:
Eclipse :: http://www.eclipse.org/callisto/c-dev.php
Microsoft Visual Studio :: http://www.microsoft.com/express/
GCC (GNU Compiler) and vi/emacs (or pico for uber-newbies)
Addendum: remember C is NOT a subset of C++, so a c++ compiler is not necessarily appropriate.
I recommend Quincy when you are just learning to program in C/C++. Simple to use and created for easily trying out small C/C++ programs.
You can download the Digital Mars C compiler for Windows for free.
Another good IDE is CodeBlocks, and its cross platform. Give it a try you might like it. I used it for a while an it gave me good results for what i was doing ( an image editor in C ), but it had some bugs.
For unix developing i've always liked using gcc plus an editor... it just makes it fun ( after you get use to it ).
When it comes to c/c++ compilers on the Windows platform there are quite a few to choose from.
And when it comes to and IDE, the Zeus IDE can be easily configured to work with any of them.
I used DevC++ when learning C years ago. It was a great tool, although I haven't seen it in a while so I'm not sure what state it is in now.
http://www.bloodshed.net/devcpp.html
For the record, I used TCC, the Tiny C Compiler, to quickly test small code. It can generate exe and DLLs.
You might need to download the Windows headers: it has a limited subset, you might want more.
Digital Mars also has a free C/C++ compiler of reasonable size.
GNU C is pretty much an industry standard, even if its a unixy compiler.
You can also use Visual Studio, but keep in mind it doesnt support C99 very well.
Other choices are out there, like pcc (I really like this one), llvm (also very interesting), etc, but those usually require some level of enthusiasm.
The free country website has a list of free C compilers. Many of which work on Windows.
You could use a C++ compiler, such as gcc, to compile your C code. Here's a good article with links to free C compilers/IDEs:
http://computerprogramming.suite101.com/article.cfm/freeprogrammingtools
Simply because the white book is influential, doesn't mean it's a good learning resource!
It is possibly the worst way to learn a language from that has ever existed. On top of that, last time I checked it was unreasonably expensive.
It's a complete language definition, and is good at that (which is why it truly is one of the most influential programming books). For a long time it actually was THE definition of C.
You might consider a second book on the subject.
That said, you should try quite a few different IDEs and see what you are happy with.
In fact, at first you might want to get used to vi/emacs/notepad/make and command-line compiling, this will get you a much stronger understanding of your environment (and if it's not understanding you're after, then you are barking up the wrong language-tree).
As you are investigating different IDEs, I'd give Eclipse or Netbeans with a c plugin a try. They are going to be the most complete and reliable IDEs (except, probably, for Microsoft's) and are platform independent so you won't be left in the cold when you decide to go to the Mac or Linux.

Resources