Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved external symbol in object files

People also ask

How do I fix unresolved external symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What causes unresolved external symbol?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. That's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.

What is an unresolved symbol?

If the linker cannot find the external definition for a symbol that has no definition internally, it reports an Unresolved External Symbol error.

How do I fix unresolved external symbol LNK2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .


This error often means that some function has a declaration, but not a definition.

Example:

// A.hpp
class A
{
public:
  void myFunc(); // Function declaration
};

// A.cpp

// Function definition
void A::myFunc()
{
  // do stuff
}

In your case, the definition cannot be found. The issue could be that you are including a header file, which brings in some function declarations, but you either:

  1. do not define the functions in your cpp file (if you wrote this code yourself)
  2. do not include the lib/dll file that contains the definitions

A common mistake is that you define a function as a standalone and forget the class selector, e.g. A::, in your .cpp file:

Wrong: void myFunc() { /* do stuff */ }
Right: void A::myFunc() { /* do stuff */ }


Check you are including all the source files within your solution that you are referencing.

If you are not including the source file (and thus the implementation) for the class Field in your project it won't be built and you will be unable to link during compilation.

Alternatively, perhaps you are using a static or dynamic library and have forgotten to tell the linker about the .libs?


It looks to be missing a library or include, you can try to figure out what class of your library that have getName, getType etc ... and put that in the header file or using #include.

Also if these happen to be from an external library, make sure you reference to them on your project file. For example, if this class belongs to an abc.lib then in your Visual Studio

  1. Click on Project Properties.
  2. Go to Configuration Properties, C/C++, Generate, verify you point to the abc.lib location under Additional Include Directories. Under Linker, Input, make sure you have the abc.lib under Additional Dependencies.

I've just seen the problem I can't call a function from main in .cpp file, correctly declared in .h file and defined in .c file. Encountered a linker error. Meanwhile I can call function from usual .c file. Possibly it depends on call convention. Solution was to add following preproc lines in every .h file:

#ifdef __cplusplus
extern "C"
{
#endif

and these in the end

#ifdef __cplusplus
}
#endif

I had an error where my project was compiled as x64 project. and I've used a Library that was compiled as x86.

I've recompiled the library as x64 and it solved it.


I had the same link errors, but from a test project which was referencing another dll. Found out that after adding _declspec(dllexport) in front of each function which was specified in the error message, the link was working well.


sometimes if a new header file is added, and this error starts coming due to that, you need to add library as well to get rid of unresolved external symbol.

for example:

#include WtsApi32.h

will need:

#pragma comment(lib, "Wtsapi32.lib")