使用CMake进行静态编译无法找到-lgtk-3

时间:2017-03-03 19:49:47

标签: c++ cmake static-libraries

我试图使用CMake对C ++项目进行静态编译,但似乎仍然是动态链接。我是CMake的新手,所以我并不完全确定一切是如何运作的。

这是我的项目根目录的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 /' 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
                                      )

我在CMake and Static Linking等类似问题中按照答案添加了-static标志 和 Compiling a static executable with CMake ,但现在我收到了错误:

/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libGLU.so'

如果我尝试添加

add_library(libGLU /usr/lib/x86_64-linux-gnu/libGLU.a) 

然后我得到

CMake Error: Cannot determine link language for target "libGLU".
CMake Error: CMake can not determine linker language for target: libGLU

然后,我仅在set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)之后添加add_executable以获取cmake ./的上述链接语言错误以及make[2]: *** No rule to make target 'src/CMakeFiles/libGLU.dir/build'.的{​​{1}}。

超级迷茫和迷茫。请帮忙吗?

编辑:我更新了我的问题和我的Cmake代码,以反映我为解决这个问题所做的努力,并且更具体地说明了我遇到的错误。

编辑2:在尝试了一些建议之后我得到了我现在收到此错误:

make

0 个答案:

没有答案