# Where to put C++ Libraries



## physicsgrad (Mar 20, 2005)

Hello,
 I am new to programming and I am learning C++.  I am a physics grad student and I am learning to write simple programs which model physical systems.  I have been doing my programming using emacs from the OSX terminal.  

 I have had to download some math libraries for C++.  Where do I put them?

 I'm using a 700MHz iMac and 10.2.8.

 Thanks in advance.


----------



## Viro (Mar 20, 2005)

You can put them anywhere. Though on Unix systems, it is customary to put them in /usr/local/. The library files (.a, .dylib, etc) will go into /usr/local/lib while the header files will all go into /usr/local/include.

In order to get the compiler to look into those directories when compiling, you need to specify them. You do that by passing the flag -I/usr/local/include to tell the compiler to look there for include files, and -L/usr/local/lib to tell the linker to look there for the libraries.


----------



## vina_melody (Mar 20, 2005)

Helo...what is the best editor for creating c++ ? well, i never try that in mac


----------



## Viro (Mar 20, 2005)

Any editor works. I use either SubEthaEdit or Jedit. They're both good.


----------



## vina_melody (Mar 21, 2005)

hmm... is there freeware one?


----------



## wiz (Mar 21, 2005)

both are.


----------



## mkwan (Apr 3, 2005)

I like to use vim...with some vim customization and terminal emulation tweaks...one can get colors in the coding


----------



## Viro (Apr 4, 2005)

Yes, but vim has IMHO some rather poor support for working with many files. I've grown to heavily rely on tabs .


----------



## vina_melody (Apr 5, 2005)

I already install the SubEthaEdit but I don't know how to compile the .cpp into .obj like the one the Visual Studio ... 

ps: i'm completely new doing c++ in mac fiuhh...


----------



## Viro (Apr 5, 2005)

SubEthaEdit is a text editor. If you want to use it for C++ development, you will need to learn to work with the command line. http://users.actcom.co.il/~choo/lupg/tutorials/c-on-unix/c-on-unix.html

If you'd like something like Visual Studio, look at XCode.


----------



## Ifrit (Apr 25, 2005)

hello,

in order to compile source written in C/C++, do the following steps:

1. Install XCode (if it isn't already installed)
2. Open Terminal
3. cd to the directory, where the source resists
4. use GCC to compile your source, in order to get a obj. file

one example: gcc -c test.c

which will produce a file called test.o which is the object file.
In order to produce a MACH-O Executable file link them using GCC in the following manner:

gcc -o test test.o

The -o means to create a executable called test by linking test.o with several other libs.

You can also use ld instead.

To link more than one file, enter them after the other object files.

To run them enter the name of the produced exec-file.

./test

will run the exec-file test.


----------



## wadesworld (Apr 30, 2005)

While the post above is correct, I just want to point out a few things to new programmers.

Outputting to an object file is not usually necessary for simple projects.  You can just do:

gcc test.c -o test

This will automatically compile and link your app, and produce and executable called test, which you would run by typing ./test

Additionally, trying to compile C++ files with the gcc command won't work unless you specify the C++ libraries.  If you use the command c++ instead, it will automatically link the right libraries.

Wade


----------

