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
Related
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
#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'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.
Today I added a class which manages the connection to a MySQL Server. It will be multi-threaded, so I want to use mysql++. I downloaded the newest version and compiled it in debug mode without any errors. Once I added the compiled mysqlpp_d.lib to my solutions, and of course the other requirements too (mysql 5.0 include and lib), I got some linker errors.
Error 17 error LNK1169: one or more multiply defined symbols found C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxxx\binaries\xxxx.exe 1 1 xxxxx
Error 16 error LNK2005: "public: __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >(int)" (??0?$basic_ostringstream#DU?$char_traits#D#std##V?$allocator#D#2##std##QAE#H#Z) already defined in xxxxxx.obj C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxxx\trunk\vc10\xxxxx\mysqlpp_d.lib(mysqlpp_d.dll) xxxxxxx
Error 15 error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::str(void)const " (?str#?$basic_ostringstream#DU?$char_traits#D#std##V?$allocator#D#2##std##QBE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##2#XZ) already defined in client_context.obj C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxx\trunk\vc10\xxx\mysqlpp_d.lib(mysqlpp_d.dll) xxxxx
Error 14 error LNK2005: "public: void __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::`vbase destructor'(void)" (??_D?$basic_ostringstream#DU?$char_traits#D#std##V?$allocator#D#2##std##QAEXXZ) already defined in xxxxx.obj C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxx\trunk\vc10\xxxx\mysqlpp_d.lib(mysqlpp_d.dll) xxx
Is there a solution for these errors?
BTW: I compiled the whole mysql++ libary without changing any compile configurations.
Define MYSQLPP_NO_DLL in Project Properties->C/C++/Preprocessor
Try setting /NODEFAULTLIB parameter in project options -> Linker/Input
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?