Eine DLL Datei ist eine dynamische Bibliothek und muss mit der EXE zusammen ausgeliefert werden.
//Windows gcc -c Lib.c -o Lib.o // output = Lib.o gcc -shared Lib.o -o Lib.dll // Output is Lib.dll //Linux gcc -c -fPIC Lib.c -o Lib.o // maybe: -std=c++11 gcc Lib.o -shared -o Lib.so // output is Lib.so
Eine statische Bibliothek muss nur zum Kompilieren vorhanden sein, muss aber nicht mit der EXE ausgeliefert werden.
gcc -c Lib.c // output = Lib.o ar rcs Lib.lib Lib.o // Output is Lib.lib gcc -c main.c gcc main.o -L. -lLib g++ -c -static -o library.o file1.cpp file2.cpp ar rcs library.a library.o g++ -o ausgabe.exe main.cpp library.a
DLL Sourcecode
#include <stdio.h> __declspec(dllimport) int func(int a, float b) { printf("%d - %f", a, b); return 0; }
Program Sourcecode
#include <Windows.h> typedef int (__cdecl *FUNC)(int, float); int main() { HANDLE dll; FUNC fn; dll = LoadLibrary("MyLib.dll"); fn = (FUNC) GetProcAddress(dll, "myFunc"); int i = (*fn)(1, 1.5f); return 0; }