I'm new to C++. I installed the C/C++ and C/C++ Extension Pack and following instructions to install MSYS2.
Through MSYS2 I downloaded mingw-w64-x86_64-crypto++
and verified that it is present (pacman -Q
). I also confirm that the package is in the include
directory (in my case: D:\msys64\mingw64\include\cryptopp
).
I verified that VS Code was working (Hello World) using C/C++: g++.exe
.
I am trying to include:
#include <cryptopp/sha.h>
#include <cryptopp/hmac.h>
#include <cryptopp/pbkdf2.h>
When I attempt to run the solution, I get an error even though the header file is in the MSYS2 directory:
cryptopp/sha.h: No such file or directory
How can I resolve this?
My c_cpp_properties.json
reads as follows:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\msys64\\mingw64\\include\\"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\msys64\\ucrt64\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
I downloaded a short program that has a function (I commented out part of it afterward):
#include <iostream>
#include <string>
#include <cryptopp/sha.h>
#include <cryptopp/hmac.h>
#include <cryptopp/pbkdf2.h>
using namespace CryptoPP;
int main() {
std::string password = "my_password";
std::string salt = "random_salt";
unsigned int iterations = 10000; // Adjust iterations for desired strength
unsigned int key_length = 32; // Desired key length in bytes
byte key[key_length];
/*
PKCS5_PBKDF2_HMAC<SHA256> pbkdf;
pbkdf.DeriveKey(key, key_length, (const byte*)password.data(), password.length(),
(const byte*)salt.data(), salt.length(), iterations);
// Convert key to hex for display (optional)
std::string hex_key;
HexEncoder encoder;
encoder.Attach(new StringSink(hex_key));
encoder.Put(key, key_length);
encoder.MessageEnd();
std::cout << "Derived key: " << hex_key << std::endl;
*/
return 0;
}
The corrected tasks.json
that points to the correct library. Added libcryptopp.a
to the args
array:
Another point to note is that I was downloading the wrong library: See first comment.
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\msys64\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"D:\\msys64\\ucrt64\\lib\\libcryptopp.a"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}