Windows 11, Visual Studio 2019, C++
The goal is to learn how to use a Base58 encoding function. Below is the code I found and put into a console app. A console app was created just for this one function. The below code was edited into a dot cpp file and included in the main file. I have not yet written any code to call it.
Building the process solicits two sets of error messages. I have tried copy paste the error message into Notepad then break it up into segments and try to understand it. I cannot derive a simple explanation other than something is declared twice. I cannot determine where in the code the error is found. Here is the function followed by the two error messages.
What are the critical parts of the error message?
If the first does not make this obvious then how can I trace this back a particular line in the source code?
Thank you for your time.
#include <iostream>
#include <string.h>
#include <vector>
// BK removed inline statement for VS 2019
//inline static constexpr const uint8_t base58map[] = {
static constexpr const uint8_t base58map[] = {
'1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z' };
// BK my description of the arguments:
// data: The string to be encoded to base 58
// mappoing: Look up the binary values of the input string and the array
// provides the characters to be used for each value.
std::string EncodeBase58(const std::vector<uint8_t>& data, const uint8_t* mapping)
{
std::vector<uint8_t> digits((data.size() * 138 / 100) + 1);
size_t digitslen = 1;
for (size_t i = 0; i < data.size(); i++)
{
uint32_t carry = static_cast<uint32_t>(data[i]);
for (size_t j = 0; j < digitslen; j++)
{
carry = carry + static_cast<uint32_t>(digits[j] << 8);
digits[j] = static_cast<uint8_t>(carry % 58);
carry /= 58;
}
for (; carry; carry /= 58)
digits[digitslen++] = static_cast<uint8_t>(carry % 58);
}
std::string result;
for (size_t i = 0; i < (data.size() - 1) && !data[i]; i++)
result.push_back(mapping[0]);
for (size_t i = 0; i < digitslen; i++)
result.push_back(mapping[digits[digitslen - 1 - i]]);
return result;
}
First error message
1> LINK : E:\WX\base_58_encode_tests\Debug\base_58_encode_tests.exe not found or not built by the last incremental link; performing full link
1> HetDerwel_may_2020.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl EncodeBase58(class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned char const *)" (?EncodeBase58@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Abv ?$vector@EV?$allocator@E@std@@@2@Peter Bertels @Z) already defined in base_58_encode_tests.obj
1> E:\WX\base_58_encode_tests\Debug\base_58_encode_tests.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Done building target "Link" in project "base_58_encode_tests.vcxproj" -- FAILED.
Second error message
1>HetDerwel_may_2020.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl EncodeBase58(class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned char const *)" (?EncodeBase58@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Abv ?$vector@EV?$allocator@E@std@@@2@Peter Bertels @Z) already defined in base_58_encode_tests.obj
1>E:\WX\base_58_encode_tests\Debug\base_58_encode_tests.exe : fatal error LNK1169: one or more multiply defined symbols found