Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to make standalone program with cmake

My program uses giblib and Imlib2 library and it is built with cmake.

It works perfectly in my computer but not in other's.

I guess the reason is I installed every library what my program needs but other's doesn't.

My goal is making standalone program. (don't need to install any other library addtionally)

What should I add in cmake file?


projectDef.cmake source code

file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    X11/[^.]*.cpp
    X11/[^.]*.h
    X11/[^.]*.cmake
    )

SOURCE_GROUP(X11 FILES ${PLATFORM})

add_definitions(
)

set (SOURCES
    ${SOURCES}
    ${PLATFORM}
    )

add_x11_plugin(${PROJECT_NAME} SOURCES)

target_link_libraries(${PROJECT_NAME}
    ${PLUGIN_INTERNAL_DEPS}
    )

include_directories(/usr/include/giblib)
include_directories(/usr/include/X11)

target_link_libraries(MyProject X11)
target_link_libraries(MyProject Imlib2)
target_link_libraries(MyProject giblib)

CMakeList.txt source code

cmake_minimum_required (VERSION 2.6)
set (CMAKE_BACKWARDS_COMPATIBILITY 2.6)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")

Project(${PLUGIN_NAME})

file (GLOB GENERAL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    [^.]*.cpp
    [^.]*.h
    [^.]*.cmake
    )

include_directories(${PLUGIN_INCLUDE_DIRS})


SET_SOURCE_FILES_PROPERTIES(
    ${GENERATED}
    PROPERTIES
        GENERATED 1
    )

SOURCE_GROUP(Generated FILES
    ${GENERATED}
    )

SET( SOURCES
    ${GENERAL}
    ${GENERATED}
    )

include_platform()

like image 277
Oz6848 Avatar asked Oct 24 '22 02:10

Oz6848


1 Answers

Try starting with this options in your root CMakeLists.txt:

set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")

BUILD_SHARED_LIBS is only needed if your project has its own libraries (add_library).

With the -static linker flag, you need static libs for ALL your additional libraries too! One common problem when static linking is to avoid circular dependencies.

like image 124
Lars Avatar answered Oct 27 '22 09:10

Lars