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

fmt shared build lacking symbols #2011

Closed
ghost opened this issue Nov 12, 2020 · 7 comments
Closed

fmt shared build lacking symbols #2011

ghost opened this issue Nov 12, 2020 · 7 comments

Comments

@ghost
Copy link

ghost commented Nov 12, 2020

Hello,

I configured the latest master fmt to build with shared mode. The build processes successfully.
Then I build local_test with #define FMT_HEADER_ONLY no problem.
But the build failed without FMT_HEADER_ONLY, the errors are:

2> locale-test.obj : error LNK2019: unresolved external symbol "struct fmt::v7::detail::dragonbox::decimal_fp __cdecl fmt::v7::detail::dragonbox::to_decimal(float)" (??$to_decimal@M@dragonbox@detail@v7@fmt@@ya?AU?$decimal_fp@M@0123@M@Z) referenced in function "class fmt::v7::detail::buffer_appender<wchar_t> __cdecl fmt::v7::detail::write<wchar_t,class fmt::v7::detail::buffer_appender<wchar_t>,float,0>(class fmt::v7::detail::buffer_appender<wchar_t>,float)" (??$write@_WV?$buffer_appender@_W@detail@v7@fmt@@m$0A@@detail@v7@fmt@@ya?AV?$buffer_appender@_W@012@V3012@M@Z)
2> locale-test.obj : error LNK2019: unresolved external symbol "struct fmt::v7::detail::dragonbox::decimal_fp __cdecl fmt::v7::detail::dragonbox::to_decimal(double)" (??$to_decimal@N@dragonbox@detail@v7@fmt@@ya?AU?$decimal_fp@N@0123@N@Z) referenced in function "class fmt::v7::detail::buffer_appender<wchar_t> __cdecl fmt::v7::detail::write<wchar_t,class fmt::v7::detail::buffer_appender<wchar_t>,double,0>(class fmt::v7::detail::buffer_appender<wchar_t>,double)" (??$write@_WV?$buffer_appender@_W@detail@v7@fmt@@n$0A@@detail@v7@fmt@@ya?AV?$buffer_appender@_W@012@V3012@N@Z)

Edit:
I found that the above symbols are required by other tests also, such as chrono-test, color-test, format-test, etc.
Exception: os-test gives this message:
os-test.obj : error LNK2001: unresolved external symbol "private: virtual void __cdecl fmt::v7::ostream::grow(unsigned __int64)" (?grow@ostream@v7@fmt@@EEAAX_K@Z)
1> D:\vcpkg\buildtrees\fmt\x64-windows\bin\Debug\os-test.exe : fatal error LNK1120: 1 unresolved externals

Please check.
I have intention to write to #1967 but it was closed.

@vitaut
Copy link
Contributor

vitaut commented Nov 12, 2020

Fixed in 6d14f78, thanks for reporting.

@vitaut vitaut closed this as completed Nov 12, 2020
@ghost
Copy link
Author

ghost commented Nov 13, 2020

I have found another issue not about missing symbols but redundant symbols.
If you put the function below into more than one cpp file, the issue should occur.

#include "fmt/format.h"
void test_memory_buffer() {
	fmt::memory_buffer buff;
	buff.push_back('A');
}


1>fmtd.lib(fmtd.dll) : error LNK2005: "protected: __cdecl fmt::v7::detail::buffer<char>::buffer<char>(char *,unsigned __int64,unsigned __int64)" (??0?$buffer@D@detail@v7@fmt@@IEAA@PEAD_K1@Z) already defined in second_src_file.obj
1>fmtd.lib(fmtd.dll) : error LNK2005: "protected: void __cdecl fmt::v7::detail::buffer<char>::set(char *,unsigned __int64)" (?set@?$buffer@D@detail@v7@fmt@@IEAAXPEAD_K@Z) already defined in second_src_file.obj
1>fmtd.lib(fmtd.dll) : error LNK2005: "public: unsigned __int64 __cdecl fmt::v7::detail::buffer<char>::size(void)const " (?size@?$buffer@D@detail@v7@fmt@@QEBA_KXZ) already defined in second_src_file.obj
1>fmtd.lib(fmtd.dll) : error LNK2005: "public: unsigned __int64 __cdecl fmt::v7::detail::buffer<char>::capacity(void)const " (?capacity@?$buffer@D@detail@v7@fmt@@QEBA_KXZ) already defined in second_src_file.obj
1>fmtd.lib(fmtd.dll) : error LNK2005: "public: char * __cdecl fmt::v7::detail::buffer<char>::data(void)" (?data@?$buffer@D@detail@v7@fmt@@QEAAPEADXZ) already defined in second_src_file.obj
1>fmtd.lib(fmtd.dll) : error LNK2005: "public: void __cdecl fmt::v7::detail::buffer<char>::push_back(char const &)" (?push_back@?$buffer@D@detail@v7@fmt@@QEAAXAEBD@Z) already defined in second_src_file.obj

@vitaut
Copy link
Contributor

vitaut commented Nov 13, 2020

buffer ctor is inline so I'm not sure why you get this error. Are you using CMake?

@ghost
Copy link
Author

ghost commented Nov 13, 2020

Yes I am using CMake to generate MSVC project files.
Why do you not make a trivial step as I mentioned previously? Then you have the clue easily.

@ghost
Copy link
Author

ghost commented Nov 14, 2020

I found the cause of redundant symbols. It was introduced in your commit 6d14f78

class FMT_API ostream final : private detail::buffer<char> {
}

Removing FMT_API from the declaration in os.h and "grow()" in os.cpp will solved the issue.
In fact, all functions of class ostream are inline except function "void grow(size_t)" but it is never invoked outside scope of fmt so no need to mark export also.

vitaut added a commit that referenced this issue Nov 14, 2020
@vitaut
Copy link
Contributor

vitaut commented Nov 14, 2020

Thanks for investigating. The issue is tentatively fixed in 5555651.

@haquocviet
Copy link

Thanks for investigating. The issue is tentatively fixed in 5555651.

I have just upgraded fmt-7x to fmt-8.x and found that the "redundant symbols" bug is appeared again.
Please check the issue.

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

2 participants