Error building c++ project with ppconsul(Consul client for c++) - c++

I'm a beginner to cpp and trying to use a cpp library called ppconsul(https://github.com/oliora/ppconsul ). This library has dependency to some of other libraries like (boost and curl). I have build ppconsul with all its dependencies and trying to use ppconsul executable in a new project. When I try to build the new project, I'm getting some linker issue like below.
error LNK2001: unresolved external symbol "public: virtual char const * thiscall ppconsul::BadStatus::what(void)const " (?what#BadStatus#ppconsul##UBEPBDXZ)
1>ConsulApp.obj : error LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ppconsul::helpers::encodeUrl(class std::basic_string,class std::allocator > const &)" (?encodeUrl#helpers#ppconsul##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV34##Z) referenced in function "void __cdecl ppconsul::parameters::detail::printParameter(class std::basic_ostream > &,class std::basic_string,class std::allocator > const &,struct ppconsul::kw::dc_keyword)" (??$printParameter#Udc_keyword__#kw#ppconsul###detail#parameters#ppconsul##YAXAAV?$basic_ostream#DU?$char_traits#D#std###std##ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##4#Udc_keyword__#kw#2##Z)
I tried to link the project and change the visual studio but nothing worked. Anybody has any idea about this linker issue?
TIA,
Prassi

Issue resolved- Refer this thread github.com/oliora/ppconsul/issues/24
build ppconsul as a static library by passing -DBUILD_STATIC_LIB=ON to CMake.

Related

Unresolved external symbol globalThreadCount when trying to compile a project including openexr

I've cloned the pbrt-v3 repository using Visual Studio 2017. I've tried to compile a project where I included the Transform.h, but I'm getting the following error from the linker:
LNK2019 unresolved external symbol "int __cdecl Imf::globalThreadCount(void)" (?globalThreadCount#Imf##YAHXZ) referenced in function "class pbrt::RGBSpectrum * __cdecl pbrt::ReadImageEXR(class std::basic_string,class std::allocator > const &,int *,int *,class pbrt::Bounds2 *,class pbrt::Bounds2 *)" (?ReadImageEXR#pbrt##YAPEAVRGBSpectrum#1#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##PEAH1PEAV?$Bounds2#H#1#2#Z)
I've compiled and installed openexr using CMake for Visual Studio. I've added
libpbrt.lib
libglog_static.lib
IlmThread-2_2.lib
Half.lib
Iex-2_2.lib
IexMath-2_2.lib
Imath-2_2.lib
as additional dependencies in the project settings. I wasn't able to figure out in which library globalThreadCount is defined. So, which library am I missing?

Boost-log linker error

i've downloaded and builded Boost 1.55 from source. I'm trying to use Boost-log. In basic case (http://boost-log.sourceforge.net/libs/log/doc/html)/log/tutorial.html#log.tutorial.trivial it's working fine without any problems, but when i try to use some more advanced features(like this - http://boost-log.sourceforge.net/libs/log/example/doc/tutorial_fmt_stream.cpp ) i'm getting this error:
main.obj : error LNK2019: unresolved external symbol "void __cdecl
boost::filesystem::path_traits::convert(char const *,char const
*,class std::basic_string,class std::allocator>
&,class std::codecvt const &)" (?convert#path_traits#filesystem#boost##YAXPBD0AAV?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##std##ABV?$codecvt#GDH#5##Z)
referenced in function "void __cdecl
boost::filesystem::path_traits::dispatch,class std::allocator > >(class
std::basic_string,class
std::allocator > const &,class std::basic_string,class
std::allocator > &,class std::codecvt const &)"
(??$dispatch#V?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##std###path_traits#filesystem#boost##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAV?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##4#ABV?$codecvt#GDH#4##Z)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl
boost::log::v2s_mt_nt5::aux::code_convert(unsigned short const
*,unsigned int,class std::basic_string,class std::allocator > &,class
std::locale const &)"
(?code_convert#aux#v2s_mt_nt5#log#boost##YAXPBGIAAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABVlocale#6##Z)
referenced in function "private: void __thiscall
boost::log::v2s_mt_nt5::basic_formatting_ostream,class std::allocator>
::aligned_write(unsigned short const *,__int64)" (??$aligned_write#G#?$basic_formatting_ostream#DU?$char_traits#D#std##V?$allocator#D#2##v2s_mt_nt5#log#boost##AAEXPBG_J#Z)
1>main.obj : error LNK2019: unresolved external symbol "public: static
class std::codecvt const & __cdecl
boost::filesystem::path::codecvt(void)"
(?codecvt#path#filesystem#boost##SAABV?$codecvt#GDH#std##XZ)
referenced in function "public: __thiscall
boost::filesystem::path::path(char const (&)[14],void
*)" (??$?0$$BY0O#$$CBD#path#filesystem#boost##QAE#AAY0O#$$CBDPAX#Z)
So basically it can't find functions convert(...), code_convert(...) and codecvt(...) in .lib files.
I've already tried to add all release libraries (.lib files made while building boost) to "additional libraries" and generally i think that visual studio find all libraries, but can't find those functions in libraries. Any ideas how can i fix this?
I've build Boost 1.55 from source using visual studio 2010 (msvc10.0), 32 bit, release and debug. I'm working on windows 7 x64.
I had the same problem and I could fix it by changing one of the Project properties on VisualStudio 2010.
Go to:
Property Pages -> ConfigurationProperties -> C/C++ -> Language -> Treat WChar_t As Built in Type:
And set the property to:
Yes (/Zc:wchar_t)
I hope it will be helpful for you too :)
Take care,

including a .lib file compiled in vs2010 in a project that is using vs2005

Is there any way I can have the main functions for a library built in vs 2010 be accessible from a vs2005 project? The problem that I face is that I have a project in vs 2005 that needs to use the clang frontend library to parse c code. The clang library requires vs 2010 to compile.
Any light you could shed on my problem is appreciated.
Thanks,
Saketh
EDIT:
I receive the following linker errors on compilation
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(_int64)" (_imp_?width#ios_base#std##QAE_J_J#Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::basic_streambuf >::sputn(char const *,_int64)" (_imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAE_JPBD_J#Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(void)const " (_imp?width#ios_base#std##QBE_JXZ) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>C:\Users\sakethk\Perforce\sakethk_SAKETHK_7702\source\qcom\qct\modem\uim\tools\sakethk\hello05\Debug\hello05.exe : fatal error LNK1120: 3 unresolved externals
No. Within a single module, you cannot mix objects compiled against different major versions of the CRT. This generally procludes mixing of objects compiled using different major versions of the compiler.
The correct thing to do would be to encapsulate your usage of Visual C++ 2010 within a DLL, and load that DLL from your executable compiled with Visual C++ 2005. Alternatively, upgrade your sources to use Visual C++ 2010. Visual C++ 2005 is ancient.
Your library functions should be at the lowest level here i mean that you should use C-style parameters to functions and use extern "C" to avoind compilers mangling. Here you will find good article on how to create a great library compatible with every compiler. http://chadaustin.me/cppinterface.html

Mixing native C++ and C++/CLI

I have a solution which consists of a native C++ DLL and a C++/CLI wrapper. My aim is to create a wrapper in C++/CLI of the native C++ DLL.
Whenever I try to create an instance of a native C++ class within the wrapper, I am met with many linker errors (see below).
2> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
2>NFileOperation.obj : error LNK2028: unresolved token (0A000208) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "[T2M] void __clrcall `dynamic initializer for 'public: static float * tagVARIANT::* ATL::CVarTypeInfo<float *>::pmField''(void)" (__t2m#???__E?pmField#?$CVarTypeInfo#PAM#ATL##2QQtagVARIANT##PAMQ3###YMXXZ#?A0x22b777aa##YMXXZ)
2>DeskUpdateManaged.obj : error LNK2028: unresolved token (0A00021C) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>DeskUpdateManaged.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>NFileOperation.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z)
2>C:\Users\ABGZAMANK\Music\DeskUpdate\Dev\Source\Solution\Debug\DeskUpdateManaged.dll : fatal error LNK1120: 3 unresolved externals
Function call within the C++/CLI to the native C++ DLL:
bool NFileOperation::FileExists(CAtlString sPathName)
{
return CFileOperation::FileExists(sPathName);
}
Is there a more adequate approach to what I am trying to achieve?
Any advice relating to the issue is much appreciated.
It seems that your native C++ code is using ATL/MFC. Assuming you are compiling under VS, go to the C++/CLI project's project properties->Configuration properties->General and select "Use of MFC" and "Use of ATL" to be either static library or shared dll (depending on your project type). This flag will add the necessary include paths, linking paths and libs to your project to make use of ATL/MFC types from within your project. Also, make sure that you are linking your C++/CLI project against your native C++ project to avoid linking errors from your project (easily found in the Linker segment of the project properties in General and Input).

Linking error while using Visual Studio 2005(VC8)

I am getting a bunch of linking errors while trying to link the release version of an executable(debug version does not have the same issue). Comparing the command line for the link does not reveal any issues.
there are broadly 2 types of errors neither of which I can get a handle on.
The first kind complains about a unresolved external symbol _declspec(dllimport)
As an example:
error LNK2019: unresolved external symbol
"_declspec(dllimport)
public: __thiscall
stlpd_std::basic_string,class stlpd_std::allocator >::basic_string,class stlpd_std::allocator >(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z)
for a more human readable version(replacing all the strings):
error LNK2019: unresolved external symbol
"__declspec(dllimport)
public: __thiscall
string::basic_string,class stlpd_std::allocator >(class string const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class string const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z
The sceond class of errors complains about
unresolved external symbol __CrtDbgReportW
I hope I can get some kind of insight in dealing with this.
From the errors it looks like you are not including the CRT as one of your linked libraries. Here is a link to the different CRT lib's offered in Visual Studio 2005. Choose the one which is most appropriate and make sure it's in the list of lib's to link against
http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx
It looks like you're either including a file that's been built using the debug settings or you're mixing runtime libraries (DLL and static).