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
Related
I have a visual studio solution that contains two projects. They are both saved in a separate folder. The main project (in my case EquitCalculatorMontecarlo) contains a main function that can work by itself. The second project contains boost Tests that are supposed to test the main project.
My issue is that when I try to run the tests with the test explorer I get an error message from the linker:
Error LNK2019 unresolved external symbol "bool __cdecl eval_best_hand(class std::vector<class std::set<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<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >,class std::allocator<class std::set<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<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > > const &)" (?eval_best_hand##YA_NAEBV?$vector#V?$set#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##U?$less#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2#V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##V?$allocator#V?$set#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##U?$less#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2#V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std###2##std###Z) referenced in function "public: void __cdecl card_evaluation1::test_method(void)" (?test_method#card_evaluation1##QEAAXXZ) Tests C:\Users\dickr\git\EquityCalculatorMontecarlo\Tests\Test.obj 1
I followed the instructions here: https://learn.microsoft.com/en-us/visualstudio/test/how-to-use-boost-test-for-cpp?view=vs-2019
The full code is visible here:
https://github.com/dickreuter/PokerEquityCalculator
but here a quick summary:
/Tests/Test.cpp
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE HandEvaluationTests
#include <boost/test/included/unit_test.hpp>
#include "../EquityCalculatorMontecarlo/Deck.h"
#include "../EquityCalculatorMontecarlo/Scoring.h"
BOOST_AUTO_TEST_CASE(card_evaluation1)
.....
/EquityCalculatorMontecarlo/Scoring.cpp
various function definitions
/EquityCalculatorMontecarlo/Scoring.h
using CardsWithTableCombined = std::set<std::string>;
using Score = std::vector<std::tuple<int, int>>;
bool eval_best_hand(const std::vector<CardsWithTableCombined>&);
std::tuple< std::vector<int>, std::vector<int>, std::string> calc_score(const CardsWithTableCombined&);
template<typename T>
std::vector<T> slice(std::vector<T> const& v, int m, int n)
{
if (m > v.size())
.....
/EquityCalculatorMontecarlo/Deck.h
various function declarations
/EquityCalculatorMontecarlo/Deck.cpp
various function definitions
What could be the problem that the test project cannot access my main EquityCalculatorMontecarlo project? I have also tried to select it as a dependency but nothing seems to help. I cannot run the tests.
Any suggestions are highly appreciated.
Definitions of eval_best_hand and its dependencies are present only in EquityCalculatorMontecarlo project that is an executable, you are just referring the function declaration of eval_best_hand from header files in your Tests project but not linking them. Either you make the definitions of whatever functions designated to be used in other projects (Executables) into a common static lib (Say Utils.lib), and link your projects against that static library or include all the .cpp files that contains definitions of necessary functions to Tests.vcxproj.
I think, simply adding Scoring.cpp and Deck.cpp to Tests.vcxproj will solve the linker errors.
You may also create a separate project namely "Utils.lib" with only Scoring.cpp and Deck.cpp source files and link that lib to whatever executable project that needs to consume those utility methods. This is basically to meet the purpose of reusing and easy maintenance. In this case your main project (EquityCalculatorMontecarlo) may only contain a main function and code to consume functions in Scoring.h and Deck.h(Definitions present in Utils.lib).
#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've been trying to write a small application which will work with mysql in C++. I am using MySQL server 5.1.41 and MySQL C++ connector 1.0.5. Everything compiles fine when i write console applications, but when i try to compile windows forms application exactly the same way (same libraries, same paths, same project properties) i get this errors:
Error 1 error LNK2001: unresolved external symbol "public: virtual int __clrcall sql::mysql::MySQL_Savepoint::getSavepointId(void)" (?getSavepointId#MySQL_Savepoint#mysql#sql##$$FUAMHXZ) test1.obj test1
Error 2 error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __clrcall sql::mysql::MySQL_Savepoint::getSavepointName(void)" (?getSavepointName#MySQL_Savepoint#mysql#sql##$$FUAM?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) test1.obj test1
following instructions from here, i've got this:
Undecoration of :- "?getSavepointId#MySQL_Savepoint#mysql#sql##UEAAHXZ"
is :- "public: virtual int __cdecl sql::mysql::MySQL_Savepoint::getSavepointId(void) __ptr64"
Undecoration of :- "?getSavepointName#MySQL_Savepoint#mysql#sql##UEAA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ"
is :- "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl sql::mysql::MySQL_Savepoint::getSavepointName(void) __ptr64"
but what should i do now?
Project + Properties, General, change Common Language Runtime support to /clr from /clr:pure
Looks like an issue with calling conventions. I am not very familiar with managed C++, but this might help you.