c++ - Static linking using cmake -


i tried static linking libstdc++-6 , libgcc_s_seh-1.i'm using clion use cmake. i'm using sfml it's not necessary it's dynamically linked.

thanks

cmake_minimum_required(version 2.8.4) project(game_project) set(executable_name "game_project")  # enable debug symbols default if(cmake_build_type strequal "")     set(cmake_build_type debug) else()     set(cmake_cxx_flags "${cmake_cxx_flags} -mwindows") endif() # (you can set on command line: -d cmake_build_type=release)   set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11 -s")  set(build_shared_libs off) set(cmake_exe_linker_flags "-static -static-libgcc -static-libstdc++")  set(cmake_module_path "${cmake_source_dir}/sfml-2.2/cmake/modules/" ${cmake_module_path})  set(cmake_source_dir src) file(glob_recurse srcs src/*.cpp)  #find version 2.x of sfml #see findsfml.cmake file additional details , instructions set(sfml_root "sfml-2.2") find_package(sfml 2 required system window graphics network audio)  include_directories(${cmake_source_dir} include)  add_executable(${executable_name} ${srcs})  if(sfml_found)     include_directories(${sfml_include_dir})     target_link_libraries(${executable_name} ${sfml_libraries})     target_link_libraries(${executable_name} ${sfml_dependencies}) endif()  install(targets ${executable_name} destination bin) 

if link dynamically against sfml, in turn links dynamically against libstdc++, application still require so/dll files libstdc++ because of sfml.

think of sfml.dll separate executable. executable has dynamic runtime dependency on libstdc++. cannot rid of that, because sfml has been linked , there no way have point part of libstdc++ statically linked executable instead.

the way rid of dependency make sure components link statically against library in linking phase.

the important thing note here static libraries of no concern this. static libraries never pass through linker (think of them bunch of packed object files), top-level executable or dynamic library pulling them in determines how link against standard library.

so if build sfml static library instead pulled in executable, configured statically link against libstdc++, problem disappear well.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -