Where to put C++ Libraries

physicsgrad

Registered
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.
 
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.
 
I like to use vim...with some vim customization and terminal emulation tweaks...one can get colors in the coding
 
Yes, but vim has IMHO some rather poor support for working with many files. I've grown to heavily rely on tabs :).
 
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...
 
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.
 
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
 
Back
Top