Skip to content

Fix warning C4251: class fmt::v8::file needs to have dll-interface - #2797

Merged
vitaut merged 2 commits into
fmtlib:masterfrom
dalboris:fix-warning-c4251
Mar 7, 2022
Merged

vitaut merged 2 commits into
fmtlib:masterfrom
dalboris:fix-warning-c4251

Conversation

@dalboris

@dalboris dalboris commented Mar 5, 2022

Copy link
Copy Markdown
Contributor

These changes fix #2796 by exporting the whole class fmt::v8::file instead of exporting all its individual member functions.

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

@vitaut

vitaut commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

There are some link errors: https://github.com/fmtlib/fmt/runs/5442603541

@dalboris

dalboris commented Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

@vitaut Looking into it

@dalboris

dalboris commented Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

The problem was that fmt was missing in this line in test/CMakeLists :

target_link_libraries(test-main gtest fmt)

Without the fmt dependency, the test-main target didn't inherit the FMT_SHARED compile definition defined L272 of fmt/CMakeLists:

target_compile_definitions(fmt PRIVATE FMT_EXPORT INTERFACE FMT_SHARED)

Therefore, when compiling test-main, the macro FMT_API resolved to nothing, so test-main didn't know it had to import existing symbols (such as fmt::file::file() and others) and instead re-defined these symbols.

Later, when compiling a test (for exemple, os-test.cc), the test does depend on fmt, so it inherits FMT_SHARED, so FMT_API resolves to __declspec(dllimport), so it correctly imports the symbols from the fmt shared lib, which conflicts with the redefined symbols in test-main.

@dalboris

dalboris commented Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

Shout out to @PixelRick who found the problem after a lot of head scratching together.

@vitaut
vitaut merged commit e3d688e into fmtlib:master Mar 7, 2022
@vitaut

vitaut commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

Thank you

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.

Warning C4251: class 'fmt::v8::file' needs to have dll-interface

2 participants