Can someone explain to me why when I include header files in my code, it is not running in VS Code? (OS: Windows 10)
If I run this code:
#include <iostream>
int main () {
std::cout << "Hello from C++ " << std::endl;
}
the VS Code is working fine, but if I run this code:
#include <iostream>
#include "./lib/Methods.h"
int main () {
int a = MyMethod(5);
std::cout << "Hello from C++ " << std::endl;
std::cout << "a = " << a << std::endl;
}
I get this error:
PS C:\Users\giorg\Documents\Development\Tests\node-addons-test\src> g++ main.cpp
C:\Users\giorg\AppData\Local\Temp\ccIQQEE1.o:main.cpp:(.text+0x1e): undefined reference to `MyMethod(int)' collect2.exe: error: ld returned 1 exit status PS
C:\Users\giorg\Documents\Development\Tests\node-addons-test\src>
lib/Methods.cpp
int MyMethod(int x) {
return x * 2;
}
lib/Methods.h
int MyMethod(int x);
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"/src/lib"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}