2021年3月23日星期二

Multiple Definitions of 'function name' : Compiling with #includes "file.cpp"

fixed: instead of having #includes "file.cpp" I should have made a header file "file.hpp" for my functions and included that in my various other files, clever people answered this in the comments

Im trying to compile an tictactoe simulator, and I made a bunch of base functions to parse the input of the game state, which is given as a string ("oxo---xox" for example), which are in a "functions.cpp" file, which I have included in a my main.cpp file using #include "functions.cpp", as well as in my Node.cpp file, which uses the functions as part of its functions as well

having done that, when I compile my program, when I compile all of that using

g++ main.cpp functions.cpp Node.cpp Node.h  

it gives multiple errors stating

multiple definitions of 'function_name(std:: yadda yadda)'  

for further context here are the files' include statements

main.cpp :

#include "functions.cpp"  #include <iostream>  #include <string>  #include <vector>  

Node.cpp :

#include "functions.cpp"  #include <string>  
https://stackoverflow.com/questions/66773991/multiple-definitions-of-function-name-compiling-with-includes-file-cpp March 24, 2021 at 10:39AM

没有评论:

发表评论