1

I'm actually doing a make and make install in the LVM source code directory so I can compile and link my application using -ldevmapper.

I'm wondering if this is the only way (correct way) to build/link applications using libdevmapper ?

ydev
  • 25
  • 4

2 Answers2

2

You can use this to just build libdevmapper and use it in your own project.

make device-mapper

And the libdevmapper.so in lvm2/libdm/libdevmapper.so is what you want.
You still need to use ./configure to generate the lvm2 makefile
Here's my Makefile in my libdevmapper related project. I put the lvm2 source in the sub-dir just under my project dir.

main: libdevmapper.so libdevmapper.h 
    gcc -ldevmapper main.c -o main
libdevmapper.so:
    cd ./lvm2&&./configure
    make -C ./lvm2 device-mapper
    cp ./lvm2/libdm/libdevmapper.so .
libdevmapper.h:
    cp lvm2/libdm/libdevmapper.h .
waTer
  • 21
  • 7
0

The preferred method seems to be to use pkg-config, as I find a devmapper.pc on my system. (It sometimes occurs that upstream projects ship no .pc file, and distros add one, as is e.g. the case with openssl IIRC, so the presence of a devmapper.pc file in the distro I happen to use may not need to mean anything.)

From your configure.ac, you would invoke like for example

PKG_CHECK_MODULES([libdevmapper], [devmapper >= 1.02.48])

and putting this to use in Makefile.am:

AM_CPPFLAGS = ${libdevmapper_CFLAGS}
bin_PROGRAMS = foo
foo_LDADD = ${libdevmapper_LIBS}

(I chose >=1.02.48 here because that was one version where the "-EBUSY problems" seemed to be fixed; the problem seemed to entail that trying to disassociate dm devices sometimes returned -EBUSY because the linux block layer was not finished using these, e.g. directly after the umount syscall completed.)

jørgensen
  • 10,149
  • 2
  • 20
  • 27