Trying to solve a LNK2019 error I made a small code to make this error again outside of my project. The error does not appear at the same place but seam to be similar. I am using Visual Studio 2013 and I did not try with an other IDE.
my program :
the main.cpp :
#include "functions.hpp"
int main(int argc, char *argv[]){
core::function1();
return 0;
}
functions.hpp :
#ifndef _functions_hpp
#define _functions_hpp
#include "core.hpp"
namespace core{
void function1();
}
#endif
core.hpp :
#ifndef _core_hpp
#define _core_hpp
#include <string>
namespace core{
//some defines
}
#endif _core_hpp
functions.cpp :
#include "functions.hpp"
#include "Input_Output.hpp"
namespace core{
void functions(){
type_writer writer;
writer.save();
}
}
Input_Output.hpp :
#ifndef _INPUT_OUTPUT_HPP
#define _INPUT_OUTPUT_HPP
namespace core{
class type_writer{
public:
void save();
};
}
#endif
Input_Output.cpp :
#include "Input_Output.hpp"
namespace core{
void type_writer::save(){
}
}
the log error :
Comand Line Compile:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt main.cpp
Link :
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt main.cpp
error :
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl core::function1(void)" (?function1@core@@YAXXZ) referenced in function _main
1>E:\Nicolas\frame_external_error\Debug\frame_external_error.exe : fatal error LNK1120: 1 unresolved externals
In my original project, this error came from another external symbol (from type_writer writer;) but I think if I understand what is the origin of the error in this exemple I should find a way to solve it in my own project.
Thanks for reading !