Skip to content

Instantly share code, notes, and snippets.

@sillykelvin
Created November 6, 2013 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sillykelvin/7332505 to your computer and use it in GitHub Desktop.
Save sillykelvin/7332505 to your computer and use it in GitHub Desktop.
A sample nmake project
#include <stdio.h>
#include "share1.h"
#include "share2.h"
#include "static.h"
int main() {
printf("hello world\n");
int a = 4;
int b = 2;
printf ("a: %d, b: %d\n", a, b);
printf("add: %d\n", add(a, b));
printf("sub: %d\n", sub(a, b));
printf("mul: %d\n", mul(a, b));
printf("div: %d\n", div(a, b));
return 0;
}
shared_library: share1.c share2.c
cl /c share1.c share2.c
link share1.obj share2.obj /dll /out:share.dll /implib:share.lib
static_library: static.c
cl /c static.c
lib static.obj /out:static.lib
all: shared_library static_library main.c
cl /c main.c
link main.obj share.lib static.lib
clean:
del /F /Q *.exe *.dll *.lib *.obj *.exp
#include "share1.h"
int add(int a, int b) {
return a + b;
}
#ifndef SHARE1_H
#define SHARE1_H
__declspec(dllexport) int add(int, int);
#endif /* SHARE1_H */
#include "share2.h"
int sub(int a, int b) {
return a - b;
}
#ifndef SHARE2_H
#define SHARE2_H
__declspec(dllexport) int sub(int, int);
#endif /* SHARE2_H */
#include "static.h"
int mul(int a, int b) {
return a * b;
}
int div(int a, int b) {
return a / b;
}
#ifndef STATIC_H
#define STATIC_H
__declspec(dllexport) int mul(int, int);
__declspec(dllexport) int div(int, int);
#endif /* STATIC_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment