libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about static and shared libraries and their usage in a bina


From: Vincent Torri
Subject: Re: Question about static and shared libraries and their usage in a binary on Windows in a autotools project
Date: Tue, 10 Aug 2021 21:31:08 +0200

On Tue, Aug 10, 2021 at 9:21 PM Roumen Petrov
<bugtrack@roumenpetrov.info> wrote:
>
> Hi Vincent,
>
> Sorry for top posting.
>
> Perhaps is not easy visible for manual ( 
> https://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html
>  ) use of conditional code.
> In this case #ifdef PIC.
>
> Perhaps better solution is use of -export-symbols.

As I have said, the problem is not the lib itself. There is no problem
with the lib. The problem is with the binary : when I compile it,
there is no way to know if the library, that the binary uses, is a
static library or shared library (know == having a macro to
distinguish shared lib and static lib)

Vincent


> Vincent Torri wrote:
> > Hello
> >
> > I contribute to an autotools project. The tree is :
> >
> > src/lib/libfoo  <--- the library, with libfoo.h declaring the public symbols
> > src/bin/bar  <-- the binary which uses libfoo and includes libfoo.h in
> > its source files
> >
> > I want to create the library 'libfoo' on Windows. I also want to
> > declare public symbols with __declspec(dllexport) and
> > __declspec(dllimport) in a macro that I call MY_API in libfoo.h
> >
> > Thanks to DLL_EXPORT that libtool is passing to the preprocessor when
> > compiling the library 'libfoo', there is no problem to compile libfoo.
> > MY_API is correctly defined either when I build the static lib, or the
> > shared lib, or both.
> >
> > The problem I am facing is when I build the 'bar' binary. On Windows:
> >
> > 1) if 'lifoo' is built as a shared library, when I include libfoo.h in
> > 'bar' source files, MY_API must be defined as __declspec(dllimport)
> > 2) if 'libfoo' is built as a static library, when I include libfoo.h
> > in 'bar' source files, MY_API must be defined as nothing
> >
> > but, as far as I know, when I compile 'bar', I couldn't find a way to
> > know if 'libfoo' has been compiled as a static library or as a shared
> > library. I have looked at the 'bar' source files gcc calls, and they
> > are the same in both cases (libfoo compiled as a static or shared
> > lib). So I don't know how I can correctly define my macro MY_API.
> >
> > Here is, for now, my macro:
> >
> > #if defined(_WIN32) || defined(__CYGWIN__)
> > # ifdef FOO_BUILD  // defined when building 'libfoo'
> > #  ifdef DLL_EXPORT
> > #   warning "BUILD DLL"
> > #   define MY_API __declspec(dllexport)
> > #  else
> > #   warning "BUILD STATIC"
> > #   define MY_API
> > #  endif
> > # else
> > #  warning "IMPORT DLL"
> > #  define MY_API __declspec(dllimport)
> > # endif
> >
> > in the last #else, I don't know what to do to correctly manage MY_API
> > for my problem above
> >
> > One solution would be : never compile 'lbfoo' as a static lib ("DLL
> > are good on Windows"), but I would like to support both static and
> > shared libraries.
> >
> > Does someone know how to solve my issue ? (I hope I've been clear enough...)
> >
> > thank you
> >
> > Vincent Torri
> >
>
> Regards,
> Roumen Petrov
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]