# Installing libZFS



## Henu (Jul 21, 2009)

I'm trying to look for libzfs for FreeBSD, but since I'm totally noob with FreeBSD the progress has been little bit slow. At the beginning I noticed that I already have shared objects of libzfs on my system, but header files are missing.

So then I found out that I can install libzfs by selecting distribution set "cddl" using sysinstall. That really bring me libzfs.h, but it is in very strane location (/usr/src/cddl/contrib/opensolaris/lib/libzfs/common/) and I think that packet didn't bring any library(.so, .a) files. I found Makefile from directory /usr/src/cddl/lib/libzfs and a bunch of .c files from elsewhere and though that maybe I need to compile the libzfs by myself after I have got the files using sysinstall. I tried to compile it, but it complained that file "pathnames.h" was missing. So I guess I'm missing some depedency.

At this point I though it is good idea to write here. Does anyone know what I'm doing wrong? If I'm missing some depedency, how should I know which one or is there some automatical system that would take care of these?


----------



## Djn (Jul 21, 2009)

More to the point, what are you trying to do?
By the looks of it, libzfs is mainly used during a buildworld (I assume the ZFS userland tools use it), and isn't really something you'd otherwise touch.


----------



## Henu (Jul 21, 2009)

I'm making a program that needs to handle ZPools and snapshots and in future maybe some other things.


----------



## Henu (Jul 22, 2009)

I noticed that only one simple define is needed from the missing file, so I tried to make a guess what it would be. After this, the whole CDDL compiled(make) and installed(make install) nicely, but I still have no libzfs.h file in any reasonable location (like /usr/include). It just exists in that strange location that I mentioned in the first post. Other libzfs files (libzfs.so and libzfs.a, etc.) were installed nicely under /usr/lib


----------



## bb (Jul 22, 2009)

Forget about compiling libzfs.

Looking at /usr/src/cddl/sbin/zfs/Makefile, and /usr/src/cddl/Makefile.inc, you can learn the compile flags you'll need for your prog on FreeBSD.

For example, you can write your Makefile like this:

```
PROG=		myzfsprog
NO_MAN=		1
SRCS=		myzfsprog.c

CFLAGS+=	-I/usr/src/cddl/contrib/opensolaris/lib/libzpool/common
CFLAGS+=	-I/usr/src/cddl/compat/opensolaris/include
CFLAGS+=	-I/usr/src/cddl/compat/opensolaris/lib/libumem
CFLAGS+=	-I/usr/src/sys/cddl/compat/opensolaris
CFLAGS+=	-I/usr/src/cddl/contrib/opensolaris/head
CFLAGS+=	-I/usr/src/cddl/contrib/opensolaris/lib/libuutil/common
CFLAGS+=	-I/usr/src/cddl/contrib/opensolaris/lib/libzfs/common
CFLAGS+=	-I/usr/src/cddl/contrib/opensolaris/lib/libumem/common
CFLAGS+=	-I/usr/src/cddl/contrib/opensolaris/lib/libnvpair
CFLAGS+=	-I/usr/src/sys/cddl/contrib/opensolaris/uts/common
CFLAGS+=	-I/usr/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
CFLAGS+=	-I/usr/src/sys/cddl/contrib/opensolaris/uts/common/sys
CFLAGS+=	-DNEED_SOLARIS_BOOLEAN

DPADD=		${LIBZFS} ${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} \
		${LIBM} ${LIBNVPAIR} ${LIBUUTIL} ${LIBUTIL}
LDADD=		-lzfs -lgeom -lbsdxml -lsbuf \
		-lm -lnvpair -luutil -lutil

.include <bsd.prog.mk>
```

May I ask, what your program will be about?

Did you check for licensing issues when linking to the libzfs?

I'm also interested in programming against this lib, but I didn't even take a look into the header, as I think I can do stuff by calling the tools (zpool, zfs). That way, I wouldn't have to learn about the cddl license.


----------



## Henu (Jul 23, 2009)

Thanks for the Makefile. I already started to use ZFS via those tools from my program but I'll move to libzfs in some point. CDDL is not a problem for me.


----------



## Henu (Sep 2, 2009)

I finally had time to try that Makefile, and it works well if I put C-sources to the root directory of my project. But I would like to put them under subdirectory "src". And I'm also using C++ instead of C, so here is another problem.

Putting C files under src caused make to complain about missing object files (it however made them to root of my project, but could not find them). Naming files to .cpp or .cc caused linker to complain "undefined reference to `__gxx_personality_v0'".

I have tried to find a good documentation about the Make of FreeBSD but I have found nothing. At least I haven't find anything that describes where those "magical" SRCS, MYPROG, etc. names come from.

Is there anyone who knows good Make docs/howtos or who can give the commands/variables straight?

EDIT: It seems, that if I use magical variable PROG_CXX instead of PROG, make magically realizes to use C++.


----------



## bb (Sep 8, 2009)

/usr/share/mk/bsd.README


----------



## Henu (Sep 9, 2009)

bb said:
			
		

> /usr/share/mk/bsd.README



I checked that file, but I still don't know how to put source files to subdirectory. Maybe I should read more of it.

I noticed, that some programs that had their source in subdir, had also another Makefile in that subdir. Is that a correct way to do it?


----------



## bb (Sep 10, 2009)

> I noticed, that some programs that had their source in subdir, had also another Makefile in that subdir. Is that a correct way to do it?


yes.

you should have one Makefile per directory and use bsd.subdir.mk to descend into the child directories.

please note that you cannot use the bsd makefiles on other systems like solaris or darwin. if this is an issue, you'll have to switch to automake anyway.


----------



## xfelix (Feb 11, 2011)

> Did you check for licensing issues when linking to the libzfs?
> 
> I'm also interested in programming against this lib, but I didn't even take a look into the header, as I think I can do stuff by calling the tools (zpool, zfs). That way, I wouldn't have to learn about the cddl license.




Did you have chance to evaluate licening issue around using libzfs


----------



## zester (Jan 27, 2012)

There's no real issue with the CDDL. You just have to license your code under the CDDL and you have to make the source available to anyone you distribute your application to. Almost as restrictive as the GPL.


----------

