Skip to content

build: respect autotools DLL_EXPORT in libssh2.h - #917

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:libssh2-h-respect-DLL_EXPORT
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:libssh2-h-respect-DLL_EXPORT

Conversation

@vszakats

@vszakats vszakats commented Apr 1, 2023

Copy link
Copy Markdown
Member

The DLL_EXPORT macro is automatically set by autotools when building the libssh2 DLL. Certain toolchains might require this to correctly export symbols, so make sure to respect it in libssh2.h to enable declspec(dllexport).

With this patch we have a manual macro for that (LIBSSH2_EXPORT), this autotools one, the CMake one, and _WINDLL (added in c355d31), possibly defined by Visual Studio.

The `DLL_EXPORT` macro is automatically set by autotools when building
the libssh2 DLL. Certain toolchains might require this to correctly
export symbols, so make sure to respect it in `libssh2.h` to enable
`declspec(dllexport)`.

With this patch we have a manual macro for that (`LIBSSH2_EXPORT`),
this autotools one, the CMake one, and `_WINDLL` (added in
c355d31), possibly defined by Visual
Studio.
@vszakats vszakats closed this in fb1195c Apr 2, 2023
@vszakats
vszakats deleted the libssh2-h-respect-DLL_EXPORT branch April 2, 2023 03:26
vszakats added a commit to curl/curl-for-win that referenced this pull request Jul 29, 2023
This libssh2 commit caused that when a dependent (like curl) is built in
shared mode, libssh2 is also setup for shared mode linking (on Windows):
  libssh2/libssh2#917
  libssh2/libssh2@fb1195c

We want to link libssh2 statically to a shared libcurl, so force linking
statically with `-DLIBSSH2_API=`.

Another option is to revert the libssh2 change, though that doesn't seem
correct in different ways. Or, to add support for `LIBSSH2_STATICLIB` in
libssh2 to make the solution more obvious.
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jul 29, 2023
Reverts fb1195c libssh2#917

On a second look this change did not improve anything with autotools
builds. autotools seems to handle the dll export matter without it.

On the other hand, this patch broke (e.g.) curl-for-win autotools
builds, where the curl build defines `DLL_EXPORT` while building
libcurl DLL. `libssh2.h` picks it up, resulting in unresolved symbols
while trying to link a static libssh2. The best fix seems to be to
revert this, instead of adding extra tweaks to dependents.

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
d.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```

Closes #xxxx
vszakats added a commit to curl/curl-for-win that referenced this pull request Jul 29, 2023
…n [ci skip]

This libssh2 commit caused that when a dependent (like curl) is built in
shared mode with autotools on Windows, libssh2 is also setup for shared
mode linking:
  libssh2/libssh2#917
  libssh2/libssh2@fb1195c

We want to link libssh2 statically to a shared libcurl, so force linking
statically with `-DLIBSSH2_API=` as a workaround (which is equivalent to
setting `-DLIBNAME_STATICLIB` as seen with other libs).

Because the libssh2 commit turned out to be not useful anyway, I opted
to revert it to avoid fallouts like this. PR:
  libssh2/libssh2#1141

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```
vszakats added a commit that referenced this pull request Jul 29, 2023
Revert fb1195c #917

On a second look this change did not improve anything with autotools
builds. autotools seems to handle the dll export matter without it.

This patch also broke (e.g.) curl-for-win autotools builds, where the
curl build defines `DLL_EXPORT` while building libcurl DLL. `libssh2.h`
picks it up, resulting in unresolved symbols while trying to link a
static libssh2 on Windows. The best fix seems to be to revert this,
instead of adding extra tweaks to dependents.

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```

Closes #1141
lampmanyao pushed a commit to lampmanyao/libssh2 that referenced this pull request Sep 3, 2023
Revert fb1195c libssh2#917

On a second look this change did not improve anything with autotools
builds. autotools seems to handle the dll export matter without it.

This patch also broke (e.g.) curl-for-win autotools builds, where the
curl build defines `DLL_EXPORT` while building libcurl DLL. `libssh2.h`
picks it up, resulting in unresolved symbols while trying to link a
static libssh2 on Windows. The best fix seems to be to revert this,
instead of adding extra tweaks to dependents.

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```

Closes libssh2#1141
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
The `DLL_EXPORT` macro is automatically set by autotools when building
the libssh2 DLL. Certain toolchains might require this to correctly
export symbols, so make sure to respect it in `libssh2.h` to enable
`declspec(dllexport)`.

With this patch we have a manual macro for that (`LIBSSH2_EXPORT`),
this autotools one, the CMake one, and `_WINDLL` (added in
c355d31), possibly defined by Visual
Studio.

Closes libssh2#917
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Revert fb1195c libssh2#917

On a second look this change did not improve anything with autotools
builds. autotools seems to handle the dll export matter without it.

This patch also broke (e.g.) curl-for-win autotools builds, where the
curl build defines `DLL_EXPORT` while building libcurl DLL. `libssh2.h`
picks it up, resulting in unresolved symbols while trying to link a
static libssh2 on Windows. The best fix seems to be to revert this,
instead of adding extra tweaks to dependents.

Fixes:
https://ci.appveyor.com/project/curlorg/curl-for-win/builds/47667412#L11035
```
ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_block_directions
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_do)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_multi_statemach)
>>> referenced 8 more times

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_init_ex
>>> referenced by vssh/.libs/libcurl_la-libssh2.o:(ssh_connect)

ld.lld-15: error: undefined symbol: __declspec(dllimport) libssh2_session_set_read_timeout
[...]
```

Closes libssh2#1141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant