I'm trying to do a static compile of a C++ project using CMake, but it seems to still be linking dynamically. I'm new to CMake so I'm not entirely sure of how everything works.
This is my project root directory's CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
SET(CMAKE_LINK_SEARCH_START_STATIC TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Werror")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
#project(wwest-outreach-app.out)
project(WWEST LANGUAGES CXX)
add_subdirectory(src)
add_subdirectory(test)
include_directories(include)
file(COPY data DESTINATION bin/)
/src/'s CMakeLists:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Werror -lpthread -std=c++0x -lglut")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBRARIES OFF)
SET(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
main.cc
audiofile.cc
button.cc
entity.cc
entity_group.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
pause_original_button.cc
pause_modified_button.cc
message_display.cc
play_original_chunk_button.cc
play_modified_chunk_button.cc
stop_original_button.cc
play_button_base.cc
pause_button_base.cc
scroll_right_button.cc
scroll_left_button.cc
goto_start_end_button.cc
file_load_button.cc)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
find_package(PkgConfig REQUIRED)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image>=2.0.0)
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
pkg_search_module(NFD REQUIRED sdl2)
find_package(OpenGL REQUIRED)
find_library(OpenGL REQUIRED)
#add_library(libGLU /usr/lib/x86_64-linux-gnu/libGLU.a)
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 other flags to the compiler
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
)
I added the -static flags as per answers in similar questions like CMake and Static Linking and Compiling a static executable with CMake , but now I'm getting errors:
/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libGLU.so'
if I try adding
add_library(libGLU /usr/lib/x86_64-linux-gnu/libGLU.a)
then I get
CMake Error: Cannot determine link language for target "libGLU".
CMake Error: CMake can not determine linker language for target: libGLU
Then, I put set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
after add_executable
only to get the above link language error for cmake ./
and and make[2]: *** No rule to make target 'src/CMakeFiles/libGLU.dir/build'.
for make
.
Super lost and confused. Help please?
EDIT: I updated my question and my Cmake code to reflect my efforts to fix this and to be more specific with the error I'm getting.
EDIT 2: After trying some suggestions I was given I'm now getting this error:
/usr/bin/ld: cannot find -lgtk-3
/usr/bin/ld: cannot find -lgdk-3
/usr/bin/ld: cannot find -latk-1.0
/usr/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/bin/ld: cannot find -lgtk-3
/usr/bin/ld: cannot find -lgdk-3
/usr/bin/ld: cannot find -latk-1.0
/usr/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
(.text+0x249): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
(.text+0xcf): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
(.text+0x106): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
src/CMakeFiles/WWEST.dir/build.make:1060: recipe for target 'bin/WWEST' failed
make[2]: *** [bin/WWEST] Error 1
CMakeFiles/Makefile2:85: recipe for target 'src/CMakeFiles/WWEST.dir/all' failed
make[1]: *** [src/CMakeFiles/WWEST.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2