]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: forcelink.h | |
3 | // Purpose: see bellow | |
4 | // Author: Vaclav Slavik | |
5 | // Copyright: (c) 1999 Vaclav Slavik | |
6 | // Licence: wxWindows Licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /* | |
10 | ||
11 | DESCRPITON: | |
12 | ||
13 | mod_*.cpp files contain handlers for tags. These files are modules - they contain | |
14 | one wxTagModule class and it's OnInit() method is called from wxApp's init method. | |
15 | The module is called even if you only link it into the executable, so everything | |
16 | seems wonderful. | |
17 | ||
18 | The problem is that we have these modules in LIBRARY and mod_*.cpp files contain | |
19 | no method nor class which is known out of the module. So the linker won't | |
20 | link these .o/.obj files into executable because it detected that it is not used | |
21 | by the program. | |
22 | ||
23 | To workaround this I introduced set of macros FORCE_LINK_ME and FORCE_LINK. These | |
24 | macros are generic and are not limited to mod_*.cpp files. You may find them quite | |
25 | useful somewhere else... | |
26 | ||
27 | How to use them: | |
28 | let's suppose you want to always link file foo.cpp and that you have module | |
29 | always.cpp that is certainly always linked (e.g. the one with main() function | |
30 | or htmlwin.cpp in wxHtml library). | |
31 | ||
32 | Place FORCE_LINK_ME(foo) somewhere in foo.cpp and FORCE_LINK(foo) somewhere | |
33 | in always.cpp | |
34 | See mod_*.cpp and htmlwin.cpp for example :-) | |
35 | ||
36 | */ | |
37 | ||
38 | ||
39 | #ifndef __FORCELINK_H__ | |
40 | #define __FORCELINK_H__ | |
41 | ||
42 | ||
43 | ||
44 | // This must be part of the module you want to force: | |
45 | #define FORCE_LINK_ME(module_name) \ | |
46 | int _link_dummy_func_##module_name () \ | |
47 | { \ | |
48 | return 1; \ | |
49 | } | |
50 | ||
51 | ||
52 | // And this must be somewhere where it certainly will be linked: | |
53 | #define FORCE_LINK(module_name) \ | |
54 | extern int _link_dummy_func_##module_name (); \ | |
55 | static int _link_dummy_var_##module_name = \ | |
56 | _link_dummy_func_##module_name (); | |
57 | ||
58 | ||
59 | #endif // __FORCELINK_H__ |