I have the following structure part of a DLL:
Utils.h
#ifdef _EXPORTS
# define UTILS_API __declspec(dllexport)
#else
# define UTILS_API __declspec(dllimport)
#endif
namespace Utils
{
static auto MyCustomComparator = [](std::shared_ptr<IMyType>& o1, std::shared_ptr<IMyType>& o2) {
// do some stuff and compare o1 and o2
};
using MyCustomPriorityQueue = std::priority_queue<std::shared_ptr<IMyType>, std::vector<std::shared_ptr<IMyType>>, decltype(MyCustomComparator)>;
UTILS_API void Foo(MyCustomPriorityQueue& myQueue);
}
Utils.cpp
#include "Utils.h"
namespace Utils
{
UTILS_API void Foo(MyCustomPriorityQueue & myQueue)
{
// implementation
}
}
These get built into a DLL that is then linked into an executable that creates a MyCustomPriorityQueue
and calls Foo
.
Tool.cpp
#include "Utils.h"
int main()
{
MyCustomPriorityQueue myQueue(MyCustomComparator);
// add things to queue
myQueue.emplace(...)
Utils::Foo(myQueue);
}
This fails to build with unresolved externals
on the Foo
API. Any ideas on what could cause this? I know that until I added the priority queue with the custom comparator as part of the exported API (it used to be internal to Foo
), it all worked, so something is definitely going wrong during linking and figuring out the type of the custom priority queue maybe?
error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl Utils::Foo(struct class std::priority_queue<class std::shared_ptr<class Utils::IMyType>,class std::vector<class std::shared_ptr<class Utils::IMyType>,class std::allocator<class std::shared_ptr<class Utils::IMyType> > >,class <lambda_19161500ece6d0a8a5b52705767e713b> const > &)" (__imp_?Foo@Utils@@$priority_queue@V?$shared_ptr@VIMyType@Utils@@@std@@V?$vector@V?$shared_ptr@VIMyType@Utils@@@std@@V?$allocator@V?$shared_ptr@VIMyType@Utils@@@std@@@2@@2@$$CBV<lambda_19161500ece6d0a8a5b52705767e713b>@@@std@@@Z)
bin\Tool.exe : fatal error LNK1120: 1 unresolved externals
Aucun commentaire:
Enregistrer un commentaire