Use precompiled openssl in C++ with vscode and mingw64 - c++

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.

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"
}

Related

Cant get Opencv C++ to run on M1 Visual Code

After days on working on this problem on my M1 studio, training to figure out, I got all these things correct on visual Code, but nothing worked, it will hang and never run; if I use Cmake, it will compile, but for debugging I could never get it to Run.
Meaning it will Run, but to will hang on my M1, everything worked fine, but could not debug code on MS Visual Code using OpenCV C++
Then I realized that I was trying to use Microsoft Software with Apple M1 and then installed XCODE, and everything worked great!!! And I love it!!!
And most important of all, I AM not using homeBrew!!!
1.- under "headers," I added /usr/local/include/opencv4
2.- under libraries, I added /usr/local/lib
3.- then I added the link libraries: libopencv_core.dylib, libopencv_imgproc.dylib, libopencv_highgui.dylib, libopencv_imgcodecs.dylib, libopencv_videoio.dylib.
So beautiful!!!! I was able to compile and debug my code, with break points and everything.
Here is my files for visual Code, for anyone:
tasks.json
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"-I/usr/local/include/opencv4/**",
"-L/usr/local/lib",
"-lopencv_core",
"-lopencv_highgui",
"-lopencv_imgcodecs",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties.jason
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include/opencv4/**",
"/usr/local/lib"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}

VScode "No such file or directory" error after trying to give the path [duplicate]

This question already has answers here:
How to avoid errors in Vscode for putting header files in a separate directory than src
(2 answers)
#include errors detected in vscode
(22 answers)
Closed 4 months ago.
I downloaded ncurses through msys64 then tried to include it in my source file as #include <ncurses.h>, then it didn't work so I tried changing the c_cpp_properties.json file
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\msys64\\mingw64\\include",
"C:\\MinGW\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:\\MinGW\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
the error persisted, what am I doing wrong
not sure what am I doing wrong, help is appreciated
i solved this problem in my vscode but i use linux, maybe this can be useful for you:
I inserted in the file "tasks.json", in the category args (cpp compiler argument) the option "** - I **", where I could define where my library is:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ compila il file attivo",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-I", //option of the compiler for set the library folder
"/usr/local/include/png++-0.2.10/", //patch to the library folder
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Attività generata dal debugger."
}
],
"version": "2.0.0"
}
this will probably help you

VS CODE, Can't link and compile multiple files of code

I am learning C++ and using VS CODE as my editor. The problem is that my compiler says that it can't find the header files created by me.
Starting build...
C:\MinGW\bin\g++.exe -g C:\Users\berkb\Desktop\codes\accpp\mains\test.cpp -o C:\Users\berkb\Desktop\codes\accpp\mains\test.exe
C:\Users\berkb\Desktop\codes\accpp\mains\test.cpp:7:10: fatal error: split.h: No such file or directory
7 | #include "split.h"
| ^~~~~~~~~
compilation terminated.
Build finished with error(s).
I included them all in a separate folder inside my workspace folder, I also added their exact path to my c_cpp_properties.json file.
I am not really sure what the problem is so here are my c_cpp_properties.json, task.json files.
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/berkb/Desktop/codes/accpp/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

fatal error: opencv2/core.hpp: No such file or directory Ubuntu and Visual Studio Code

I have the opencv installed in /usr/include/opencv4 folder
I configured the VSCode as it should be, and the IntelliSense can detect the library.
The configuration should be correct (I guess)
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/opencv4/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
However, I get an error:
fatal error: opencv2/core.hpp: No such file or directory
2 | #include <opencv2/core.hpp>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Am I missing something? Thanks
After a couple of days, I was able to find out the solution.
It was to add the necessary flags to the build task.
I posted the full sample on GitHub. Hopefully, it will help someone in the future.
The task.json should be
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"`pkg-config",
"--cflags",
"--libs",
"opencv4`"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
The missing was to add these arguments
"`pkg-config",
"--cflags",
"--libs",
"opencv4`"

"unknown type name 'NSString'" error when trying to use Metal in a C++ project (vs code, mac m1)

As indicated by the title, I got many "unknown type name 'NSString'" errors from files including NSObjCRuntime.h, NSObject.h, and NSZone.h. Then I added
#include <Foundation/NSString.h>
to main.cpp file, but the errors persist.
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
"/opt/homebrew/include",
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm"
}
],
"version": 4
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-g",
"${file}",
"-I:/opt/homebrew/include",
"-I:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
"-I:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include",
"-I:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"-I:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"-I:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
The "include" part of main.cpp
#include <Foundation/NSString.h>
#include <Metal/Metal.h>
#include <MetalKit/MTKView.h>
#include <MetalKit/MetalKit.h>
using namespace std;
What did I miss?
Xcode will compile .cpp files as C++ files by default and #imports for Objective-C stuff won't work. You should rename your file to .mm or change its type in Inspector window on the right.
Since you aren't using Xcode, but rather vscode, it's much easier to just rename the file, cause then clang will automatically compile it as Objective-C++