How do I Create files needed to build and use DLLs under Linux?

You need to use command called dlltool. It create files needed to build and use DLLs. dlltool reads its inputs, which can come from the -d and -b options as well as object files specified on the command line. It then processes these inputs and if the -e option has been specified it creates an exports file. If the -l option has been specified it creates a library file and if the -z option has been specified it creates a def file. Any or all of the -e, -l and -z options can be present in one invocation of dlltool.

ADVERTISEMENTS

Here is an example of creating a DLL from a source file dll.c:

$ gcc -c dll.c
$ dlltool -e exports.o -l dll.lib dll.o
$ gcc dll.o exports.o -o dll.dll

Where,

  • -c : Specifies that when dlltool is creating the exports and library files it should omit the “.idata5” section. This is for compatibility with certain operating systems.
  • -e: Specifies the name of the export file to be created by dlltool.
  • -l : Specifies the name of the library file to be created by dlltool.

Creating a program (from an object file called program.o) that uses that DLL:

$ gcc program.o dll.lib -o program

Read the man page of dlltool for more information.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.