I am having an issue where I have a ton of custom C/C++ header files (and respective .cpp files) where I would like to include them in other scripts in the visual studio code environment. I'm using windows 10. I thought I understood C/C++, but apparently not. Anyway, my goal is to be able to run something like the code below:
#include <iostream>
#include <JeffsLaboratory_Earth.h> // This causes the error, even though VS code opens the correct file if I right-click on it
int main() {
int x = 10;
int y = 20;
earth ear;
float f = ear.atm_alt_temp_dens;
std::cout << "Hello World" << std::endl;
}
where "JeffsLaboratory_Earth.h" points to a header file I have, which is in the same folder as the equivalent "JeffsLaboratory_Earth.cpp" file. This folder is local.
However, I am having tons of difficulty getting this to work. I am also including below the JSON files as well. As you can see, I have included the path to which this library/header file resides, but I am still getting "undefined reference to earth::earth()" and it terminates. Even though VS code will point to the right location of JeffsLaboratory_Earth.h when I right-clock on it. I know for a fact this code and library works, as I have used it in other applications, so that is not the issue. Any help would be much appreciated! Thanks.
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/JeffsLaboratory/commonsoftware/C++/PQRIntegratedSim_libraries"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++"
]
}
}
],
"version": 4
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-g", "main.cpp",
"-I", "C:\\JeffsLaboratory\\commonsoftware\\C++\\PQRIntegratedSim_libraries",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}