How do I wite unit tests for a visual c++ project which builds a .dll without a .lib – the suggested methods of writing unit tests require a .lib


I have a project which builds a plugin .dll for another program – no .lib is produced for this, despite having several exports. Note that I have very little control over how the exports are defined in the main executable’s header.

I want to write unit tests for it, but honestly, trying to write them by calling via the small number of API calls implemented would be massively unproductive. So I thought I’d link with the generated object files as suggested in a few places.

But I can’t.

The unit test project that visual c++ helps you to create expects you to provide a .lib file. However, the build does not provide a .lib file. I’ve seen various questions submitted about similar problems over the years – and none of the answers work. They suggest if you’re not exporting anything, a .lib file won’t be generated – well, I’m definitely exporting symbols.

Another answer to a similar question says I need to have a header which does

#ifdef MYPROJECT_EXPORTS
#define MYPROJECT_API __declspec(dllexport)
#else
#define MYPROJECT_API __declspec(dllimport)
#endif

and use MYPROJECT_API in the source.

So I did that. It had absolutely no effect.

Some answers say there’s an ‘export symbols’ in the project properties – not that I can find, there isn’t (though searching project properties isn’t all that easy, so I could have missed it).

A couple of things have suggested I should use import libraries. But I don’t import any libraries.

So I’m a bit stuck.

Leave a Reply

Your email address will not be published. Required fields are marked *