Skip to content

Commit

Permalink
Added Readme.md and license. Updated Makefile so that it creates the
Browse files Browse the repository at this point in the history
required output directories. Added resource file for executable.
  • Loading branch information
MartinPayne committed Nov 10, 2017
1 parent 7723aaa commit 422ec40
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 14 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Ignore compiled binaries
/bin/
/lib/
/obj/
*.exe
*.dll
*.a
24 changes: 24 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
62 changes: 52 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
# This Makefile will build a DLL and an application using the DLL.
# This Makefile will build a DLL and an application which makes use of the DLL.

all: AddLib.dll AddTest.exe
# Object files to create for the executable
DLL_OBJS = obj/add.o obj/dllres.o
EXE_OBJS = obj/addtest.o obj/exeres.o

AddLib.dll: include/add.h
gcc -O3 -std=c99 -D ADD_EXPORTS -Wall -I.\include -c src/add.c -o obj/add.o
windres -i res/resource.rc -o obj/resource.o
gcc -o AddLib.dll obj/add.o obj/resource.o -shared -s -Wl,--subsystem,windows,--out-implib,libaddlib.a
# Warnings to be raised by the C compiler
WARNS = -Wall

AddTest.exe: include/add.h AddLib.dll
gcc -O3 -std=c99 -Wall -I.\include -c src/addtest.c -o obj/addtest.o
gcc -o AddTest.exe obj/addtest.o -s -L. -lAddLib
# Names of tools to use when building
CC = gcc
RC = windres
EXE = AddTest.exe
DLL = AddLib.dll

# Compiler flags
EXE_CFLAGS = -O2 -std=c99 ${WARNS} -Iinclude
DLL_CFLAGS = ${EXE_CFLAGS} -D ADD_EXPORTS

# Linker flags
DLL_LDFLAGS = -shared -s -Wl,--subsystem,windows,--out-implib,lib/libaddlib.a
EXE_LDFLAGS = -Llib -laddlib -s -Wl,--subsystem,console

.PHONY: all clean

# Build DLL and executable by default
all: bin/${DLL} bin/${EXE}

# Delete all build output
clean:
del obj\*.o *.exe *.dll *.a
if exist bin\* del /q bin\*
if exist lib\* del /q lib\*
if exist obj\* del /q obj\*

# Create build output directories if they don't exist
bin lib obj:
@if not exist "$@" mkdir "$@"

# Compile object files for DLL
obj/add.o: src/add.c include/add.h | obj
${CC} ${DLL_CFLAGS} -c "$<" -o "$@"

# Compile object files for executable
obj/addtest.o: src/addtest.c include/add.h | obj
${CC} ${EXE_CFLAGS} -c "$<" -o "$@"

# Build the resource files
obj/%.o: res/%.rc | obj
${RC} -Iinclude -Ires -i "$<" -o "$@"

# Build the DLL
bin/${DLL}: ${DLL_OBJS} | bin lib
${CC} -o "$@" ${DLL_OBJS} ${DLL_LDFLAGS}

# Buld the executable
bin/${EXE}: ${EXE_OBJS} | bin
${CC} -o "$@" ${EXE_OBJS} ${EXE_LDFLAGS}
47 changes: 47 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# MinGW DLL Example

## Table of Contents

- [Introduction](#introduction)
- [Terms of Use](#terms-of-use)
- [Problems?](#problems)
- [Changelog](#changelog)

## Introduction

This is an example Win32 DLL and console application. It is intended to demonstrate how to build DLLs using MinGW, and
utilise their functionality within a client application. It accompanies the
[Building Windows DLLs with MinGW](http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/) article.

To build the application on a Windows machine, extract the contents of this archive to a folder on your computer. Open a
command prompt, change to the directory where you extracted the files, and type "mingw32-make". The DLL and executable
should be compiled, linked, and output as "AddLib.dll" and "AddTest.exe" in the "bin" directory. The import library will
be created as "libaddlib.a" in the "lib" directory.

To build under another operating system, the Makefile will probably require some small changes. For example, under
Fedora the 32 bit C compiler and resource compiler are named "i686-w64-mingw32-gcc" and "i686-w64-mingw32-windres".
Also, your version of the make utility may be named differently--please check the documentation which came with your
MinGW packages.

## Terms of Use

Refer to "License.txt" for terms of use.

## Problems?

If you have any problems or questions, please ensure you have read this readme
file and the
[Building Windows DLLs with MinGW](http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/)
article. If you are still having trouble, you can
[get in contact](http://www.transmissionzero.co.uk/contact/).

## Changelog

2. 2013-08-26: Version 1.1
- Minor tweaks to the VERSIONINFO resource so that it uses constants rather than magic numbers.

1. 2011-04-16: Version 1.0
- First release.

Transmission Zero
2017-11-10
2 changes: 1 addition & 1 deletion res/resource.rc → res/dllres.rc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BEGIN
VALUE "FileDescription", "A library to perform addition."
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "AddLib"
VALUE "LegalCopyright", "�2013 Transmission Zero"
VALUE "LegalCopyright", "�2017 Transmission Zero"
VALUE "OriginalFilename", "AddLib.dll"
VALUE "ProductName", "Addition Library"
VALUE "ProductVersion", "1.0.0.0"
Expand Down
35 changes: 35 additions & 0 deletions res/exeres.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <windows.h>

// DLL version information.
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE
#else
FILEFLAGS 0
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "Transmission Zero"
VALUE "FileDescription", "Application which uses the Addition Library."
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "AddTest"
VALUE "LegalCopyright", "�2017 Transmission Zero"
VALUE "OriginalFilename", "AddTest.exe"
VALUE "ProductName", "Addition Test"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

0 comments on commit 422ec40

Please sign in to comment.