# How can I compile the /usr/src/usr.sbin/gstat/gstat.c file?



## olav (Oct 28, 2010)

I want to do some minor modifications to it. (The long story is learning how it works and make a python module for fetching diskinfo).

I'm really a newbie when it comes to compile c sources. I've tried the following
[CMD="gcc"]/usr/src/usr.sbin/gstat/gstat.c -o /home/olav/gstat[/CMD]

But that command gave me a long screen with this error message repeated

```
undefined reference to `geom_gettree'
```

I guess it's some kind of a missing library error?

What steps should I take to create a build environment for the gstat application?


----------



## expl (Oct 28, 2010)

If you can't for some reason get root and build it in original path, copy it to your home and build by running make there.

`% cp -R /usr/src/usr.sbin/gstat ~/`
`% cd ~/gstat && make`


----------



## SIFE (Oct 28, 2010)

You have to link libgeom with your source, try this:

```
gcc /usr/src/usr.sbin/gstat/gstat.c -o /home/olav/gstat -ldevstat -lkvm -lgeom -lbsdxml -lsbuf -ledit -lcurses
```

It's gcc not ggc, the code is linked statically with other libraries, so you have to set them before compile it, best way to start is to read Makefile in its root directory.


----------



## olav (Oct 28, 2010)

Great! Thanks, that worked just fine!


----------



## wblock@ (Oct 28, 2010)

olav said:
			
		

> I want to do some minor modifications to it.(The long story is learning how it works and make a python module for fetching diskinfo).
> 
> I'm really newbie when it comes to compile c sources.
> I've tried the following
> [CMD="gcc"]/usr/src/usr.sbin/gstat/gstat.c -o /home/olav/gstat[/CMD]



Why not just use the Makefile already in that directory?  Being the official way to build it, everything will get done in the right way:

`# cd /usr/src/usr.sbin/gstat`
make your modifications
`# make install`


----------



## olav (Oct 29, 2010)

I need to learn more about how a make file works. Are there any "magic" in the make file for the gstat application?


----------



## expl (Oct 29, 2010)

http://en.wikipedia.org/wiki/Makefile


----------

