Skip to content

Instantly share code, notes, and snippets.

@elieux
Last active April 2, 2017 14:56
Show Gist options
  • Save elieux/1ebd7cd1599648c74ad4 to your computer and use it in GitHub Desktop.
Save elieux/1ebd7cd1599648c74ad4 to your computer and use it in GitHub Desktop.
DLL troubles
#include <stdio.h>
extern const int answer;
extern __declspec(dllexport) void print42() {
printf("Hello %d.\n", answer);
}
__declspec(dllexport) const int answer = 42;
#include <stdio.h>
__declspec(dllimport) void print42();
__declspec(dllimport) const int answer;
int main() {
printf("Hello %d. ", answer);
print42();
return 0;
}
all: main.exe
foo.o: foo.c
gcc -c foo.c -o foo.o
libfoo.a: foo.o
ar sr libfoo.a foo.o
bar.o: bar.c
gcc -c bar.c -o bar.o
libbar.dll: bar.o libfoo.a
gcc -shared -o libbar.dll -Wl,--out-implib,libbar.dll.a bar.o -L. -lfoo
main.exe: main.c libbar.dll
gcc -o main.exe main.c -L. -lbar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment