Creating Windows DLL from C++ source files

泪湿孤枕 提交于 2019-12-10 20:49:12

问题


I have multiple source files in C++ using which i want to create a Dynamic link library.

I see this happening in linux with gcc -shared and ln

however for Windows i suppose i would have to modify source files to generate a DLL.

Is there a way to generate DLL (a file similar to *.so in linux) with provided source files. Please correct me if i m wrong, i think *so is dll for linux.

The reason for needing this is to use SWIG for calling C++ functions in python in Windows Platfrom. I am stuck at the step that requires me to generate a dll in windows.


回答1:


The exact approach depends on which compiler you are using, but the procedure is probably documented. For example, if you want to create a DLL using Visual Studio, a walkthrough is available here.




回答2:


DLL functions that are callable from outside the DLL have special macro keywords

__declspec(dllexport) void __cdecl SomeFunction(int a, int b);




回答3:


What compiler are you using? For Visual C++ the command line that creates a dynamic library from the given object files looks like this:

link -nologo -dll -out:mylib.dll -implib:mylib.lib myobj1.obj myobj2.obj ...

Also while compiling your source files into object files you will need to use the -D option to define any macros necessary to ensure that your dynamic library's symbols will be exported.



来源:https://stackoverflow.com/questions/1604200/creating-windows-dll-from-c-source-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!