title: Compile Static executable with CMAKE
body: <p>I am trying to build static executable but having no success in building up. It was working fine before adding following lines:</p>
  
  <pre><code>SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
  SET(BUILD_SHARED_LIBRARIES OFF)
  SET(CMAKE_EXE_LINKER_FLAGS "-static")
  </code></pre>
  
  <p>I want to convert it into static executable. Any help or suggestions?</p>
  
  <p>Here is my cmake Code : </p>
  
  <pre><code>cmake_minimum_required(VERSION 3.5)
  
  set(CMAKE_CXX_STANDARD 11)
  
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Werror -lpthread")
  SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
  SET(BUILD_SHARED_LIBRARIES OFF)
  SET(CMAKE_EXE_LINKER_FLAGS "-static")
  
  
  add_executable(${PROJECT_NAME} MACOSX_BUNDLE
                                 main.cc
                                 audiofile.cc
                                 button.cc
                                 entity.cc
                                 entity_group.cc
                                 filter.cc
                                 splash_screen_state.cc
                                 sprite.cc
                                 signal.cc
                                 signal_chunk.cc
                                 sound_edit_state.cc
                                 splash_screen_state.cc
                                 sprite.cc
                                 state.cc
                                 state_stack.cc
                                 waveform_chunk_display.cc
                                 waveform_chunk_select_button.cc
                                 waveform_chunk_select_display.cc
                                 waveform_component_display.cc
                                 waveform_display.cc
                                 wwest_app.cc
                                 play_original_button.cc
                                 low_pass_button.cc
                                 high_pass_button.cc
                                 mid_pass_button.cc
                                 reset_button.cc
                                 play_modified_button.cc
                                 speed_up_button.cc
                                 slow_down_button.cc)
  
  find_package(PkgConfig REQUIRED)
  pkg_search_module(SDL2 REQUIRED sdl2)
  pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image&gt;=2.0.0)
  pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
  pkg_search_module(NFD REQUIRED sdl2)
  find_package(OpenGL REQUIRED)
  
  include_directories(${SDL2_INCLUDE_DIRS}
                      ${SDL2_IMAGE_INCLUDE_DIR}
                      ${SDL2_TTF_INCLUDE_DIR}
                      ${OPENGL_INCLUDE_DIRS}
                  ${NFD_INCLUDE_DIRS}
                  ${GTK3_INCLUDE_DIRS})
  
  pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
  link_directories(${GTK3_LIBRARY_DIRS})
  add_definitions(${GTK3_CFLAGS_OTHER})
  
  target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES}
                                        ${SDL2_IMAGE_LIBRARIES}
                                        ${SDL2_TTF_LIBRARIES}
                                        ${OPENGL_LIBRARIES}
                                        ${NFD_LIBRARIES} 
                                        ${GTK3_LIBRARIES} 
                                        nfd
                                        pthread)
  </code></pre>
  
  <p>I tried merging steps from the link, but not working and getting following error: </p>
  
  <blockquote>
    <p>/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libGLU.so'
    collect2: error: ld returned 1 exit status
    src/CMakeFiles/wwest-outreach-app.out.dir/build.make:774: recipe for target 'bin/wwest-outreach-app.out' failed
    make[2]: <strong>* [bin/wwest-outreach-app.out] Error 1
    CMakeFiles/Makefile2:85: recipe for target 'src/CMakeFiles/wwest-outreach-app.out.dir/all' failed
    make[1]: *</strong> [src/CMakeFiles/wwest-outreach-app.out.dir/all] Error 2
    Makefile:83: recipe for target 'all' failed
    make: *** [all] Error 2</p>
  </blockquote>
  
  <p>Here is the link that I tried following:
  <a href="https://stackoverflow.com/questions/24648357/compiling-a-static-executable-with-cmake">Compiling a static executable with CMake</a></p>
  
  <p>Note: I added following line and it compiled but not statically as I still cant open the output file (.out) on other linux machines.</p>
  
  <pre><code>set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
  </code></pre>