I am trying to include the SOCI library in my C++ library. The compilation fails with:
fatal error: soci/soci.h: No such file or directory
3 | #include "soci/soci.h"
I have downloaded and built the library in the path:
/users/niko/.env/libraries
My c_cpp_properties.json looks like:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"users/niko/.env/libraries/include/**"
],
"defines": [],
"compilerPath": "/opt/devtoolset//gcc",
"cStandard": "gnu17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-Wall",
"-Wextra",
"-Wconversion",
"-Wpedantic",
"-I /users/niko/.env/libraries/include/**"
]
}
],
"version": 4
}
And correspondingly, the tasks.json looks like:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp build active file",
"command": "/opt/devtoolset//cpp",
"args": [
"-fdiagnostics-color=always",
"-I",
"users/niko/.env/libraries/include/*",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: /opt/devtoolset//cpp"
}
]
}
IntelliSense correctly finds it from this path, but the compilation fails. I have tried various things on SO, but nothing seems to work.
Related
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"
}
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"
}
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`"
I am trying to use mlpack in VSCode. I have installed the library using brew, and have included the path in c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/Cellar/mlpack/3.4.2_2/include"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
However, when I try and include core.hpp, I get the following error:
cannot open source file "boost/serialization/serialization.hpp" (dependency of "mlpack/core.hpp")C/C++(1696)
Does anyone know how to resolve this? It's my understanding that brew handles the dependencies, is this wrong?
Here is my current tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build all files",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${workspaceFolder}/src/*.cpp",
"--include-directory=/opt/homebrew/Cellar/mlpack/3.4.2_2/include",
"--include-directory=/opt/homebrew/Cellar/boost/1.75.0_3/include",
"--include-directory=/opt/homebrew/Cellar/armadillo/10.4.1_1/include",
"-o",
"${workspaceFolder}/build/app",
"-larmadillo",
"-lmlpack"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}
Edit: if I add paths for boost and armadillo:
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/Cellar/mlpack/3.4.2_2/include",
"/opt/homebrew/Cellar/boost/1.75.0_3/include",
"/opt/homebrew/Cellar/armadillo/10.4.1_1/include"
],
the error becomes:
'mlpack/core.hpp' file not found
In includePath just add this:
"/opt/homebrew/opt/boost/include"
I'm currently trying to compile a C++ file using Visual Studio Code and I tried editing the c_cpp_properties.json file adding the include folders in the includePath variable and the tasks.json file adding arguments but I still can't compile, it gives me this error:
LINK : fatal error LNK1104: can't open 'SDL2.lib'
Here are the files:
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\vclib\\include\\",
"C:\\vclib\\SDL2_image-2.0.5\\include\\"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"/IC:\\vclib\\include",
"/IC:\\vclib\\SDL2_image-2.0.5\\include",
"${file}",
"SDL2.lib", "SDL2main.lib", "SDL2_image.lib",
"/link /LIBPATH:C:\\vclib\\lib\\x64;C:\\vclib\\SDL2_image-2.0.5\\lib\\x64",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
UPDATE: the second file looks like this now:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"SDL2.lib", "SDL2main.lib","SDL2_image.lib",
"/IC:\\vclib\\include",
"/IC:\\vclib\\SDL2_image-2.0.5\\include",
"/link /LIBPATH:C:\\vclib\\lib\\x86", "/LIBPATH:C:\\vclib\\SDL2_image-2.0.5\\lib\\x86",
"/SUBSYSTEM:CONSOLE"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Now I have this error:
SDL2main.lib(SDL_windows_main.obj) : error LNK2019: extern symbol not resolved __imp__CommandLineToArgvW#8 referenced in function _main_getcmdline
I had the same issue and got it to work eventually using some of the answers given here: Compile a C / SDL program with Visual C++ 2013 from the Command Line
My c_cpp_properties.json looks like:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"G:/SDL2/include/",
"G:/SDL2/lib/x86/"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
My tasks.json file looks like this:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"/I G:\\SDL2\\include\\",
"/link G:\\SDL2\\lib\\x86\\SDL2main.lib G:\\SDL2\\lib\\x86\\SDL2.lib"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
It didn't work for a while until I remembered to put the SDL2.dll runtime binary in the workspace directory.
And including:
#define SDL_MAIN_HANDLED
#include <G:\SDL2\include\SDL.h>
Which I got from Do I need SDL's main() function?