1
General / Re: Static linking under Linux
« on: May 07, 2012, 08:22:05 pm »
Ok. I have fixed it. First of all seems like
is wrong (at least on ubuntu 12.04)
Here is part of final cmakelists.txt that does work:
linking to pthread-openal libs BEFORE linking to SFML worked under ubuntu 8.04 without problems. But under ubuntu 12.04 i should link to these libs AFTER linking with SFML. Also if i link after SFML, some libs(commented out) are not needed at all on both systems(but were needed on ubuntu 8.04 in previous case)
Code: [Select]
g++ app.cpp -o app -lpthread -lX11 -lGL -lXrandr -lfreetype -lsfml-graphics -lsfml-window -lsfml-system
is wrong (at least on ubuntu 12.04)
Here is part of final cmakelists.txt that does work:
Code: [Select]
add_Executable (Holyspirit ${GAME_SOURCES})
# add an option for choosing the build type of SFML(shared or static)
set_option(SFML_STATIC_LIBRARIES TRUE BOOL "TRUE to build SFML as static libraries, FALSE to build it as shared libraries")
# Detect and add SFML
find_package(SFML 2.0 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
list(APPEND LINKS
${GNUWIN_LIBRARY} ${SFML_AUDIO_LIBRARY} ${SFML_NETWORK_LIBRARY} ${SFML_GRAPHICS_LIBRARY} ${SFML_WINDOW_LIBRARY} ${SFML_SYSTEM_LIBRARY})
endif()
#If game doesn't build try to put next IF statement before SFML detection
if (NOT WIN32 AND SFML_STATIC_LIBRARIES)
#This can be used if your distro can't find needed libraries
#find_package(OpenGL REQUIRED) ${OPENGL_gl_LIBRARY}
#find_package(Freetype REQUIRED) ${FREETYPE_LIBRARY}
#find_package(GLEW REQUIRED) ${GLEW_LIBRARY}
#find_package(JPEG REQUIRED) ${JPEG_LIBRARY}
#find_package(X11 REQUIRED) ${X11_LIBRARIES}
#find_package(OpenAL REQUIRED) ${OPENAL_LIBRARY}
#find_package(Sndfile REQUIRED) ${SNDFILE_LIBRARY}
list(APPEND LINKS
#if needed uncomment those
#pthread
#X11
#GL
Xrandr
freetype
GLEW
jpeg
sndfile
openal
)
endif()
target_link_libraries(Holyspirit ${LINKS})
linking to pthread-openal libs BEFORE linking to SFML worked under ubuntu 8.04 without problems. But under ubuntu 12.04 i should link to these libs AFTER linking with SFML. Also if i link after SFML, some libs(commented out) are not needed at all on both systems(but were needed on ubuntu 8.04 in previous case)