2

I am doing a project for which I need to compile a source code. The code uses the PBC library (which in turn needs the GMP, both of which have been installed). The Makefile has this line :

node: node.o $(COMMON_OBJS)
g++ -m32 -g -static -o $@ $^ -L../PBC -lPBC -lpthread -lgnutls -lpbc -lgmp -lgcrypt -lgpg-error -ltasn1 -lz

But when I run make, I get this error :

/usr/bin/ld : cannot find -lgpg-error

Now this is quite frustrating as I don't know how to fix it. I tried installing libgcrypt11-div (saw a suggestion on some site). Didn't work.

I noticed that libgpg-error.so is installed in /usr/lib/i386-linux-gnu/. So I created link with ln -s in /usr/bin/. Still not working.

After adding the -v switch :

g++ -m32 -g -static -o node node.o application.o networkmessage.o usermessage.o buddy.o buddyset.o systemparam.o bipolynomial.o polynomial.o lagrange.o commitment.o commitmentmatrix.o commitmentvector.o io.o timer.o message.o -L../PBC -lPBC -lpthread -lgnutls -lpbc -lgmp -lgcrypt -lgpg-error -ltasn1 -lz -v

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6.1/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu

Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

COMPILER_PATH=/usr/lib/gcc/i686-linux-gnu/4.6.1/:/usr/lib/gcc/i686-linux-gnu/4.6.1/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6.1/:/usr/lib/gcc/i686-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/i686-linux-gnu/4.6.1/:/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../:/lib/:/usr/lib/

COLLECT_GCC_OPTIONS='-m32' '-g' '-static' '-o' 'node' '-L../PBC' '-v' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-linux-gnu/4.6.1/collect2 --build-id --no-add-needed --as-needed -m elf_i386 --hash-style=gnu -static -z relro -o node /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.6.1/crtbeginT.o -L../PBC -L/usr/lib/gcc/i686-linux-gnu/4.6.1 -L/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.6.1/../../.. node.o application.o networkmessage.o usermessage.o buddy.o buddyset.o systemparam.o bipolynomial.o polynomial.o lagrange.o commitment.o commitmentmatrix.o commitmentvector.o io.o timer.o message.o -lPBC -lpthread -lgnutls -lpbc -lgmp -lgcrypt -lgpg-error -ltasn1 -lz -lstdc++ -lm --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/i686-linux-gnu/4.6.1/crtend.o /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crtn.o
/usr/bin/ld: cannot find -lgpg-error
collect2: ld returned 1 exit status
make: *** [node] Error 1

Ajoy
  • 1,838
  • 3
  • 30
  • 57
  • Can you add the `-v` switch to gcc/g++? – slm Dec 29 '12 at 14:22
  • Did you add the switch? You should see the version of gcc/g++ and the library search path among other things. – slm Dec 29 '12 at 14:58
  • I ran sudo ldconfig -v | grep gpg '/sbin/ldconfig.real: Path `/usr/lib/i386-linux-gnu' given more than once /sbin/ldconfig.real: Path `/lib/i386-linux-gnu' given more than once /sbin/ldconfig.real: Path `/usr/lib/i386-linux-gnu' given more than once libgpg-error.so.0 -> libgpg-error.so.0.8.0 libgpgme-pth.so.11 -> libgpgme-pth.so.11.7.0 libgpgme.so.11 -> libgpgme.so.11.7.0 libgpgme++-pth.so.2 -> libgpgme++-pth.so.2.8.0 libgpgme++-pthread.so.2 -> libgpgme++-pthread.so.2.8.0 libgpgme-pthread.so.11 -> libgpgme-pthread.so.11.7.0 libgpgme++.so.2 -> libgpgme++.so.2.8.0 ' – Ajoy Dec 29 '12 at 15:15
  • And what if you try it without the `-static` switch? – slm Dec 29 '12 at 15:45
  • Looks like the package you need is `libgpg-error-dev`. Making your own symlink in `/usr/bin` is never a good idea. – tripleee Dec 29 '12 at 15:53
  • @slm Wonderful. Thanks , that did the trick. The code has compiled succesfully. – Ajoy Dec 29 '12 at 15:56
  • @tripleee I had already installed **libgpg-error-dev** but it still hadn't worked. Though I think I should remove the links from /usr/bin/. Thank you. – Ajoy Dec 29 '12 at 16:01
  • If you want to `-static` you need to wrap it around libraries that you want to be static and let the other libraries remain dynamic, otherwise gcc/g++ will try and go down into every library and compile everything statically which may not be possible. – slm Dec 29 '12 at 16:01

1 Answers1

1

Try removing the -static switch.

If you want to -static you need to wrap it around libraries that you want to be static and let the other libraries remain dynamic, otherwise gcc/g++ will try and go down into every library and compile everything statically which may not be possible.

See this SO post, Static link of shared library function in gcc.

For example to compile applejuice statically while everything else remaining dynamic:

gcc object1.o object2.o -Wl,-Bstatic -lapplejuice -Wl,-Bdynamic -lorangejuice
Community
  • 1
  • 1
slm
  • 15,396
  • 12
  • 109
  • 124