0

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 !

  • 3
    `functions` vs `function1` ? – O'Neil Apr 24 '18 at 12:19
  • 2
    You only build the `main.cpp` file. The other source files will not be automatically built and linked, you have to do it explicitly. – Some programmer dude Apr 24 '18 at 12:20
  • 1
    You call `core::function1();`, you declare `namespace core{ void function1(); }`, but I do not see a definition for `function1` in the code you show. If there is no definition, then your usage will result in an unresolved externals error. – crashmstr Apr 24 '18 at 12:22
  • dude yes I called functions() in functions.cpp instead of function1()... it solve the error and so... the error from my project is somewhere else... – Ystalio Di Staniovich Apr 24 '18 at 12:32
  • [What is an undefined reference/unresolved external symbol error and how do I fix it?: Declared but did not define a variable or function.](https://stackoverflow.com/a/12574403/902497) – Raymond Chen Apr 24 '18 at 14:21

0 Answers0