[CMake] Win32: exporting symbols for DLLs - simpler method ?

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sat Nov 24 05:44:42 EST 2007


Eric Noulard schrieb:
> 2007/11/23, Christian Ehrlicher <Ch.Ehrlicher at gmx.de>:
>> Eric Noulard schrieb:
>>> 2) is possible if you use .def file instead of __declspec(dllexport/dllimport)
>>>     see e.g.
>>>     http://www.codeproject.com/dll/SimpleDllP3.asp
>>>
>> This is the old way to export functions and imho very error-prone (you
>> have to change your function name on two places for proper export).
> 
> Yes that's right.
> 
>> Also this does not work for linux.
> 
> I'm no shared lib specialist but as far as I know when
> you build a shared lib on linux the default behavior
> is to export all symbols?
> 
> As far as understood from
> " How to Write Shared Libraries"
> http://people.redhat.com/drepper/dsohowto.pdf
> 
Since gcc 4.x has support for __attribute__ ((visibility()). The effect
of this atribute is nearly the same like dllexport on windows - hiding
private symbols to speedup shared lib loading. kde4 is using this (maybe
more an effect because we need it on windows than really using it to
speedup shared lib loading, don't know ;) )
>> You'll need a single #define FOO_EXPORT for every lib you create.
> 
> Yes I agree with that if you do not use .def.
> 
>>> I'm interested in your problem too because I personnally
>>> would like to throw away those LIB_EXPORTS prefix from the source.
>> I don't understand this.
> 
> I wanted to say that I don't like to have all those
> WHATEVER_EXPORTS in my header files.
> I think it makes the header less readable.
The only thing you need is a FOO_EXPORT before every class / function.
When you move out the import/export stuff into an own header (like it's
done in kde4) it's not that unreadable :)


Christian





More information about the CMake mailing list