0

I am trying to make a static library (.a file) and I have a main.cpp (Where I call the function), a library.cpp (The code of the library) and a header file which should work in theory (I watched and followed countless tutorials about how to do it) but it doesn't.

It gives me the error: identifier "Sus" is undefined (Where Sus the name of the function)

I tried changing the include path by following this answer: How to avoid errors in Vscode for putting header files in a separate directory than src but it doesn't help since the files are already in the same folder, I also tried including the specific path in the IncludePath but still no luck. I tried rewriting, reinstalling VSCode and even creating again the project but it doesn't work.

Here is my task.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}",
                "${workspaceFolder}/include/**"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build",
            "detail": "compiler: cl.exe"
        }
    ]
}

And my c_cpp_propreties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

Header File(Teroro.h):

#pragma once

class Teroro{
    public:
        static int Sus(int a, int b);
};

Library File(Teroro.cpp):

#include "Teroro.h"

int Sus(int a, int b)
{
    return a+b+69;
}

And the Main File(Main.cpp):

#include "Teroro.h"
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<Sus(a,b);
}
Teroro
  • 3
  • 5
  • Do I add them as text ? – Teroro Nov 23 '22 at 09:02
  • Done just added them – Teroro Nov 23 '22 at 09:06
  • `int Sus(int a, int b)` is not `static int Teroro::Sus(int a, int b)`. Please include the error exactly as output by the compiler in the question. – Richard Critten Nov 23 '22 at 09:07
  • @Teroro The problem is that you're defining a free function called `Sus` instead of a member function. To solve this use `Teroro::Sus` as also mentioned in the [dupe](https://stackoverflow.com/questions/71208777/why-am-i-getting-an-undefined-reference-error-while-using-separate-cpp-and-h-f/71209257#71209257) – Jason Nov 23 '22 at 09:13
  • I fixed it and now it tells me undefines reference – Teroro Nov 23 '22 at 09:14

0 Answers0