Hi guys,
So I've cloned the repo, I've installed cmake and vs2010 sp1 and compiled the library.
apart from some signed/unsigned problems, everything appears to be ok
then I did the following:
then I tried to compile and it complains about multiple defined symbols :/
fmt.lib(format.obj) : error LNK2005: "unsigned int __cdecl fmt::internal::clz(unsigned int)" (?clz@internal@fmt@@YAII@Z) already defined in user.obj
I'm not exactly sure what I'm doing wrong, is there a right way and wrong way to use this library on windows?
Alternatively, I did the following, with the exact same problem as above
I added both format.c and format.h to my project by copying the files into the source directory, once I got around the problem with the includes wanting "fmt/format.h" by adding an include path, I got it to compile again.
However, the problem specified above persists, so for some reason, I cannot use the .lib as I expected and neither can I just include the files like it also suggested in the documentation.
So I'm unsure what to do here
I found after googling a lot that the problem seemed to be with certain functions that are defined as inline and it was suggested on stackoverflow that I try to use static also.
I tried to apply static to each of the problem functions and it did in fact stop the compiler from complaining.
However, just trying to do random things doesn't really sound like a good idea, I just knew it shut up the compiler, but I'm not a genius with compilers, so I don't know the effects of adding static to these functions will be, I just know it stopped the compiler complaining.
Could you post the full compiler and linker output?
fmt::internal::clz is inline so it's not clear what is causing the linkage error. What version of the fmt library do you use?
Hey, sorry for the delay, here is the compiler output, I'm using the latest git repository, I installed cmake, built the solution files, compiled the release build and then I'm including it in my project.
`------ Build started: Project: php_mt4_ext, Configuration: Release Win32 ------
fmt.lib(format.obj) : error LNK2005: "void __cdecl fmt::internal::require_numeric_argument(struct fmt::internal::Arg const &,char)" (?require_numeric_argument@internal@fmt@@YAXABUArg@12@D@Z) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "class std::basic_string
fmt.lib(format.obj) : error LNK2005: "unsigned __int64 __cdecl fmt::internal::make_type(struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType,struct fmt::internal::ArgType)" (?make_type@internal@fmt@@YA_KUArgType@12@00000000000000@Z) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "unsigned int __cdecl fmt::internal::count_digits(unsigned int)" (?count_digits@internal@fmt@@YAII@Z) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "unsigned int __cdecl fmt::internal::count_digits(unsigned __int64)" (?count_digits@internal@fmt@@YAI_K@Z) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "struct fmt::internal::DummyInt __cdecl fmt::internal::isnan(...)" (?isnan@internal@fmt@@YA?AUDummyInt@12@ZZ) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "struct fmt::internal::DummyInt __cdecl fmt::internal::isinf(...)" (?isinf@internal@fmt@@YA?AUDummyInt@12@ZZ) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "struct fmt::internal::DummyInt __cdecl fmt::internal::signbit(...)" (?signbit@internal@fmt@@YA?AUDummyInt@12@ZZ) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "unsigned int __cdecl fmt::internal::clzll(unsigned __int64)" (?clzll@internal@fmt@@YAI_K@Z) already defined in Manager.obj
fmt.lib(format.obj) : error LNK2005: "unsigned int __cdecl fmt::internal::clz(unsigned int)" (?clz@internal@fmt@@YAII@Z) already defined in Manager.obj
Creating library C:\projects\php_mt4_ext\Release\php_mt4_ext.lib and object C:\projects\php_mt4_ext\Release\php_mt4_ext.exp
C:\projects\php_mt4_ext\Release\php_mt4_ext.dll : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========`
This is just a guess, but I'd check that inline is not redefined by some rogue header by adding the following code before clz in format.h:
#ifdef inline
# error inline is redefined
#endif
it's code in a php extension, which doesnt give me much hope, I'll try it, thanks
Here's an example of a working VC2010 project using fmt: test.zip
@christhomas Does the example work for you?
I was not able to reproduce this issue so I'm closing it. However, feel free to reopen and provide a reproducible example.
Hi Vitaut, sorry for not reponding earlier and thanks for the demo solution, I've got a lot of things to do with releasing a product, so I'm going to come back to this when I've got more time, but yes, consider it closed since I'm assuming what you've got it working, so must have been something I did, I'll analyse it in more detail
Hi All,
I've stumbled across this page as I came across a linkage error using fmt as a NuGet Package in a native C++ project. I managed to resolve it so I thought I would include it here in case anyone else follows the same path as me. The error was resolved by ensuring that fmt had static linkage from Project Properties -> Configuration Properties -> Referenced Packages -> fmt.
After that the build worked fine.

Most helpful comment
Hi All,
I've stumbled across this page as I came across a linkage error using fmt as a NuGet Package in a native C++ project. I managed to resolve it so I thought I would include it here in case anyone else follows the same path as me. The error was resolved by ensuring that fmt had static linkage from Project Properties -> Configuration Properties -> Referenced Packages -> fmt.
After that the build worked fine.