Ubuntu – Trouble creating library package

package-management

I am having some trouble creating a package for a shared library.

I ran dh_make and edited the files. However, when I go to build the package, I get the following:

******@******-laptop:~/Documents/temp/jsoncpp/jsoncpp-0.5.0$ debuild
 dpkg-buildpackage -rfakeroot -D -us -uc
dpkg-buildpackage: set CFLAGS to default value: -g -O2
dpkg-buildpackage: set CPPFLAGS to default value: 
dpkg-buildpackage: set LDFLAGS to default value: -Wl,-Bsymbolic-functions
dpkg-buildpackage: set FFLAGS to default value: -g -O2
dpkg-buildpackage: set CXXFLAGS to default value: -g -O2
dpkg-buildpackage: source package jsoncpp
dpkg-buildpackage: source version 0.5.0-1
dpkg-buildpackage: source changed by ****** 
dpkg-buildpackage: host architecture amd64
 fakeroot debian/rules clean
dh  clean
   dh_testdir
   dh_auto_clean
   dh_clean
 dpkg-source -b jsoncpp-0.5.0
dpkg-source: info: using source format `1.0'
dpkg-source: info: building jsoncpp using existing jsoncpp_0.5.0.orig.tar.gz
dpkg-source: info: building jsoncpp in jsoncpp_0.5.0-1.diff.gz
dpkg-source: info: building jsoncpp in jsoncpp_0.5.0-1.dsc
 debian/rules build
dh  build
   dh_testdir
   dh_auto_configure
   dh_auto_build
make[1]: Entering directory `/home/******/Documents/temp/jsoncpp/jsoncpp-0.5.0'
test -d obj || mkdir obj
g++ -I ./include -c -o obj/json_reader.o src/lib_json/json_reader.cpp
g++ -I ./include -c -o obj/json_writer.o src/lib_json/json_writer.cpp
g++ -I ./include -c -o obj/json_value.o src/lib_json/json_value.cpp
ar -r libjsoncpp.a obj/json_reader.o obj/json_writer.o obj/json_value.o
ar: creating libjsoncpp.a
make[1]: Leaving directory `/home/******/Documents/temp/jsoncpp/jsoncpp-0.5.0'
   dh_auto_test
 fakeroot debian/rules binary
dh  binary
   dh_testroot
   dh_prep
   dh_installdirs
   dh_auto_install
make[1]: Entering directory `/home/******/Documents/temp/jsoncpp/jsoncpp-0.5.0'
sudo cp -r include/json --target-directory=/usr/include
ERROR: ld.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded: ignored.
cp libjsoncpp.a /usr/lib/libjsoncpp.a
cp: cannot create regular file `/usr/lib/libjsoncpp.a': Permission denied
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/******/Documents/temp/jsoncpp/jsoncpp-0.5.0'
dh_auto_install: make -j1 install DESTDIR=/home/******/Documents/temp/jsoncpp/jsoncpp-0.5.0/debian/tmp returned exit code 2
make: *** [binary] Error 29
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2
debuild: fatal error at line 1340:
dpkg-buildpackage -rfakeroot -D -us -uc failed

The problem seems to be here:

ERROR: ld.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded: ignored.
cp libjsoncpp.a /usr/lib/libjsoncpp.a
cp: cannot create regular file `/usr/lib/libjsoncpp.a': Permission denied

…but I haven't the faintest idea what the problem is.

The makefile is here if needed.

Best Answer

The Makefile you are using is not respecting the DESTDIR variable - packages should never install directly into /usr at build time, but instead put files into a temporary tree. You've mentioned that you added the Makefile yourself - the usual case is that you'd need to make it use the DESTDIR variable as a prefix for all install paths. Having looked at the package build instructions, the package uses scons as a build system, which is a replacement of sorts for make. dh_make most likely doesn't have a template for building packages with this, so you should look for packages that do use it for building, such as yafray, and look at their debian/rules

As package builds are never done as root, it is better to have this error shown & corrected rather than having a package overwrite important files as the package is being built on an unsuspecting developer's system.

Related Question