void myFunction() { // ERROR: defined here // implementation }
The error message occurs in Microsoft C++ when you declare a function with __declspec(dllimport) but then attempt to provide a definition (implementation) for that function in the same module (usually a .cpp file being compiled into an executable or DLL).
LIB_API void MyFunction();
) occurs when a compiler encounters a function body (definition) for a symbol that it has been told is located in an external 1. Root Cause In Windows programming, __declspec(dllimport)
// main.cpp #include "mymath.h"
To understand why this error occurs, you must first understand the duality of Windows DLL macros.
If you ignore this error or fail to resolve it, you may encounter a range of issues, including: a function declared dllimport may not be defined
__declspec(dllimport) is a Microsoft-specific keyword that is used to declare a function or variable as being imported from a Dynamic Link Library (DLL). When you use this keyword, you're telling the compiler that the function or variable is defined in a DLL and should be linked against.
When someone else uses your DLL, the macro is NOT defined. The function becomes dllimport . Common Pitfalls to Check void myFunction() { // ERROR: defined here //
Are you accidentally including the .cpp file instead of the .h file?