'how to prepare Prometheus Client Library for Modern C++ for using in Visual Studio 2019

I want to use prometheus-cpp library to get metrics from my application.

I use prometheus-cpp
CMakeLists.txt
CMake v3.21.1.0
Visual Studio 2019.

But I don't understand how to prepare the prometheus-cpp for using in Visual Studio 2019.

When I do CMake instructions from the prometheus-cpp webpage, I get some errors in console output.

For example, when I do the CMake build instructions cmake --install, I get the :

cmake.exe --install .
-- Install configuration: "Release"
CMake Error at core/cmake_install.cmake:56 (file):
  file INSTALL cannot find
  "G:/prometheus-cpp/_build/bin/Release/prometheus-cpp-core.dll":
  No error.
Call Stack (most recent call first):
  cmake_install.cmake:42 (include)

But there is no a Release folder in my
G:/prometheus-cpp/_build/bin/
There is only Debug folder here!

As @vre advised, I called the build command twice from the build directory: cmake --build . --config Release --parallel 4 and cmake --build . --config Debug --parallel 4
Afet that there are both Release and Debug folders appeared.
I called cmake.exe --install . , added the path to c:\Program Files (x86)\prometheus-cpp\include to AdditionalIncludeDirectories in Visual Studio and started the project with this code as Debug x64.
Here is the output:

1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: __cdecl prometheus::Counter::Counter(void)" (__imp_??0Counter@prometheus@@QEAA@XZ) in function "class std::unique_ptr<class prometheus::Counter,struct std::default_delete<class prometheus::Counter> > __cdecl prometheus::detail::make_unique<class prometheus::Counter>(void)" (??$make_unique@VCounter@prometheus@@$$V@detail@prometheus@@YA?AV?$unique_ptr@VCounter@prometheus@@U?$default_delete@VCounter@prometheus@@@std@@@std@@XZ).
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: void __cdecl prometheus::Counter::Increment(void)" (__imp_?Increment@Counter@prometheus@@QEAAXXZ) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) class prometheus::detail::Builder<class prometheus::Counter> __cdecl prometheus::BuildCounter(void)" (__imp_?BuildCounter@prometheus@@YA?AV?$Builder@VCounter@prometheus@@@detail@1@XZ) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: __cdecl prometheus::Exposer::Exposer(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned __int64,struct CivetCallbacks const *)" (__imp_??0Exposer@prometheus@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_KPEBUCivetCallbacks@@@Z) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: __cdecl prometheus::Exposer::~Exposer(void)" (__imp_??1Exposer@prometheus@@QEAA@XZ) в функции main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: void __cdecl prometheus::Exposer::RegisterCollectable(class std::weak_ptr<class prometheus::Collectable> const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?RegisterCollectable@Exposer@prometheus@@QEAAXAEBV?$weak_ptr@VCollectable@prometheus@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: __cdecl prometheus::Registry::Registry(enum prometheus::Registry::InsertBehavior)" (__imp_??0Registry@prometheus@@QEAA@W4InsertBehavior@01@@Z) in function "void __cdecl std::_Construct_in_place<class prometheus::Registry>(class prometheus::Registry &)" (??$_Construct_in_place@VRegistry@prometheus@@$$V@std@@YAXAEAVRegistry@prometheus@@@Z).
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) public: virtual __cdecl prometheus::Registry::~Registry(void)" (__imp_??1Registry@prometheus@@UEAA@XZ) в функции "public: virtual void * __cdecl prometheus::Registry::`scalar deleting destructor'(unsigned int)" (??_GRegistry@prometheus@@UEAAPEAXI@Z).
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "public: class prometheus::detail::Builder<class prometheus::Counter> & __cdecl prometheus::detail::Builder<class prometheus::Counter>::Name(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Name@?$Builder@VCounter@prometheus@@@detail@prometheus@@QEAAAEAV123@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "public: class prometheus::detail::Builder<class prometheus::Counter> & __cdecl prometheus::detail::Builder<class prometheus::Counter>::Help(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Help@?$Builder@VCounter@prometheus@@@detail@prometheus@@QEAAAEAV123@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "public: class prometheus::Family<class prometheus::Counter> & __cdecl prometheus::detail::Builder<class prometheus::Counter>::Register(class prometheus::Registry &)" (?Register@?$Builder@VCounter@prometheus@@@detail@prometheus@@QEAAAEAV?$Family@VCounter@prometheus@@@3@AEAVRegistry@3@@Z) in function main.
1>prometheus_test.obj : error LNK2019: reference to unresolved external symbol "__declspec(dllimport) private: class prometheus::Counter & __cdecl prometheus::Family<class prometheus::Counter>::Add(class std::map<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> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > const &,class std::unique_ptr<class prometheus::Counter,struct std::default_delete<class prometheus::Counter> >)" (__imp_?Add@?$Family@VCounter@prometheus@@@prometheus@@AEAAAEAVCounter@2@AEBV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@V?$unique_ptr@VCounter@prometheus@@U?$default_delete@VCounter@prometheus@@@std@@@5@@Z) in function "public: class prometheus::Counter & __cdecl prometheus::Family<class prometheus::Counter>::Add<>(class std::map<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> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > const &)" (??$Add@$$V@?$Family@VCounter@prometheus@@@prometheus@@QEAAAEAVCounter@1@AEBV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@@Z).
1>prometheus_test.obj : error LNK2001: unresolved external symbol "public: virtual class std::vector<struct prometheus::MetricFamily,class std::allocator<struct prometheus::MetricFamily> > __cdecl prometheus::Registry::Collect(void)const " (?Collect@Registry@prometheus@@UEBA?AV?$vector@UMetricFamily@prometheus@@V?$allocator@UMetricFamily@prometheus@@@std@@@std@@XZ).
1>G:\_Job\_Education\Cpp\Prometheus\prometheus_test\x64\Debug\prometheus_test.exe : fatal error LNK1120: unresolved external symbols: 13

Could you explaine me please, how to prepare the prometheus-cpp correctly by CMake to use in Visual Studio 2019??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source