Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compile a .cpp source file into a .dll?

Tags:

c++

dll

How do I compile a .cpp source file into a .dll?

like image 237
Sakthivel Avatar asked May 24 '26 16:05

Sakthivel


2 Answers

There are two steps you need to follow in order to compile a dll:

  • Compile your source files to object files
  • Link your object files to a dynamic link library (DLL)

Here is one example using gcc:

  1. gcc -c source.cpp //compile sources; will output "source.o"

  2. gcc -shared -o mydll.dll source.o //add -shared to create a dll, will output "mydll.dll"

A dll file is a library file, which is composed of many object files. This means you need to compile your .cpp file then combine it with any other files you need into the .dll.

Here's a tutorial I found with a quick google: http://www.icynorth.com/development/createdlltutorial.html

EDIT A fix for the above link since it's dead now https://web.archive.org/web/20130924001807/http://icynorth.com/development/createdlltutorial.html

like image 38
samoz Avatar answered May 27 '26 05:05

samoz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!