0

I am trying to use the openssl library for my C++ code. I was able to configurate the include path correctly, but when I compile my program there is still a linker issue -> C:/Users/felix/my_future/PMS_Blockchain_CPP/pms_blockchain/src/Wallet.cpp:77: undefined reference to `EVP_PKEY_CTX_new_id' collect2.exe: error: ld returned 1 exit status

I am using mingw64 inside visual studio code, my task.json looks like this:

{
"tasks": [
  {
    "type": "cppbuild",
    "label": "C/C++: g++.exe build active file",
    "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
    "args": [
      "-fdiagnostics-color=always",
      "-g",
      "${workspaceFolder}\\pms_blockchain\\src\\**.cpp",
      "${workspaceFolder}\\openssl\\**.h",
      "-o",
      "${workspaceFolder}\\${fileBasenameNoExtension}.exe"
    ],
    "options": {
      "cwd": "${fileDirname}"
    },
    "problemMatcher": ["$gcc"],
    "group": {
      "kind": "build",
      "isDefault": true
    },
    "detail": "Task generated by Debugger."
  }
],
"version": "2.0.0"

}

I think I have to add a new task for using the .lib files. I am not familiar with configurations like this, it already took me a lot of time to figure out how to create the existing task for compiling. I appreciate your help.

Felix Jost
  • 23
  • 6
  • 1
    If possible you should just use pacman to install it. And then just add the additional library to your args. You don't want to create a different task. – drescherjm Oct 19 '22 at 21:06
  • Can you pls give me an example how the args statement would look like with the library and thanks for you answer – Felix Jost Oct 19 '22 at 21:25
  • 1
    From this answer [https://stackoverflow.com/a/4352761/487892](https://stackoverflow.com/a/4352761/487892) it should be `-lssl`, `-lcrypto` added to your args. And remove `"${workspaceFolder}\\openssl\\**.h",` This is assuming you installed openssl in the mingw64 terminal with pacman – drescherjm Oct 19 '22 at 21:34
  • The new compiling takes a lot of time, I think this is maybe a good sign. Thank you for your help, I will give you a feedback tomorrow and I really would upvote your comments but unfortunately I don't have the privilege for that. – Felix Jost Oct 19 '22 at 21:55
  • "args": [ "-fdiagnostics-color=always", "-g", "${workspaceFolder}\\pms_blockchain\\src\\**.cpp", "-o", "${workspaceFolder}\\${fileBasenameNoExtension}.exe", "-L", "${userHome}\\OpenSSL-Win64\\lib", "-lssl", "-lcrypto", "${workspaceFolder}\\openssl\\**.h" ], – Felix Jost Oct 21 '22 at 21:10
  • Please answer your own question and add the tasks.json file containing your changes and write 1 or two sentences about this. If you do that I will upvote your answer. – drescherjm Oct 21 '22 at 21:58
  • Thanks a lot, I've done it – Felix Jost Oct 26 '22 at 19:37

1 Answers1

1

So with the help of drescherjm and his recommendation I was able to fix the issue. My problem was that I just made the configurations for using the header files in code, inside the c_cpp_properties.json file like this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\OpenSSL-Win64\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}

But I didn't made the configuration for using the pre-build lib-files in the compiling process. Because the lib-files are containing the implementation for the header files, this is necessary. In the answer of the stackoverflow-link he provided, I was able to find the right commands to make the setup. Now my file is looking like this:

{
    "tasks": [
      {
        "type": "cppbuild",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
        "args": [
          "-fdiagnostics-color=always",
          "-g",
          "${workspaceFolder}\\pms_blockchain\\src\\**.cpp",
          "-o",
          "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
          "-L",
          "${userHome}\\OpenSSL-Win64\\lib",
          "-lssl",
          "-lcrypto",
          "${workspaceFolder}\\openssl\\**.h"
        ],
        "options": {
          "cwd": "${fileDirname}"
        },
        "problemMatcher": ["$gcc"],
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "detail": "Task generated by Debugger."
      }
    ],
    "version": "2.0.0"
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
Felix Jost
  • 23
  • 6