I would like to package my software (in C) into a .deb file, but I encounter some difficulties. It would be nice if someone could give me a hand.

Let the source code be the following toy example:

#include <stdio.h>
#include <stdlib.h>
#include <lbfgs.h>

int main(void)
    printf("liblbfgs will be used here!\n");
    return 0;

In the above C program, liblbfgs library will be used. liblbfgs is available in repos. I have written the following simple Makefile:

CFLAGS=-Wall -g
LIBS=-lm -llbfgs

    $(CXX) -o $(OUTPUT) $(LIBS) $(OUTPUT).o

.PHONY: clean

    rm -f *~ *.o

If I install the library via synaptic/apt-get or by manually compiling the available source code, and by building the above code, everything is alright. But it would be very desired to avoid installing liblbfgs first. For this reason, I want to package my software into a .deb file where I should define liblbfgs as a dependency.

I create a folder, say toypackage_1.0/, where I store the source code and the Makefile. Then I compress this directory as

tar czvf toypackage_1.0.orig.tar.gz toypackage-1.0/

Then, I run dh_make as follows

$ cd toypackage-1.0/
$ dh_make

Type of package: single binary, indep binary, multiple binary,     library, kernel module, kernel patch?
  [s/i/m/l/k/n] s

  Maintainer name  : geppetto
  Email-Address    : geppetto@phi 
  Date             : Fri, 06 Jun 2014 16:25:22 +0300
  Package Name     : toypackage
  Version          : 1.0
  License          : blank
  Type of Package  : Single
  Hit <enter> to confirm: 
  Skipping creating ../toypackage_1.0.orig.tar.gz because it already exists
  Done. Please edit the files in the debian/ subdirectory now. You should also
  check that the toypackage Makefiles install into $DESTDIR and not in / .

$ debuild

  dpkg-buildpackage -rfakeroot -D -us -uc
  dpkg-buildpackage: source package toypackage
  dpkg-buildpackage: source version 1.0-1
  dpkg-buildpackage: source distribution unstable
  dpkg-buildpackage: source changed by geppetto <geppetto@phi>
  dpkg-source --before-build toypackage-1.0
  dpkg-buildpackage: host architecture amd64
  fakeroot debian/rules clean
  dh clean 
  make[1]: Entering directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
  rm -f *~ *.o
  make[1]: Leaving directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
  dpkg-source -b toypackage-1.0
  dpkg-source: info: using source format `3.0 (quilt)'
  dpkg-source: info: building toypackage using existing ./toypackage_1.0.orig.tar.gz
  dpkg-source: info: building toypackage in toypackage_1.0-1.debian.tar.xz
  dpkg-source: info: building toypackage in toypackage_1.0-1.dsc
  debian/rules build
  dh build 
  make[1]: Entering directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
  cc -Wall -g -D_FORTIFY_SOURCE=2  -c -o toypackage.o toypackage.c
  gcc -o toypackage -lm -llbfgs toypackage.o
  make[1]: Leaving directory '/home/geppetto/LAB/Debian_Packaging/ToyPackage/toypackage-1.0'
  fakeroot debian/rules binary
  dh binary 
  dpkg-gencontrol: warning: Depends field of package toypackage: unknown substitution variable ${shlibs:Depends}
  dpkg-deb: building package `toypackage' in `../toypackage_1.0-1_amd64.deb'.
  dpkg-genchanges  >../toypackage_1.0-1_amd64.changes
  dpkg-genchanges: including full source code in upload
  dpkg-source --after-build toypackage-1.0
  dpkg-buildpackage: full upload (original source is included)
  Now running lintian...
  E: toypackage changes: changed-by-address-malformed geppetto <geppetto@phi>
  W: toypackage source: dh-make-template-in-source debian/init.d.ex
  W: toypackage source: dh-make-template-in-source debian/manpage.1.ex
  W: toypackage source: dh-make-template-in-source debian/manpage.sgml.ex
  W: toypackage source: dh-make-template-in-source debian/manpage.xml.ex
  W: toypackage source: dh-make-template-in-source debian/menu.ex
  W: toypackage source: dh-make-template-in-source debian/postinst.ex
  W: toypackage source: dh-make-template-in-source debian/postrm.ex
  W: toypackage source: dh-make-template-in-source debian/preinst.ex
  W: toypackage source: dh-make-template-in-source debian/prerm.ex
  W: toypackage source: dh-make-template-in-source debian/toypackage.cron.d.ex
  W: toypackage source: dh-make-template-in-source debian/toypackage.default.ex
  W: toypackage source: dh-make-template-in-source debian/toypackage.doc-base.EX
  W: toypackage source: dh-make-template-in-source debian/watch.ex
  W: toypackage source: package-needs-versioned-debhelper-build-depends 9
  E: toypackage source: maintainer-address-malformed geppetto <geppetto@phi>
  W: toypackage source: superfluous-clutter-in-homepage <insert the upstream URL, if relevant>
  W: toypackage source: bad-homepage <insert the upstream URL, if relevant>
  W: toypackage source: out-of-date-standards-version 3.9.4 (current is 3.9.5)
  W: toypackage: wrong-bug-number-in-closes l3:#nnnn
  E: toypackage: debian-changelog-file-contains-invalid-email-address geppetto@phi
  W: toypackage: new-package-should-close-itp-bug
  E: toypackage: changelog-is-dh_make-template
  E: toypackage: helper-templates-in-copyright
  W: toypackage: copyright-has-url-from-dh_make-boilerplate
  E: toypackage: copyright-contains-dh_make-todo-boilerplate
  W: toypackage: readme-debian-contains-debmake-template
  E: toypackage: description-is-dh_make-template
  E: toypackage: maintainer-address-malformed geppetto <geppetto@phi>
  E: toypackage: section-is-dh_make-template
  W: toypackage: superfluous-clutter-in-homepage <insert the upstream URL, if relevant>
  W: toypackage: bad-homepage <insert the upstream URL, if relevant>
  Finished running lintian.
  Now signing changes and any dsc files...
  signfile toypackage_1.0-1.dsc geppetto <geppetto@phi>
  gpg: skipped "geppetto <geppetto@phi>": secret key not available
  gpg: /tmp/debsign.wQjBHrJP/toypackage_1.0-1.dsc: clearsign failed: secret key not available
  debsign: gpg error occurred!  Aborting....
  debuild: fatal error at line 1283:
  running debsign failed

It seems a bit erroneous, but if I

$ cd ..
$ sudo dpkg -i toypackage_1.0-1_amd64.deb

[sudo] password for geppetto: 
Selecting previously unselected package toypackage.
(Reading database ... 426247 files and directories currently installed.)
Preparing to unpack toypackage_1.0-1_amd64.deb ...
Unpacking toypackage (1.0-1) ...
Setting up toypackage (1.0-1) ...

$ cd ./toypackage-1.0/
$ cd ./toypackage

liblbfgs will be used here!

then I see that the code has been built correctly, as I have already installed liblbfgs via apt-get.

Here are my questions:

  • What if I have not installed liblbfgs before? What should I do to be able to build my code correctly?
  • What would be a meaningful Makefile for my purposes? Could you suggest me how to change it using $DESTDIR$ in order the binaries are stored to /usr/bin/?
  • 1
    You generally need to build in a clean chroot or other custom minimal build environment. see sbuild, pbuilder, or similar. I'd check out the hello package in Debian. apt-get source hello. Also, the #debian-mentors channel on oftc is quite helpful, if you have packaging questions. Bear in mind they are focused on packagers that are trying to get their package into Debian, so they may make suggestions about things you don't need to care about unless you want your software in Debian. – Faheem Mitha Jun 6 '14 at 14:44
  • if you want help with the packaging, another option is to talk on U&L chat. I am usually in chat. So are a few other people. – Faheem Mitha Jun 7 '14 at 15:48
  • What if I have not installed liblbfgs before? What should I do to be able to build my code correctly?

In order for build tools to notice that kind of dependencies, you need to specify it in the Build-Depends field of the debian/control file.

  • What would be a meaningful Makefile for my purposes? Could you suggest me how to change it using $DESTDIR$ in order the binaries are stored to /usr/bin/?

Your Makefile needs to have a install target, and that target needs to respect $DESTDIR (and also $PREFIX if you want to support things like FreeBSD). A good install target would look like:


    install -m 755 $(OUTPUT) $(DESTDIR)/$(PREFIX)/bin/$(OUTPUT)

See the destdir section of the very useful new maintainer guide.

  • First, thanks a lot for your response! But I think that there are some errors to your install target above: $(DESTDIR)/$(PREFIX)/bin/$(OUTPUT) would lead to //usr/bin/toypackage. But, even if I correct this in my Makefile, I cannot build my code... Apologies for being such a newbie, but may you provide a complete Makefile for my pursposes? Could you make corrections to my originally posted Makefile above? Thanks a lot! – nullgeppetto Jun 7 '14 at 8:38
  • P.s.: Nice site! – nullgeppetto Jun 7 '14 at 8:40
  • //usr/bin/toy is fine, even if it's not really pretty. why do you say you can't build your code? what's the error? – anarcat Jun 10 '14 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.