I have read many posts about this problem on stackoverflow and I have tried them but having no luck. I have removed some files which inherit the interface class but still the error multiple definition for functions in the protocol.h file.
main.cpp
#include "interfaceinterface.h"
interface.h
#pragma once
#ifndef INTERFACE_H
#define INTERFACE_H
#include "..buffer.h"
#include "..enums.h"
#include "..cpu.h"
...More Code
#endif
interface.cpp
#include "interface.h"
buffer.h
#ifndef BUFFER_H
#define BUFFER_H
#include "common.h"
#include "protocol.h"
...More Code
#endif
common.h
#pragma once
...Common include files like <vector> and such
protocol.h
#pragma once
#ifndef PROTOCOL_H
#define PROTOCOL_H
...More Code
#endif
enums.h
Just Code
cpu.h
Just code
command with gcc 13.2.0
"args": [
"-fdiagnostics-color=always",
"-I",
"${fileDirname}",
"-fcommon",
"-g",
"-std=c++20",
"${workspaceFolder}\*.cpp",
"${workspaceFolder}\interface\*.cpp"
"-o",
// "${fileDirname}\${fileBasenameNoExtension}.exe"
"${fileDirname}\main.exe"
]
Since only two cpp files so pretty much main.cpp and interface.cpp
- I have tried putting extern in front of the functions
- I have put #pragma once and #ifndef on all the files
- The file structure to see if any files gets included twice
interface{
buffer{
common
protocol
}
cpu
enums
}
main
So it looks like common,protocol,buffer,cpu,enums,interface,main in that particular order