Added GCC visibility support

develop
Petr Mrázek 2010-02-25 23:43:37 +01:00
parent 4509e275ce
commit 626d266e27
4 changed files with 12 additions and 9 deletions

@ -86,6 +86,7 @@ IF(UNIX)
add_definitions(-DUSE_CONFIG_H) add_definitions(-DUSE_CONFIG_H)
find_library(X11_LIBRARY X11) find_library(X11_LIBRARY X11)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -pedantic") SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -pedantic")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
SET(PROJECT_LIBS ${X11_LIBRARY} rt) SET(PROJECT_LIBS ${X11_LIBRARY} rt)
ELSE(UNIX) ELSE(UNIX)

@ -22,10 +22,9 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
/// TODO: add visibility for GCC?
#ifdef LINUX_BUILD #ifdef LINUX_BUILD
# ifndef DFHACK_EXPORT # ifndef DFHACK_EXPORT
# define DFHACK_EXPORT # define DFHACK_EXPORT __attribute__ ((visibility("default")))
# endif # endif
#else #else
# ifdef BUILD_DFHACK_LIB # ifdef BUILD_DFHACK_LIB

@ -38,6 +38,7 @@ LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
IF(UNIX) IF(UNIX)
add_definitions(-DLINUX_BUILD) add_definitions(-DLINUX_BUILD)
SET(PROJECT_LIBS rt) SET(PROJECT_LIBS rt)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
ADD_LIBRARY(dfconnect SHARED ${PROJECT_SRCS}) ADD_LIBRARY(dfconnect SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(dfconnect ${PROJECT_LIBS}) TARGET_LINK_LIBRARIES(dfconnect ${PROJECT_LIBS})
ELSE(UNIX) ELSE(UNIX)

@ -41,6 +41,8 @@ distribution.
#include <sys/syscall.h> #include <sys/syscall.h>
#include <signal.h> #include <signal.h>
#define DFhackCExport extern "C" __attribute__ ((visibility("default")))
// various crud // various crud
int counter = 0; int counter = 0;
int errorstate = 0; int errorstate = 0;
@ -138,7 +140,7 @@ static int (*_SDL_Init)(uint32_t flags) = 0;
static int (*_SDL_Flip)(void * some_ptr) = 0; static int (*_SDL_Flip)(void * some_ptr) = 0;
// hook - called every tick in OpenGL mode of DF // hook - called every tick in OpenGL mode of DF
extern "C" void SDL_GL_SwapBuffers(void) DFhackCExport void SDL_GL_SwapBuffers(void)
{ {
if(_SDL_GL_SwapBuffers) if(_SDL_GL_SwapBuffers)
{ {
@ -152,7 +154,7 @@ extern "C" void SDL_GL_SwapBuffers(void)
} }
// hook - called every tick in the 2D mode of DF // hook - called every tick in the 2D mode of DF
extern "C" int SDL_Flip(void * some_ptr) DFhackCExport int SDL_Flip(void * some_ptr)
{ {
if(_SDL_Flip) if(_SDL_Flip)
{ {
@ -167,7 +169,7 @@ extern "C" int SDL_Flip(void * some_ptr)
} }
// hook - called at program exit // hook - called at program exit
extern "C" void SDL_Quit(void) DFhackCExport void SDL_Quit(void)
{ {
if(!errorstate) if(!errorstate)
{ {
@ -180,7 +182,7 @@ extern "C" void SDL_Quit(void)
} }
// hook - called at program start, initialize some stuffs we'll use later // hook - called at program start, initialize some stuffs we'll use later
extern "C" int SDL_Init(uint32_t flags) DFhackCExport int SDL_Init(uint32_t flags)
{ {
// find real functions // find real functions
_SDL_GL_SwapBuffers = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_GL_SwapBuffers"); _SDL_GL_SwapBuffers = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_GL_SwapBuffers");
@ -210,7 +212,7 @@ extern "C" int SDL_Init(uint32_t flags)
static int (*_refresh)(void) = 0; static int (*_refresh)(void) = 0;
//extern NCURSES_EXPORT(int) refresh (void); //extern NCURSES_EXPORT(int) refresh (void);
extern "C" int refresh (void) DFhackCExport int refresh (void)
{ {
if(_refresh) if(_refresh)
{ {
@ -226,7 +228,7 @@ extern "C" int refresh (void)
static int (*_endwin)(void) = 0; static int (*_endwin)(void) = 0;
//extern NCURSES_EXPORT(int) endwin (void); //extern NCURSES_EXPORT(int) endwin (void);
extern "C" int endwin (void) DFhackCExport int endwin (void)
{ {
if(!errorstate) if(!errorstate)
{ {
@ -241,7 +243,7 @@ extern "C" int endwin (void)
typedef void WINDOW; typedef void WINDOW;
//extern NCURSES_EXPORT(WINDOW *) initscr (void); //extern NCURSES_EXPORT(WINDOW *) initscr (void);
static WINDOW * (*_initscr)(void) = 0; static WINDOW * (*_initscr)(void) = 0;
extern "C" WINDOW * initscr (void) DFhackCExport WINDOW * initscr (void)
{ {
// find real functions // find real functions
_refresh = (int (*)( void )) dlsym(RTLD_NEXT, "refresh"); _refresh = (int (*)( void )) dlsym(RTLD_NEXT, "refresh");