Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Last active March 7, 2017 22:13
Show Gist options
  • Save ScatteredRay/357686427c7101e4edf9275b2e51defe to your computer and use it in GitHub Desktop.
Save ScatteredRay/357686427c7101e4edf9275b2e51defe to your computer and use it in GitHub Desktop.
Circular dll build
#include <stdio.h>
#include "Foo.h"
#include "Baz.h"
#undef API
#define API __declspec(dllexport)
#include "Bar.h"
void Bar::Print() {
printf("Bar\n");
}
void Bar::PrintDeps() {
Foo::Print();
Baz::Print();
}
#ifndef API
#define API __declspec(dllimport)
#endif
struct Bar {
static void API Print();
static void API PrintDeps();
};
#include <stdio.h>
#include "Foo.h"
#include "Bar.h"
#undef API
#define API __declspec(dllexport)
#include "Baz.h"
void Baz::Print() {
printf("Baz\n");
}
void Baz::PrintDeps() {
Foo::Print();
Bar::Print();
}
#ifndef API
#define API __declspec(dllimport)
#endif
struct Baz {
static void API Print();
static void API PrintDeps();
};
REM cl * /c generates .obj
REM lib * /DEF generates .exp and dynamic export .libs
REM cl * generates the .exe
REM cl * /LD generates a .dll
cl Foo.cpp /c
cl Bar.cpp /c
lib Bar.obj /DEF
cl Baz.cpp /c
lib Baz.obj /DEF
cl Foo.obj Baz.lib Bar.lib
cl /LD Baz.obj Bar.lib Foo.lib
cl /LD Bar.obj Baz.lib Foo.lib
#include <stdio.h>
#include "Bar.h"
#include "Baz.h"
#undef API
#define API __declspec(dllexport)
#include "Foo.h"
void Foo::Print() {
printf("Foo\n");
}
void Foo::PrintDeps() {
Bar::Print();
Baz::Print();
}
int main(int argc, char** argv) {
Foo::PrintDeps();
Bar::PrintDeps();
Baz::PrintDeps();
}
<
#ifndef API
#define API __declspec(dllimport)
#endif
struct Foo {
static void API Print();
static void API PrintDeps();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment