7

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()

Oz6848
  • 319
  • 1
  • 9
  • 17
  • http://stackoverflow.com/questions/3762057/cmake-how-to-produce-binaries-as-static-as-possible ? –  Aug 18 '11 at 06:30

1 Answers1

5

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.

pooya13
  • 2,060
  • 2
  • 23
  • 29
Lars
  • 1,426
  • 10
  • 25
  • After repeat your solution, size of result .so file is not changed. I think it doesn't work correctly as you said. – Oz6848 Aug 18 '11 at 08:45
  • and at the end of 'make' result message is 'Linking CXX shared library ../../bin/Printmade2/npMyProject.so', so I don't think it is static dynamic linking. – Oz6848 Aug 18 '11 at 09:16
  • Did you try a new out-of-source build dir? BTW static libs have the suffix .a not .so... – Lars Aug 18 '11 at 11:40
  • What I want to include is in /usr/lib and I already know about suffix. – Oz6848 Aug 19 '11 at 01:59