Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake never creates import libraries for executables #5952

Closed
Kha opened this issue Nov 8, 2019 · 10 comments
Closed

cmake never creates import libraries for executables #5952

Kha opened this issue Nov 8, 2019 · 10 comments

Comments

@Kha
Copy link

Kha commented Nov 8, 2019

Upstream cmake always creates implibs for executables, mingw-w64-cmake never does. According to the docs, it should actually depend on ENABLE_EXPORTS. While this use case is rare, I believe it is the correct way to build plugin libraries that use symbols of an executable they are loaded into.

Currently I'm using

target_link_options(foo PRIVATE "-Wl,--out-implib,$<TARGET_LINKER_FILE:foo>")

as a workaround.

@oscarfv
Copy link
Contributor

oscarfv commented Nov 10, 2019

Usually executables are not used as shared libraries, which IIUC is what you need. Creating an import library for every .exe is wasteful.

On my pluging-based apps, the application is compiled into a dll. Plugins link to that dll. There is a tiny exe that loads and runs the dll.

@Kha
Copy link
Author

Kha commented Nov 10, 2019

Creating an import library for every .exe is wasteful.

Yes, which is supposedly why ENABLE_EXPORTS exists (except for the fact that it is ignored in this regard by both upstream and the mingw patch, of course). The cmake docs literally describe the use case of "loadable modules", i.e. plugins.

@Kha
Copy link
Author

Kha commented Nov 10, 2019

For a cross-platform discussion see also leanprover/lean4#59 (comment).

@oscarfv
Copy link
Contributor

oscarfv commented Nov 10, 2019

If ENABLE_EXPORTS does not create an export library, that's a bug, because the documentation says:

On Windows-based systems (including Cygwin) an “import library” is created along
with the executable to list the exported symbols. Loadable modules link to the import
library to get the symbols.

I just tried ENABLE_EXPORTS on one of my projects and the export library is not created. This is a bug that should be reported upstream.

@oscarfv
Copy link
Contributor

oscarfv commented Nov 10, 2019

@Kha : if you create a bug report upstream please reference it here. Thanks.

@mati865
Copy link
Collaborator

mati865 commented Nov 10, 2019

@oscarfv the issue could be caused by this patch: https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-cmake/0007-Do-not-generate-import-libs-for-exes.patch (it was linked in the first post).

@Kha
Copy link
Author

Kha commented Nov 10, 2019

Yes, it is only mingw cmake that breaks my build! Upstream's behavior should perhaps be changed as well, but at least it is not broken, just wasteful.

@oscarfv
Copy link
Contributor

oscarfv commented Nov 10, 2019

@mati865 : without that patch cmake always generates an import library for an executable. Upstream could argue that ENABLE_EXPORTS "works" in that sense, but that's a very poor implementation. The import library should be created only when requested.

Of course our patch is very relevant because the upstream bug report should not be about ENABLE_EXPORTS not creating the import library, but about the import library being created even when ENABLE_EXPORTS if OFF.

@oscarfv
Copy link
Contributor

oscarfv commented Nov 10, 2019

@Kha : doing something to support a somewhat exotic use case at the expense of being wasteful for the vast majority of projects is not acceptable, IMHO, much less so when there is an easy workaround.

@Kha
Copy link
Author

Kha commented Sep 15, 2021

Fixed in 76446f4

@Kha Kha closed this as completed Sep 15, 2021
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

No branches or pull requests

3 participants