Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Permission denied collect2.exe: error: ld returned 1 exit status" Error when using #include<openssl/evp.h> in VSCode #19941

Closed
Batres3 opened this issue Dec 20, 2022 · 1 comment
Labels
help wanted triaged: question The issue contains a question

Comments

@Batres3
Copy link

Batres3 commented Dec 20, 2022

So I installed OpenSSL directly following the instructions in the install.txt file you get when cloning the git repository. It installed it seemingly with no issues and it is located in C:/Program Files/OpenSSL and C:/Program Files(x86)/OpenSSL. Inside each of those there are 4 folders: bin, html, include, lib.

In VSCode I'm using the code runner extension with the following command:

g++ -I "C:/Users/Batres/vcpkg/installed/x86-windows/include" "C:/Program Files/OpenSSL/include" simple_functions.cpp -o simple_functions 

the "C:/Users/Batres/vcpkg/installed/x86-windows/include" is a different library called XTensor, which works completely fine as I have tested the code without OpenSSL and it outputs the correct results with no problem.

I have also tried these commands, all yeilding the same error. I have also tried running all the same commands through a terminal with admin priviliges and it gives the same error. I even copied the folder to a different directory inside my /Documents/ folder and it still didn't help. My compiler is mingw and I'm on Windows 11.

g++ -I "C:/Users/Batres/vcpkg/installed/x86-windows/include" "C:/Program Files (x86)/OpenSSL/include" simple_functions.cpp -o simple_functions 

and

g++ -I "C:/Users/Batres/vcpkg/installed/x86-windows/include" -L "C:/Program Files/OpenSSL/lib" simple_functions.cpp -o simple_functions -lssl 

This last one returns a different error. Insted of being acces denied it seems like none of the functions or variables that I call inside my code are recognised, so these are the errors: undefined reference to `EVP_MD_CTX_new', or any other functions or variables I call, my code is the following:

#include <cmath>
#include <iomanip>
#include <cstddef>
#include "xtensor.hpp"
#include <functional>
#include <string>
#include <typeinfo>
#include <vector>
#include <regex>
#include <array>
#include <algorithm>
#include <openssl/sha.h>
#include <openssl/evp.h>

/*
def hash_string(string):
    # Truncating at 16 bytes for cleanliness
    hasher = hashlib.sha256(string.encode())
    return hasher.hexdigest()[:16]
    */
std::string hash_string(std::string string) {
    // Truncating at 16 bytes for cleanliness
    std::array<unsigned char, SHA256_DIGEST_LENGTH> hash;
    std::array<unsigned char, SHA256_DIGEST_LENGTH>::iterator it;

    EVP_MD_CTX* ctx = EVP_MD_CTX_new();
    EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
    EVP_DigestUpdate(ctx, string.c_str(), string.size());
    EVP_DigestFinal_ex(ctx, hash.data(), NULL);

    // Convert the hash to a hexadecimal string
    std::stringstream ss;
    for (it = hash.begin(); it != hash.end(); it++) {
        ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(*it);
    }
    return ss.str().substr(0, 16);
}

int main(){
    double a = gen_choose(2,5);
    std::string input = "Hello, world!";
    std::string output = hash_string(input);
    std::cout << std::setprecision(16) << output << std::endl;
    return 0;
}

Ignore all the other #includes, they are for different functions that work with no issue. As you can probably see I have some python code commented above my C++ code. Thats simply because it's a function I tried transalting using ChatGPT, but that's not relevant to the error.
The weird thing is that even though it says access denied when compliling, Intellisense can acess the files just fine, I can right click on the functions and "Go to Definition" and it takes me to my C:/Program Files/OpenSSL/include/openssl/ folder.

If anyone knows how to fix the error I would be very thankful.

@Batres3 Batres3 added the issue: bug report The issue was opened to report a bug label Dec 20, 2022
@t8m t8m added help wanted triaged: question The issue contains a question and removed issue: bug report The issue was opened to report a bug labels Dec 21, 2022
@t8m
Copy link
Member

t8m commented Dec 21, 2022

g++ -I "C:/Users/Batres/vcpkg/installed/x86-windows/include" "C:/Program Files/OpenSSL/include" simple_functions.cpp -o simple_functions 

This looks incorrect - you need to duplicate the -I before each include directory. Also this command is actually directly compiling and linking, so you'll also need the -L option to find the libcrypto/libssl. Also you need to use -lcrypto for EVP functions and not -lssl.

@Batres3 Batres3 closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted triaged: question The issue contains a question
Projects
None yet
Development

No branches or pull requests

2 participants