[FFmpeg-devel] Fix libssh static linkage on Windows

Reimar Döffinger Reimar.Doeffinger at gmx.de
Wed Feb 5 19:53:54 CET 2014


On Thu, Feb 06, 2014 at 01:21:34AM +1100, Matt Oliver wrote:
> On windows there are 2 ways to link to a function found in an external
> shared library (.dll on windows). The first is to generate an export
> library with your shared dll. This export library looks just like a static
> lib but all the functions found in it point out to the external dll. The
> second method is to declare each function as dllimport. This bypasses
> needing to link to the export lib by explicitly stating its from a dll in
> the code.
> 
> dllimport is placed in front of any function or data declarations in code
> to specify that they are found in an external .dll (.so shared library on
> linux). If a function is declared as dllimport then the linker will only
> look for that function in an external dll even if that function has been
> provided with a static library. So linking will always fail if using a
> static library to provide a function as the linker will only allow for an
> external shared function.

Are you sure about that? Because that is not my experience.
As long as you use dllexport for the corresponding functions while
compiling the static lib I believe it should work just fine.
Note that you like this risk that libavformat ends up exporting
the libssh functions, so it's not exactly such a great idea,
but the underlying issue should be using dllimport where you use
the function but not using dllexport where you defined it.
Also, to quote Microsoft:
> dllexport of a function exposes the function with its decorated name. For C++ functions, this includes name mangling. For C functions or functions that are declared as extern "C", this includes platform-specific decoration that's based on the calling convention. If you don't want name decoration, use a .def file (EXPORTS keyword).

So it's basically a name mangling issue (for C I believe it's just
that a _ is prepended).
It also hints that just using a .def file and none of this dllimport/dllexport
stuff would avoid the issue as well.


More information about the ffmpeg-devel mailing list