I am using C++ MVS2019 and trying to use a vector function declared in h. file and defined in a secondary .cpp file, but the code doesn't compile and throws me 2 errors:
1. Error LNK1120 1 unresolved externals library D:\VS_cpp\library\library\x64\Release\library.exe 1
2. Error LNK2001 unresolved external symbol "struct Vector<int> __cdecl Biblio::debtors(void)" (?debtors@Biblio@@YA?AU?$Vector@H@@XZ) library D:\VS_cpp\library\library\library\library.obj 1
At the same time if I use the same code in Code Blocks it compiles perfectly. MAIN.cpp:
#include "test_int.h"
using namespace Biblio;
int main()
{
vector<int> debtorss = debtors();
int test = test_int();
}
test_int.h:
#ifndef BIBLIO_H_INCLUDED
#define BIBLIO_H_INCLUDED
#include <iostream>
#include <vector>
#include <string>
using namespace std;
namespace Biblio
{
vector<int> debtors();
int test_int();
}
#endif
test_int.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
namespace Biblio
{
vector<int> debtors()
{
vector<int> abc{ 1,2,3 };
return abc;
}
int test_int()
{
return 0;
}
}
If I kill "debtors()" function in all files and compile just with "int test_int()" function - everything is fine. But any vector function causes the same error. Since it works in CodeBlocks it might be some Visual Studio settings that have to be changed but since I am just studying I don't know much.
Would be happy to get any advice. Thanks.