tags:

views:

190

answers:

3

I am creating a utility which depends on libassuan aside other depends. While these ‘others’ provide shared libraries, libassuan comes with static one only.

libassuan comes with simple libassuan-config tool which is meant to provide CFLAGS & LDFLAGS for the compiler/linker to use. These LDFLAGS refer to the library as -lassuan.

The result of standard call of make is then:

cc   -I/usr/include/libmirage -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include     -lmirage -lglib-2.0   -L/usr/lib64 -lassuan -o mirage2iso mirage2iso.c mirage-getopt.o mirage-wrapper.o mirage-password.o
mirage-password.o: In function `mirage_input_password':
mirage-password.c:(.text+0x1f): undefined reference to `assuan_pipe_connect'
mirage-password.c:(.text+0x32): undefined reference to `assuan_strerror'
collect2: ld returned 1 exit status
make: *** [mirage2iso] Error 1

(I've just started writing this unit and that's why there aren't more errors)

So, if I understand the result correctly, gcc doesn't want to link the app to libassuan.a.

Using -static here will cause gcc to prefer static libraries over shared which is unindented. I've seen solution suggesting using something like that:

-Wl,-Bstatic -lassuan -Wl,-Bdynamic

but I don't think it would be a portable one.

I think the best solution would be to provide full path to the static library file but libassuan-config doesn't provide much of help (all I can get from it is -L/usr/lib64 -lassuan).

Maybe I should just try to create the static library path by ‘parsing’ returned LDFLAGS and using -L for the directory name and -l for the library name — and then hoping that in all cases libassuan-config will return it like that.

What do you think about that? Is there any good, simple and portable solution to resolve the issue?

PS. Please note that although I'm referring to gcc here, I would like to use something that will work fine with other compilers.

PS2. One additional question: if package does install static library only, returning such LDFLAGS instead of full .la path can be considered as a bug?

A: 

Which directory is libassuan.a in

I think the first error is not gcc doesn't want to link the app to libassuan.a it is more gcc does not know where libassuan.a . You need to pass gcc a -L parameter giving the path to libassuan.a . e.g. -L /home/path

Mark
+1  A: 

gcc will link to libassuan.a if it doesn't find libassuan.so

It's probably the order symbols are looked up in the static library when you link. The order matters. ) Assuming gcc can find libassuan.a and it actually provides the functions the linker complains about, try:

cc -I/usr/include/libmirage -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lmirage -lglib-2.0 -L/usr/lib64 -o mirage2iso mirage2iso.c mirage-getopt.o mirage-wrapper.o mirage-password.o -lassuan

Since you say libassuan is under /usr/lib64 it's probably a 64 bit library, are your app and the other libraries 64 bit as well ?

nos
Michał Górny
+1  A: 

Compiler's command-line options are not a portable thing. There's no standard for it. Every compiler uses its own and several can merely informally agree to comply with each other in command-line format. The most portable way for your linking is to use libassuan-config, of course. I think, it can generate not only flags for gcc, but for other compilers as well. If it can't, then no portable way exists, I suppose (other than CMake or something on higher level).

The command line to cc you shown is totally correct. If you have a static library libassuan.la and path to it is supplied to -L option, then the compiler does link against it. You can see it from its output: has it not found the static library, would it complain with error message like "can't find -lassuan". I

Moreover, if no libassuan.so is found, then compiler links against your library statically, even if you haven't used -Wl,-Bstatic stuff or -static flag.

Your problem may be in persistence of several versions of libassuan in your system. Other that that, I don't see any errors in what you've provided.

Pavel Shved