PDA

View Full Version : How Do I Install New Libraries in gcc compiler




ScKaSx
Mar 8, 2006, 04:43 PM
Hi All,

Just wondering how I would install (or where to place) new libraries that I would like to include into my programming. Thanks! Also does anyone know how I can get the function "plot" to work in the unix shell. It works on PC's, but I can't seem to get it to work with the mac yet. Thanks again.

Cheers,
ScKaSx



caveman_uk
Mar 8, 2006, 05:26 PM
Generally speaking, it's considered good practise to have all the additional libraries/resources etc you need in the application bundle you ship. It's considered bad to leave stuff littering a users machine all over the place.

mrichmon
Mar 8, 2006, 06:38 PM
Also does anyone know how I can get the function "plot" to work in the unix shell. It works on PC's, but I can't seem to get it to work with the mac yet.

Without some description of the "plot" function you mention, I doubt you will get much help. The unix shell does not invoke "functions", rather the unix shell launches "commands".

MarkCollette
Mar 8, 2006, 07:25 PM
Are you using gcc on the command line, with a makefile, or via XCode? Are the libraries statically linked, or dynamically linked shared libraries?

ScKaSx
Mar 8, 2006, 07:27 PM
Issue 1:

I have a header file called tnt.h, which I want to evoke in my code. However, I can't seem to run it if it's in the same directory. I figured if I could put it where the other libraries are: stdio.h, etc. I could run it. Is this false thinking, if so WHAT do I do, and if not, WHERE do I save the libraries.

Mark, I am using a makefile. I believe the libraries are statically linked (what does that mean off-hand, that I'm changing the libraries?) Thanks.

Issue 2:

The command is called "plot". It's under the GNU plot utilites which is apparently on PC's stock, whereas it is not on the mac. I am trying to use old code from a PC on my mac, which is why I wanted this command.

Cheers

MarkCollette
Mar 8, 2006, 08:15 PM
Issue 1:

I have a header file called tnt.h, which I want to evoke in my code. However, I can't seem to run it if it's in the same directory. I figured if I could put it where the other libraries are: stdio.h, etc. I could run it. Is this false thinking, if so WHAT do I do, and if not, WHERE do I save the libraries.

Mark, I am using a makefile. I believe the libraries are statically linked (what does that mean off-hand, that I'm changing the libraries?) Thanks.

Issue 2:

The command is called "plot". It's under the GNU plot utilites which is apparently on PC's stock, whereas it is not on the mac. I am trying to use old code from a PC on my mac, which is why I wanted this command.

Cheers

If you want to use tnt.h, from the same directory as your source files, then do this:


#include <stdio.h>
#include "tnt.h"

int main(int argc, char *argv[]) {
...
}


Alternatively, there is an argument to gcc, I think -I to add another directory to the include path. So, if tnt.h is somewhere else, then do:

gcc -I/path/to/tnt-includes myfile.cpp

In this case you'd still do:

#include <tnt.h>


Keep in mind that the header file usually just gives function prototypes. The actual code is in .cpp files, and can be assembled into a static library library with a .lib extension, or a dynamic library with a .so or .dynlib (I think) extension. So, when compiling you're trying to use the right header file, and when linking you're trying to use the right library. I think gcc has -L and -l (lowercase L) arguements to specify the library directory, and library name, respectively. For example, on some platforms, if you use sockets, you give a -lsocket argument to the linker. The -L/path/to/libraries argument is typically not necessary for socket or math libraries because they're in some standard location that's already on the library search path.

The difference between static libraries and shared libraries is that static libraries become part of your executable. On Win32, your .exe file would contain that code. Shared libraries on Win32 are .dll files, which your .exe connects to at runtime.

Now, you refer to the "plot" command. Do you mean command line program, or do you mean C/C++ function?

mrichmon
Mar 8, 2006, 09:29 PM
I have a header file called tnt.h, which I want to evoke in my code. However, I can't seem to run it if it's in the same directory. I figured if I could put it where the other libraries are: stdio.h, etc. I could run it.

A header file is not a library. When you compile your code and link it correctly the contents of the header file will be linked into the resulting executable. There is no way to "run" a header file because a header file does not contain executable code.

The command is called "plot". It's under the GNU plot utilites which is apparently on PC's stock, whereas it is not on the mac. I am trying to use old code from a PC on my mac, which is why I wanted this command.

GNU plot is not installed on a stock Windows system. None of the GNU software is shipped as part of any Windows install. Microsoft have made it very clear that Microsoft as a whole abhors open source software. All GNU software is very much open source.

You can download and install GNU plot under OS X. One of the easiest ways to do this is to download and install "fink" then run fink to install GNU plot. Fink is a package management system that makes it easy to install a wide range of open source programs.

jeremy.king
Mar 9, 2006, 12:45 PM
Is this the plotting you are talking about? (http://gamma.magnet.fsu.edu/install/mac/gnuplot/index.html#GNUPLOT)

ScKaSx
Mar 9, 2006, 07:34 PM
Hey Guys,

Thanks for the help (especially you Mark, you seem to be much more adept at programming than myself). I am continuing to work on your suggestions, with little luck as of yet. Here's the makefile I'm running if there's anything obviously wrong, plz let me know:
CC = g++
FF = g77
CLIB = -lm

LIBS = -L/usr/lib/lg2c
CFLAGS = -Wall -I./tnt
FFLAGS =
OBJS = fit1.o lmdif.o
main: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LIBS) $(CLIB) -o run
fit1.o: fit1.cc
$(CC) $(CFLAGS) -c fit1.cc
lmdif.o: lmdif.f
$(FF) $(FFLAGS) -c lmdif.f

I still get an error with not being able to find tnt or lg2c. I will continue to give this a shot.

The plot is a command in unix. I realize now it's not built-in with the windows software but when I type "man plot" in the unix shell it recognizes it. I can't seem to find this command or similar one for the unix on mac. Kingjr3 thanks for the gnuplot link, I tried that and my only concern with it is that it seems to be more of a program than a command. Thanks.

cheers,
ScKaSx