How to force inclusion of an object file in a static library when linking into executable?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a C++ project that due to its directory structure is set up as a static library A , which is linked into shared library B , which is linked into executable C . (This is a cross-platform project using CMake, so on Windows we get A.lib , B.dll , and C.exe , and on Linux we get libA.a , libB.so , and C .) Library A has an init function ( A_init , defined in A/initA.cpp ), that is called from library B 's init function ( B_init , defined in B/initB.cpp ), which is called from C 's main. Thus, when linking B , A_init (and all symbols