Question

This question might be similar to DLL Exports: not all my functions are exported but as it was not fully answered there, I have to ask again. Also my case is because of the use of templates and exporting the whole classes slightly different.

Used environment: VS2008, cl9.0.

I have created a dll-project and added about 40 files (each class a file), mainly headers, because a lot of the classes are templates. An example of the heritage would be:

// Class1.h
template<class TYPE>
class TInt
{
    // Some member functions here
    // Also a function bool IsValid() const;
};
// Implementation of template here in the header

// Class2.h
#ifndef DllExpImpM
#define DllExpImpM __declspec(dllimport)
#endif

class DllExpImpM CInt : public TInt<double> 
{ 
    // Some member functions here
};

// Class2.cpp
// Some includes, including "stdafx.h", which sets DllExpImpM 
// to __declspec(dllexport)
template class DllExpImpM TInt<double>;
// Implemenation of CInt

So far, it worked fine as long as I used the debug (compile) option. I was able the use the dll project from other projects.

But if the dll projekt is compiled as release (which works fine), I cannot use it from other projects, because the compiler complains that are some missing functions, e.g. that IsValid() in TInt. I used the dependency walker to check it, and indeed, the compiler is right! The member function IsValid() was not exported, along with another function and with a constructor und the destructor. All other member functions of TInt are exported, I can see them using the dependency walker, I can use them from other projects. This also happens in a similar way with one other class.

I then compared the debug dll and the release dll using the dependency walker and winmerge. They are almost identical, just that the release dll is missing a few functions (about 3 %).

I have no idea what is wrong. I know that I do not have a lot information (the whole information is much too big and I yet could not find a simple example that does not work) and to me all sounds a little bit weird. But perhaps anyone out there once had the same problem. I appreciate every idea very much.

Thank you!

Was it helpful?

Solution

If it works for debug, but not release, then you need to identify what is different. My first guess would be that a #define macro or an equivalent /D macro us not getting defined or is getting defined wrongly.

Maybe DllExpImpM or maybe something else.

If not a macro, then what else changes between builds?

OTHER TIPS

Here are some things I found when I ran into this.

I had the same issue, but taking off the /GL parameter didn't make any difference.

My first test was creating a very simple funcion - void test () - and trying to export it. That didn't work until I got rid of the whole output directory (x64 in my case) and rebuilt it all. It would guess that some intermediate file was messing my compilation, anyway, I didn't investigate it further.

But there was still one function that wouldn't be exported. I took some time to realize the declaration in the .h file wasn't matching exatly the signature in the .cpp file! I was missing a parameter in the .h file... I don't know why it was even compiling, anyway, fixing that allowed the function to be exported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top