Visual Studio dll export issue for class and function template instantiations

前端 未结 3 2065
心在旅途
心在旅途 2021-01-05 13:24

I am using VS2008 in win7 and g++ 4.7 in CentOS 18. The issue is only seen on Windows when I used dynamically shared library. When I convert it static library the program li

3条回答
  •  滥情空心
    2021-01-05 14:02

    I worked out the problem. Under windows class template and function template are exported differently and there is a interesting reading on the net.

    VS compilers exports class template symbols if class template is instantiated on the translation unit (.cpp).

    However, in the case of function template, the keyword '__declspec(dllexport)' needs to be present explicitly for the symbols to be present on the dynamic library.

    e.g

    template EXPORT void HelpingRegistration( double );
    //EXPORT is defined as __declspec(dllexport) 
    

    It's just another case where VS decide to things differently. There is interesting reading here: http://www.codesynthesis.com/~boris/blog/2010/01/18/dll-export-cxx-templates/

提交回复
热议问题