vc dll静态函数导出

tech2026-03-31  9

导出类

#ifdef DLL_EXPORT # define Q_DECL_EXPORT __declspec(dllexport) #elif DLL_IMPORT # define Q_DECL_EXPORT __declspec(dllimport) #else # define Q_DECL_EXPORT //使用lib静态库不用export #endif

导出类,可以直接导出

class DECL_EXPORT object {} //这个类不能被导出,可以尝试导出后在dumpbin中查看,或者调用

如果一个类的所有成员函数都是内联的,就会发现该类无法导出,添加一个cpp文件中的函数 静态函数的实现需要在头文件中

导出模板

模板函数定义和实现分离,如果报错最好不要cpp Foo.h template <typename T> struct Foo { void doSomething(T param); }; #include "Foo.cpp" // here 导出类函数模板 class Q_DECL_EXPORT Task { public: template <class T> static void New(void(*ftask)(void*,T), void* p1, T p2) { } } 模板参数限制 #include "Foo.h" // implementation of Foo's methods // explicit instantiations template class Foo<int>; template class Foo<float>; // You will only be able to use Foo with int or float // template void TestClass::templateFunction<int, int>(int, int); 类模板使用静态库lib,或者使用hpp文件(ipp文件实现),不用导出

模板在预编译期,编译成实体

最新回复(0)