newbie: Determinate CRT lib used by library - c++

I'm developing application using VC++ 6.
I have a 3rd party DLL. This library compiled as Multithreaded DLL (/MD) and my application too.
But I fail to link:
LINK : warning LNK4075: ignoring /EDITANDCONTINUE due to /INCREMENTAL:NO specification
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_strin
g#DU?$char_traits#D#std##V?$allocator#D#2##std##QAE#XZ) already defined in XXXApi.lib(CODbg.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<c
har,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##QAE#ABV01##Z) already defined in XXXApi.lib(Dictionary.obj)
../../Exes/win2k3_oracle11/XXX.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
From here I see that even though both 3rd library and my code compiled as /MD, there's possibly conflict with old/new iostream beining used.
Is there way to determinate what iostream library old/new is used by 3rd party library?
UPD:
The 3rd party lib is static and not dynamic as I thought before.
The lib is compiled /MD. Dependency Walker works wirh DLLs and not which Libs.

There is dependency Walker, if you don't know this tool.
http://dependencywalker.com/
Drag and drop your DLL or exe on the main window. It will show all dependencies.
And if you want to link to a 3rd party DLL, all you need is a .lib made for that DLL.
If you don't have that .lib, you can always make one using lib.exe or polib.exe from pelles c tools.
polib is easier to use because you don't need to write a .def file.
http://www.smorgasbordet.com/pellesc/
I hope it helps for your question.
Edit: Do you have the source code for the .lib you are using?

Related

Crypto++ library link error using Visual Studio 2017

I'm trying to use the Crypto++ librairy in my project (windows application). Using it, include, compilation work fine, but impossible to deal with the link error
Here is some exemple of link errors, there is more, but don't think it's revelant to copy paste all of them
error LNK2019: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl CryptoV2::encrypt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?encrypt#CryptoV2##SA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V23##Z) referenced in function "public: void __thiscall PStore::storeReversibleCrypt(wchar_t *,char *)" (?storeReversibleCrypt#PStore##QAEXPA_WPAD#Z)
error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl CryptoV2::hashPassword(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> >)" (?hashPassword#CryptoV2##SA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V23#0#Z)
fatal error LNK1120: 4 unresolved externals
Basically, I add the "Win32\Output\Release" directory of crypto++ to my linker's additionnal library directories properties, and also the main folder to my C/C++'s General's property "Additional Include Directories"
I've tried a lot of thinks, like adding the library as a new project (same errors), adding all cpp files to my project and compiling with it (not compiling), adding only .cpp files I was using (not realistic, too much), linking all different folder of the cryptopp610 releases (cryptdll, cryptlib, dll_output, Output, same errors), and now, I don't really know what more I can try. I makre also a lots of search, trying all solution I saw (don't remember all of them), still the same problems. I also try to create a new project to add crypto++ without long compilation or mysterious problem, but I also get linker error.
Do anyone got any advice to help me ? Anyway, thank's a lot, and pardon my English
EDIT: Need to add that on the new blank project, I get 63 unresolved external symbol, so I think I forgot to do some basic stuff, but can't figure out which
error LNK2019: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl CryptoV2::encrypt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?encrypt#CryptoV2##SA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V23##Z) referenced in function "public: void __thiscall PStore::storeReversibleCrypt(wchar_t *,char *)" (?storeReversibleCrypt#PStore##QAEXPA_WPAD#Z)
error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl CryptoV2::hashPassword(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> >)" (?hashPassword#CryptoV2##SA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V23#0#Z)
The missing symbols are not from Crypto++. Crypto++ uses the CryptoPP namespace. The missing symbols are from the CryptoV2 namespace or class. I'm guessing that's another crypto library.
You were right in adding directories and a library to the linker settings. However, you need to do it for the CryptoV2 library (in addition to the Crypto++ library).
For completeness, it looks like these are missing:
std::string CryptoV2::encrypt(std::string);
std::string CryptoV2::hashPassword(std::string, std::string);
It could be Ws2_32.lib there is missing from the linker
add #include "dll.h" like stated in the Readme:
To use the Crypto++ DLL in your application, #include "dll.h" before including any other Crypto++ header files, and place the DLL in the same directory as your .exe file. dll.h includes the line #pragma comment(lib, "cryptopp") so you don't have to explicitly list the import library in your project settings.
https://github.com/weidai11/cryptopp/blob/master/Readme.txt#L136

Can't get google test to work

#include "gtest/gtest.h"
TEST(BattleUnitTest, CountryReturnsProperName) {
EXPECT_EQ(1, 1);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
I can't seem to get google test to work. I ran Nuget package manager to get gtest. It keeps giving me these errors:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "bool __cdecl testing::internal::IsTrue(bool)" (?IsTrue#internal#testing##YA_N_N#Z) referenced in function "public: void __thiscall testing::internal::scoped_ptr<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::reset(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?reset#?$scoped_ptr#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###internal#testing##QAEXPAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) Assignment1_Battle E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj 1
.
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: __thiscall testing::Message::Message(void)" (??0Message#testing##QAE#XZ) referenced in function "private: virtual void __thiscall BattleUnitTest_CountryReturnsProperName_Test::TestBody(void)" (?TestBody#BattleUnitTest_CountryReturnsProperName_Test##EAEXXZ) Assignment1_Battle E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj 1
.
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "class testing::AssertionResult __cdecl testing::internal::EqFailure(char const *,char const *,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 &,bool)" (?EqFailure#internal#testing##YA?AVAssertionResult#2#PBD0ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##1_N#Z) referenced in function "class testing::AssertionResult __cdecl testing::internal::CmpHelperEQ<int,int>(char const *,char const *,int const &,int const &)" (??$CmpHelperEQ#HH#internal#testing##YA?AVAssertionResult#1#PBD0ABH1#Z) Assignment1_Battle E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj 1
I could post all the errors but almost all of them have to do with LNK2019. Does anyone know how to fix these errors?
I had this problem but there was nothing wrong with my linker settings. I eventually tracked it down to this post PrintTo link issue:
This was indeed caused by the mismatching /Zc:wchar_t setting. I
failed to mention in the previous post that I had made that example
code as Qt Console Application project (with Qt Add-in 1.1.9).
Apparently the wchar_t setting is set to 'no' with that project
template, while Google Mock's project setting is set to 'yes' by
default. When I recompiled Google Mock with the setting set to 'no'
the linker problem went away.
When I changed my setting "Treat WChar_t As Built in Type" to "Yes /Zc:wchar_t" the build worked.
Looks like you need some additional configuration of your test project:
Add gtest library name to you project properties (Project Properties->Configuration Properties->Linker->Input). Be aware that you probably need to add this thing for both Debug and Release configurations and that library names are different (they are gtest.lib for Release and gtestd.lib for Debug; the difference is "d" at the end of the name before dot).
Add the path to the gtest library to your project properties (Project Properties->Configuration Properties->VC++ Directories->Library Directories). This also needs to be done separately for Debug and Release configurations, because the directories are different as well.
If something else goes wrong, this article might be really useful. It contains the full scenario of setting up gtest for a project in Visual Studio without using Nuget. Just be aware that Nuget basically sets up already compiled version of gtest to "package" sub-directory of your project/solution.

I can't get my own static library to work in my project

I've made a static library project and I added it to the solution that has a project which uses the library.
I included the class I needed from it in the main project like I would with another static library but it throws these errors:
error LNK2019: unresolved external symbol "public: __thiscall NetworkingLib::Base::Base(void)" (??0Base#NetworkingLib##QAE#XZ) referenced in function _SDL_main
error LNK2019: unresolved external symbol "public: void __thiscall NetworkingLib::Base::Connect(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> >)" (?Connect#Base#NetworkingLib##QAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##0#Z) referenced in function _SDL_main
I have no idea what is going wrong. I checked with another project that uses a library in the same way and I can't find any differences. Any help detecting the problem?
The class NetworkingLib::Base has a method I want to use. So what I did in the main project is:
#include "../NetworkLibrary/Base.h"
NetworkingLib::Base *m_pNetworkObj;
m_pNetworkObj = new NetworkingLib::Base();
m_pNetworkObj->Connect("localhost", "80");
I don't think there's anything wrong with this so the problem must be elsewhere.
It's not enough to have the static library in the same solution. You have to pass it to the linker of the project that uses it.
In Visual Studio, the best way to do this is by adding a "Project Reference". This sets up the dependency so that the projects build in the correct order, and also picks the version of the static library matching the consuming project, be that Debug vs Release, x86 vs x64, etc.

unresolved symbols from boost filesystem

I am using boost 1_53 libraries with VS10.
I am getting many unresolved symbols during linking. like the following:
error LNK2019: unresolved external symbol "void __cdecl boost_1_53_0::filesystem::path_traits::convert(char const *,char const *,class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > &,class std::codecvt<unsigned short,char,int> const &)" (?convert#path_traits#filesystem#boost_1_53_0##YAXPEBD0AEAV?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##std##AEBV?$codecvt#GDH#5##Z) referenced in function "void __cdecl boost_1_53_0::filesystem::path_traits::convert(char const *,class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > &,class std::codecvt<unsigned short,char,int> const &)" (?convert#path_traits#filesystem#boost_1_53_0##YAXPEBDAEAV?$basic_string#GU?$char_traits#G#std##V?$allocator#G#2##std##AEBV?$codecvt#GDH#5##Z)
I checked /LIBPATH is set correctly also "boost_1_53_0_filesystem-mt.lib" is coming in link line.
i used dumpbin to find symbol in "lib" its coming like:
00000036 REL32 00000000 515 ?convert#path_traits#filesystem#boost_1_53_0##YAXPEBD0AEAV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##AEBV?$codecvt#_WDH#5##Z (void __cdecl boost_1_53_0::filesystem::path_traits::convert(char const *,char const *,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &))
Is this parameter change causing issue?
EDIT:
I like to add more details:
Previously i was using boost 1_48 which was working fine.
I found that in boost 1_48 symbols under path_traits ends with #GDH#5##Z whicle in boost 1_53 its ending with #_WDH#5##Z
But still It trying to search synbol end with #GDH#5##Z
This can cause error?
If so why its taking that symbols?
Unless you've built every possible permutation of the Boost libraries, it is necessary to make sure that your compiler settings match the settings used to build Boost.
The relevant settings are:
debug vs. release
statically linked runtime vs. DLL
single-threaded vs. multi-threaded
The name boost_1_53_0_filesystem-mt.lib implies that the Boost libraries were built release mode, multi-threaded, DLL runtime.
Is that how you're building your project?
Right click on
->properties
->in general tab
check whether
Common Language Runtime support = "No Common Language Runtime support"
-> in c/C++ -> code generation
check whether
Runtime library Multi-threaded DLL (/MD)
finally in the menu bar go to
-> tools -> options -> project and solutions -> VC++ directories -> library files
check whether you have given the complete path where you boost librarus are usually
"\boost_1_53\stage\lib"
NOTE: the setting paths are mentioned for VS2008
You can check if you are not using 64 bit compiled boost libraries instead of 32 bit ones (and vice versa). It's what happened for me while using boost::filesystem.

Strange linker error in cpp

When I add the following line to my code:
std::string sFrameTag
I get the following linker error:
Error 34 error LNK2005: "public: __thiscall std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string#DU?
$char_traits#D#std##V?$allocator#D#2##std##QAE#XZ) already defined in
VFPAnalyzerApi.lib(VFPEvaluation.obj) msvcprtd.lib
I'm sure sFrameTag is only defined once, I tried using other names for this variable to be sure. I have the following includes: stdio.h, time.h, string.
Can someone please guide it as to what causes this error?
I too get similar kind of errors when I tried to statically include all needed runtime libraries. Do check that when you are trying to import a library which is linked statically with /MD option you also need to use /MD.
Thanks
Niraj Rathi