0
votes

(Re-written for clarity)

I have a multi-project solution that I am looking to convert from using .lib to .DLL files. I have created my __declspec macros and applied it to every class except for those in the project that creates the final .exe. The linker is throwing a fit on just about everything, however. I have set up to ignore errors about exporting templated objects.

One example is this:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall Rail::SetNextRail(class Rail *)" (__imp_?SetNextRail@Rail@@QAEXPAV1@@Z) referenced in function "public: static void __cdecl MyUtilities::CreateBezierRails(int,class MyVector *,class std::vector > &)" (?CreateBezierRails@MyUtilities@@SAXHPAVMyVector@@AAV?$vector@PAVRail@@V?$allocator@PAVRail@@@std@@@std@@@Z) MyUtilities.obj

Unresolved external symbol on my __declspec(dllimport)? That doesn't seem right. It is getting placed by a macro such as:

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

Basically, what gives? Why am I getting these errors and how can I fix them? Thank you to everybody who has tried to help thus far, but I am still stuck with this.

4

4 Answers

2
votes

Are you linking against MyRenderer.lib?

2
votes

Do you export your functions and classes using

__declspec(dllexport)

and import them using

__declspec(dllimport)

? If not, you will have to do this. In your header, during compiling the DLL, you will need to have the dllexport clause, and when using the header in other DLLs or EXEs, you will have to use the dllimport clause. You can easily do this by defining a macro like

// set this in preprocessor options for the DLL
#ifdef MYDLL
# define MYDLL_IMPORTEXPORT __declspec(dllexport)
#else
# define MYDLL_IMPORTEXPORT __declspec(dllimport)
#endif
class MYDLL_IMPORTEXPORT MyClass {};
0
votes

Well its saying that it found a declaration but no implementation. Are you sure you are compilnig the file with the function implementation in it? Have you remembered to put the MyRenderer:: before the DrawVertices call? Are you sure you are linking both the libraries into the executable?

Edit: When compiling a lib the library leaves a stub, effectively, saying I want this function when you can link it to me.

When you run the linker it runs through all the libraries looking for these stubs and "links" them to the actual implementation. Each cpp file you build compiles to an object file and this object file works in exactly the same way. If it can't link the stub to the actual function then you get a linker error such as you are seeing. Thus, either your renderer library is not being linked into the executable OR the implementation is missing something vital such as the MyRenderer::. Though if it was the latter i'd expect other problems to arise such as the lack of a IDirect3DDevice which, i assume, is a member of the class. Thus, most probably, you are failing to link the .lib in.

0
votes

there are different configurations of DLLs.

  • staticly linked DLL - the implementations are in a DLL, and the definitions are in a .lib. You statically link to the .lib (which is kinda like a header), and the lib tells c++ how to call the function. this is probably what you want. make sure you get your __declspecs right.
  • dynamically linked DLL - everything is in the DLL, the definitions are also in the DLL, you need to manually set up function pointers to all the exported things, which are indexed by a string at runtime.

Google will help and made this CW so someone can make this answer suck less.

i also advise you to get DLLs working in a skeleton app.