diff options
Diffstat (limited to 'tutorial/chapter-9/lib')
-rw-r--r-- | tutorial/chapter-9/lib/lib.c | 10 | ||||
-rw-r--r-- | tutorial/chapter-9/lib/lib.h | 8 | ||||
-rw-r--r-- | tutorial/chapter-9/lib/lib.qbs | 10 | ||||
-rw-r--r-- | tutorial/chapter-9/lib/lib_global.h | 25 |
4 files changed, 53 insertions, 0 deletions
diff --git a/tutorial/chapter-9/lib/lib.c b/tutorial/chapter-9/lib/lib.c new file mode 100644 index 000000000..5dcae0de3 --- /dev/null +++ b/tutorial/chapter-9/lib/lib.c @@ -0,0 +1,10 @@ +#include "lib.h" + +#ifndef CRUCIAL_DEFINE +# error CRUCIAL_DEFINE not defined +#endif + +const char *get_string() +{ + return "Hello from library"; +} diff --git a/tutorial/chapter-9/lib/lib.h b/tutorial/chapter-9/lib/lib.h new file mode 100644 index 000000000..ef39ca4a1 --- /dev/null +++ b/tutorial/chapter-9/lib/lib.h @@ -0,0 +1,8 @@ +#ifndef LIB_H +#define LIB_H + +#include "lib_global.h" + +MYLIB_EXPORT const char *get_string(); + +#endif // LIB_H diff --git a/tutorial/chapter-9/lib/lib.qbs b/tutorial/chapter-9/lib/lib.qbs new file mode 100644 index 000000000..e8cf9bdb9 --- /dev/null +++ b/tutorial/chapter-9/lib/lib.qbs @@ -0,0 +1,10 @@ +MyLibrary { + name: "mylib" + files: [ + "lib.c", + "lib.h", + ] + Depends { name: 'cpp' } + cpp.defines: ['CRUCIAL_DEFINE'] +} + diff --git a/tutorial/chapter-9/lib/lib_global.h b/tutorial/chapter-9/lib/lib_global.h new file mode 100644 index 000000000..329b62fd3 --- /dev/null +++ b/tutorial/chapter-9/lib/lib_global.h @@ -0,0 +1,25 @@ +#ifndef LIB_GLOBAL_H +#define LIB_GLOBAL_H + +#if defined(_WIN32) || defined(WIN32) +#define MY_LIB_DECL_EXPORT __declspec(dllexport) +#define MY_LIB_DECL_IMPORT __declspec(dllimport) +#else +#define MY_LIB_DECL_EXPORT __attribute__((visibility("default"))) +#define MY_LIB_DECL_IMPORT __attribute__((visibility("default"))) +#endif + +// ![0] +// lib/lib_global.h +#if defined(MYLIB_STATIC_LIBRARY) +#define MYLIB_EXPORT +#else +#if defined(MYLIB_LIBRARY) +#define MYLIB_EXPORT MY_LIB_DECL_EXPORT +#else +#define MYLIB_EXPORT MY_LIB_DECL_IMPORT +#endif +#endif +// ![0] + +#endif // LIB_GLOBAL_H |