This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Transforming a static library to a DLL


Angelo Graziosi wrote:

> Trying to transform in DLL, for example the library 'libmathlib.a', I
> have tried this:

I don't really think you should try to "convert" a library like this. 
You really need to recompile each object, as normally there are
different preprocessor defines in effect for creating a static library
vs. a DLL, which affects function declarations.  And on other non-PE
platforms you would most certainly have to recompile so that you can
generate position independent code, but on PE at the moment there is no
distinction between PIC and non-PIC.
  
[ This could potentially change at some point in the future; there was a
gcc patch submitted but not championed to add PLT-like true-PIC behavior
on PE, instead of using text relocations.  I don't think it's going
anywhere, and it might have problems interoperating with native
toolchains, but there's a chance somebody might clean it up and champion
it. ]

No matter how you go about it though, when creating a DLL you have to
arrange for the function and data exports to be specified, using the
standard methods, i.e. one of:

- explicitly declare with __declspec(dllexport)
- use a .def file
- --export-all-symbols

If no object file has any __declspec(dllexport) anywhere then you get
--export-all-symbols by default, otherwise you have to specify it.  In
your case that might be enough to do what you want, but you'll have to
dig in a little further and see where these missing symbols need to come
from.

>    gcc -shared -o cygmathlib.dll \
>        -Wl,--enable-auto-image-base \
>        -Wl,--out-implib=libmathlib.dll.a \
>        -Wl,--enable-auto-import
>        -Wl,--whole-archive libmathlib.a \
>        -Wl,--no-whole-archive -lg2c
> 
> but it fails with a lot of :
> -------------------------------------
> libmathlib.a(arithm.o):cccrN4fn.f:(.text+0x17): undefined reference to
> `_funct_'
> libmathlib.a(arithm.o):cccrN4fn.f:(.text+0x154): undefined reference to
> `_funct_'
> libmathlib.a(d501l1.o):cc44FCLd.f:(.text+0x2dd): undefined reference to
> `_dvset_'
> ...
> -------------------------------------
> 
> Perhaps I have forgot to add some other library on command line.

I don't know.  You'll have to use nm/ar to look around and see where
these missing symbols are defined.  It could be a missing library, it
could be a link order problem, or it could be that some preprocessor
symbol was in the wrong state (i.e. defined when it shouldn't be or
missing when it was required, ala -DFOO_STATIC or -DBUILDING_FOO or
-DFOO_DLL etc.) when the objects were compiled which caused __declspec
declarations to be wrong.  It all depends on the design of the library.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]