how to pass fmt library for linking to cl.exe on windows 10

95 views Asked by At

I have this small piece of code in hello.cpp

#include "fmt/core.h"

int main()
{
    fmt::println("Hello from fnt!");
}

I am trying to compile this and I know that I am supposed to pass an additional linker option as it is not compiling.

cl /EHsc /I C:\dev\vcpkg\packages\fmt_x64-windows\include hello.cpp

and the output is

Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33126.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.cpp
Microsoft (R) Incremental Linker Version 14.38.33126.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:hello.exe
hello.obj
hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fmt::v10::detail::vprint_mojibake(struct _iobuf *,class fmt::v10::basic_string_view<char>,class fmt::v10::basic_format_args<class fmt::v10::basic_format_context<class fmt::v10::appender,char> >)" (__imp_?vprint_mojibake@detail@v10@fmt@@YAXPAU_iobuf@@V?$basic_string_view@D@23@V?$basic_format_args@V?$basic_format_context@Vappender@v10@fmt@@D@v10@fmt@@@23@@Z) referenced in function "void __cdecl fmt::v10::print<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(struct _iobuf *,class fmt::v10::basic_format_string<char,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &&)" (??$print@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@v10@fmt@@YAXPAU_iobuf@@V?$basic_format_string@DV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@01@$$QAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl fmt::v10::vformat(class fmt::v10::basic_string_view<char>,class fmt::v10::basic_format_args<class fmt::v10::basic_format_context<class fmt::v10::appender,char> >)" (__imp_?vformat@v10@fmt@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_string_view@D@12@V?$basic_format_args@V?$basic_format_context@Vappender@v10@fmt@@D@v10@fmt@@@12@@Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl fmt::v10::format<>(class fmt::v10::basic_format_string<char>)" (??$format@$$V@v10@fmt@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_format_string@D$$V@01@@Z)
hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl fmt::v10::vprint(struct _iobuf *,class fmt::v10::basic_string_view<char>,class fmt::v10::basic_format_args<class fmt::v10::basic_format_context<class fmt::v10::appender,char> >)" (__imp_?vprint@v10@fmt@@YAXPAU_iobuf@@V?$basic_string_view@D@12@V?$basic_format_args@V?$basic_format_context@Vappender@v10@fmt@@D@v10@fmt@@@12@@Z) referenced in function "void __cdecl fmt::v10::print<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(struct _iobuf *,class fmt::v10::basic_format_string<char,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &&)" (??$print@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@v10@fmt@@YAXPAU_iobuf@@V?$basic_format_string@DV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@01@$$QAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
hello.exe : fatal error LNK1120: 3 unresolved externals

I installed fmt library using vcpkg and also performed the integrated installation.

1

There are 1 answers

0
Morpheus On BEST ANSWER

This heled me

cl /EHsc /I C:\dev\vcpkg\packages\fmt_x64-windows\include /DFMT_HEADER_ONLY hello.cpp