Kazoom
Kazoom

Reputation: 5849

Creating Windows DLL from C++ source files

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.

Upvotes: 4

Views: 5275

Answers (3)

grigy
grigy

Reputation: 6826

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.

Upvotes: 1

patrick
patrick

Reputation: 16949

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

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

Upvotes: 2

David Seiler
David Seiler

Reputation: 9705

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.

Upvotes: 4

Related Questions