C++ – Under what conditions will you get unresolved external symbol for __declspec(dllimport)

cdlldllimportlinkervisual studio

I am converting an application to use .dlls and I'm riddled with linker errors stating

unersolved external
symbol"__declspec(dllimport) public:
void __thiscall
Rail::SetNextrail(class Rail *)"

There is more gibberish at the end of this error message. Why should this happen and how do you fix it? __declspec(dllimport) is being placed with a macro defined as:

#ifdef LUDOAI_EXPORT
#define DECLSPECAI __declspec(dllexport)
#else
#define DECLSPECAI __declspec(dllimport)
#endif

Best Answer

I believe what you need to do is specify the Rails "import library" to the linker. Using the GUI, this is on the linker tab of project settings, under "additional libraries."

The "import library" is a .LIB file which contains symbols that resolve to the imports of the corresponding library. In the symbols from the .LIB file is an unconditional jump to the imports table's corresponding address for the import. When your code calls an import, it really calls this stub in the import library, which jumps to the import.

Related Topic