I'm calling a class method in a shared library from within another shared library. Application builds fine on Linux and macOS but on Windows I receive:
exportlib.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::vector > __cdecl Algorithmslib::k_means(class std::vector > const &,unsigned __int64,unsigned __int64)" (__imp_?k_means@Algorithmslib@@QEAA?AV?$vector@VPoint@@V?$allocator@VPoint@@@std@@@std@@AEBV23@_K1@Z) referenced in function "private: void __cdecl Exportlib::setSuppPoints(void)" (?setSuppPoints@Exportlib@@AEAAXXZ) debug\exportlib.dll : fatal error LNK1120: 1 unresolved externals
I ran out of ideas what might cause the error (only on Windows!)
Shared library with exported class:
// Project file for exported shared library
// algorithmslib.pro
DEFINES += ALGORITHMSLIB_LIBRARY
Export or import according to defines:
// algorithmslib_global.h
#if defined(ALGORITHMSLIB_LIBRARY)
# define ALGORITHMSLIBSHARED_EXPORT Q_DECL_EXPORT
#else
# define ALGORITHMSLIBSHARED_EXPORT Q_DECL_IMPORT
#endif
Class declaration:
// algorithmslib.h
#include "algorithmslib_global.h"
class ALGORITHMSLIBSHARED_EXPORT Algorithmslib : public QObject
{
Q_OBJECT
public:
Algorithmslib();
std::vector<Point> k_means(const std::vector<Point>& data,
size_t k,
size_t number_of_iterations);
};
Calling k_means
method of exported class from within another shared library:
// This is a second shared library which calls the exported class of the 1st shared library
// exportlib.cpp
#include "algorithmslib.h"
void Exportlib::setSuppPoints()
{
Algorithmslib algorithmEngine;
std::vector<Point> means = algorithmEngine.k_means(data, k, number_of_iterations);
}
I'm compiling with Desktop_Qt_5_12_1_MSVC2017_64bit-Debug kit:
I renamed the shared library to something very unique, and yet the same linker error is thrown. Therefore, this issue is NOT my case