Compiling C applications
Ian Lance Taylor
iant@google.com
Mon Sep 28 17:52:00 GMT 2009
"Marcus Carey" <marcuscarey@mlcarey.com> writes:
> I have an application that uses the Mysql C-API and another library.
>
> The application is on a remote host and I must compile it using the
> -shared flag to use the Mysql C-API.
>
> My problem is I need to use the static version of the second library.
>
> Is it possible to compile an application with gcc that uses both
> shared and static libraries?
I'm not sure I really understand your question.
If you need to use the -shared flag, that implies that the MySQL C-API
does a dlopen of a shared library which you provide. That is possible
but it doesn't seem very likely to me.
In any case, if you have a static library, and you need to link it
into a shared library, and the static library was not compiled with
-fPIC, then you are in trouble on some platforms. On x86_64 in
particular, you can not link code compiled without -fPIC into a shared
library. So if that is your platform, you need to recompile the
static library with -fPIC. And compiling with -fPIC will be advisable
on any platform for code which goes into a shared library.
Ian
More information about the Gcc-help
mailing list