On Mon, Mar 18, 2013 at 12:57 PM, Michael Powell <mwpowellhtx@xxxxxxxxx> wrote: > > It's been a little while for me, I want to build a shared library and > define an "EXPORT" preprocessor symbol that is ubiquitous whether I am > including the same headers for the shared library project, or for > projects depending on the shared library. > > ... > Prior experience tells me that this is usually done in the same EXPORT > symbol, or at least that's what I've seen in projects through Visual > Studio. I've also seen examples that define an EXPORT and an IMPORT, > but then we have the trickiness needing potentially two sets of > includes. Its a little different in the GNU/GCC world. See gcc.gnu.org/wiki/Visibility and http://rcl-rs-vvg.blogspot.com/2010/02/default-gcc-visibility-is-evil.html. For shared objects, the decoration is usually export/no export. So your common header might include: #if defined(MYLIB_CXX_MSVC) # if defined MYLIB_MS_DLL_EXPORTS # define MYLIB_EXPORT __declspec(dllexport) # define MYLIB_PRIVATE # elif defined MYLIB_MS_DLL_IMPORTS # define MYLIB_EXPORT __declspec(dllimport) # define MYLIB_PRIVATE # else // Static lib # define MYLIB_EXPORT # define MYLIB_PRIVATE # endif #elif defined(MYLIB_CXX_ICC) # define MYLIB_EXPORT # define MYLIB_PRIVATE #elif defined(MYLIB_CXX_GCC) || defined(MYLIB_CXX_CLANG) # if (__GNUC__ >= 4) # define MYLIB_EXPORT __attribute__ ((visibility ("default"))) # define MYLIB_PRIVATE __attribute__ ((visibility ("hidden"))) # else # define MYLIB_EXPORT # define MYLIB_PRIVATE # endif #endif Obviously, MSVC, ICC, GCC, and Clang are compilers picked up through preprocessor definitions. A shared object will also make everything visible by default (IIRC). Everything includes shared libraries your shared object links against. So also look into using '-Wl,--exclude-libs,ALL'. Jeff