Using an IDE (ie. XCode) is IMO a horrible way to learn to start programming.
You miss out on how compilers and build tools work which IMO is an important part to being a good systems programmer.
If your professor is using cygwin, then the equivalent would be to install the Command Line Tools for XCode(you don't actually have to install XCode to use it) and use gcc from the Terminal.
Sorry about the late reply. I have XCode installed, but did not know how to use it for C programming, only to make apps.
How does gcc work? I am always wanted to learn it, seems like it's a really useful tool. Could anyone tell me how to gcc a C code on Lion? Thanks everyone!
Sorry about the late reply. I have XCode installed, but did not know how to use it for C programming, only to make apps.
How does gcc work? I am always wanted to learn it, seems like it's a really useful tool. Could anyone tell me how to gcc a C code on Lion? Thanks everyone!
I would recommend Stephen Kochans and Aaron Hillegass' books over anything from Apress.
http://www.amazon.com/Programming-3...d=1347532914&sr=8-1&keywords=Programming+in+C
Thanks for the recommendation. I tried learning C on the mac and failed to even get a compiler going that worked with the book I was reading. xCode just gave me errors!
I would recommend Stephen Kochans and Aaron Hillegass' books over anything from Apress.
http://www.amazon.com/Programming-3...d=1347532914&sr=8-1&keywords=Programming+in+C
Doing a quick search on google, gets me this:
http://www.informit.com/articles/article.aspx?p=1315356
Follow the directions under the one talking about Terminal to get an example of using gcc for ObjC. It's basically a little bit more complex than using gcc for C, where you'd be using a .c file instead of .m.
You'd best get yourself a basic C book to learn from if you want to proceed from that.
I am pretty new to Mac OS X, I want to program C code on Mac, what software/program should I use?
I was told by my prof to use Cygwin in Windows, but I have a Mac, what would be the equivalent? Or can I just run it in terminal?
...I've used CodeRunner for small C programs and if you are reading from a book, CodeRunner is perfect for that. I've also used Eclipse... and while people swear by it, I really couldn't get into it. I used it for like a semester. On the other hand, I've used Xcode and I think it's too bloated for someone beginning...
If you install the developer tools, you will get gcc and clang, which are the equivalent of cygwin.
You can then write code with the text editor of your choice, and compile with gcc. I'd suggest textwrangler, as it does C syntax highlighting amongst other languages, which will give you the most helpful IDE feature without forcing you to learn how to drive the IDE.
Yes, just installed it. Looks pretty good so far. For compiling on Cygwin I remember,
1. save hello.c in the same folder as Cygwin.
2. open up Cygwin, type gcc hello.c
3. done!
Since I don't have Cygwin here, where should I save the file for compiling, or just anywhere?
...You may want to learn how basic command line navigation works in the terminal (so you can save things in folders, navigate to them in the terminal and run gcc there, etc), but its as simple as that.
Thanks for the quick response, I asked on post #16,
"I was able to compile, but got an error saying "gsl/gsl_math.h" not found. I haven't used cygwin, but heard there's no problem. Does Mac not have all necessary libraries equipped?"
Compiler works, yay. I am mainly stuck with the library error now. Am I actually miss this library? Or am I missing the right command? I heard on Cygwin, this comes with it.
I was able to compile, but got an error saying "gsl/gsl_math.h" not found. I haven't used cygwin, but heard there's no problem. Does Mac not have all necessary libraries equipped?
$ port provides /opt/local/include/gsl/gsl_math.h
/opt/local/include/gsl/gsl_math.h is provided by: gsl
$ port info gsl
gsl @1.15, Revision 1 (math, science)
Variants: doc, gcc43, gcc44, gcc45, gcc46, gcc47, optimize, universal
Description: The GNU Scientific Library (GSL) is a numerical library for C
and C++ programmers. It is free software under the GNU General
Public License. The library provides a wide range of
mathematical routines such as random number generators, special
functions and least-squares fitting. There are over 1000
functions in total.
Homepage: http://www.gnu.org/software/gsl
Build Dependencies: texinfo
Conflicts with: gsl-devel
Platforms: darwin
License: GPL-3+
Maintainers:
sudo port install gsl
2.1 An Example Program
======================
The following short program demonstrates the use of the library by
computing the value of the Bessel function J_0(x) for x=5,
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int
main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
The output is shown below, and should be correct to double-precision
accuracy,(1)
J0(5) = -1.775967713143382920e-01
The steps needed to compile this program are described in the following
sections.
---------- Footnotes ----------
(1) The last few digits may vary slightly depending on the compiler
and platform used--this is normal.
$ cat > bessel.c << EOF
> #include <stdio.h>
> #include <gsl/gsl_sf_bessel.h>
>
> int
> main (void)
> {
> double x = 5.0;
> double y = gsl_sf_bessel_J0 (x);
> printf ("J0(%g) = %.18e\n", x, y);
> return 0;
> }
> EOF
$ gcc -Wall -I/opt/local/include -L/opt/local/lib -lgsl -o bessel bessel.c
$ ./bessel
J0(5) = -1.775967713143382642e-01
$
I'd be surprised if it did. Is your professor handing out a preconfigured cygwin environment, somehow?I heard on Cygwin, this comes with it.
I write code with Xcode and compile it with GCC.
Download xcode, prefences, find additional downloads and download command line tools.
From there write the code, save it, then open terminal and type gcc filenameofyourcode
it'll compile (hopefully!) then you should be able to run it in terminal
Thanks for your example. I am following what you did in terminal, does it look like it is installed?If you install macports, run:Code:sudo port install gsl
nbp-152-194:~ Colin$ sudo port install gsl
Password:
---> Fetching archive for gsl
---> Attempting to fetch gsl-1.15_2.darwin_11.x86_64.tbz2 from http://packages.macports.org/gsl
---> Attempting to fetch gsl-1.15_2.darwin_11.x86_64.tbz2.rmd160 from http://packages.macports.org/gsl
---> Installing gsl @1.15_2
---> Deactivating gsl @1.15_1
---> Cleaning gsl
---> Activating gsl @1.15_2
---> Cleaning gsl
---> Updating database of binaries: 100.0%
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.
nbp-152-194:~ Mike$