I am making libraries, to use in multiple games so I don't have to duplicate code. In this example, my main program is main.cpp
and the other two files are my libraries. Everything is linked correctly.
When all my functions in Common Functions Library.h
have static
in front, I get the error: static function 'std::string common::joinAll(std::vector<std::string,std::allocator<_Ty>>)' declared but not defined (Error C2129)
from main.cpp
(even though the functions are in the Common Functions Library.h/.cpp
), and it says the line number is one more than there is in the whole program which is very strange.
So, to fix this, I found people online saying I need to replace static
with inline
, so I tried again and got this error: cannot open file 'Common Functions Library.lib' (Error LNK1104)
Then I tried setting all the functions back to static
, and then commented out #include "Cubes Library.h"
in main.cpp
, which didn't give me the other errors anymore, but instead things related to the cubes library (obviously). However, this stopped on line 65, after where the functions which caused the errors saying they weren't defined. I have no clue what is going wrong, but thanks for any help :)
Code:
main.cpp
#include "Common Functions Library.h"
#include "Cubes Library.h"
// Using functions from `Common Functions Library`
Common Functions Library.cpp (Part of a DLL)
#include "Common Functions Library.h"
namespace common
{
// Functions
}
Cubes Library.cpp (Part of a DLL)
#include "Cubes Library.h"
#include "Common Functions Library.h"