Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ScKaSx

macrumors regular
Original poster
Feb 27, 2006
105
0
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

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
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

macrumors 6502a
Jun 17, 2003
873
3
ScKaSx said:
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

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
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

macrumors regular
Original poster
Feb 27, 2006
105
0
More Specifically....

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

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
ScKaSx said:
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:

Code:
#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

macrumors 6502a
Jun 17, 2003
873
3
ScKaSx said:
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.

ScKaSx said:
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.
 

ScKaSx

macrumors regular
Original poster
Feb 27, 2006
105
0
Thanks but still having some issues

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.