0

I have a problem that in my project I have multiple libraries who all link eachother differently. And then there is one executable that links to only one library. Now there are two problems:

1) The linked libraries are not showing up in the librarian of the static libraries.

2) the librarires are all showing up at the executable.

So here is my project order

Game
|- Engine
|--Core
|---Graphics
|----Libpng
|---Platform

so Graphic links Libpng
Core links Graphics and Platform
Engine links Core
Game links Engine

Utilities is an interface library so headers only

what happens is that all Additional dependencies are at Game
The librarian of Core, Engine and Graphic containts no additional dependencies.

This is the Root CMake

cmake_minimum_required(VERSION 2.8.9)
set(CMAKE_GENERATOR "Visual Studio 14 2015")
project(EngineOnly)

set(CMAKE_SUPPRESS_REGENERATION true)

if(WIN32)
    set(PLATFORM WIN32)
else()
    set(PLATFORM LINUX)
endif (WIN32)

add_subdirectory(UTILITIES)
add_subdirectory(PLATFORM)
add_subdirectory(GRAPHICS)
add_subdirectory(CORE)
add_subdirectory(Engine)
add_subdirectory(Game)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Trinity.Game)

This is game

enter image description here

#UTILITIES LIB
include_directories(../UTILITIES/INCLUDE)
include_directories(../ENGINE/INCLUDE)

#SOURCE
file(GLOB SOURCES "SOURCE/*.cpp")
file(GLOB INCLUDES "INCLUDE/*.h")

#PROJECTNAME
set(PROJECTNAME "Trinity.Game")

#LINK ALL
add_executable(${PROJECTNAME} ${SOURCES} ${INCLUDES})

set_target_properties(${PROJECTNAME} PROPERTIES 
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/../BIN/${PLATFORM}/DEBUG" 
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/../BIN/${PLATFORM}/RELEASE" 
)

target_link_libraries(${PROJECTNAME} 
LINK_PRIVATE Trinity.Engine
)

Engine

#UTILITIES LIB
include_directories(../UTILITIES/INCLUDE)
include_directories(../CORE/INCLUDE)

#SOURCE
file(GLOB SOURCES "SOURCE/*.cpp")
file(GLOB INCLUDES "INCLUDE/*.h")

#PROJECTNAME
set(PROJECTNAME "Trinity.Engine")

#LINK ALL
add_library(${PROJECTNAME} ${SOURCES} ${INCLUDES})

set_target_properties(${PROJECTNAME} PROPERTIES 
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/LIB/${PLATFORM}/DEBUG" 
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/LIB/${PLATFORM}/RELEASE" 
)

target_link_libraries(${PROJECTNAME} 
LINK_PRIVATE Trinity.Core
)

Core

#UTILITIES LIB
include_directories(../UTILITIES/INCLUDE)
include_directories(../GRAPHICS/INCLUDE)
include_directories(../PLATFORM/INCLUDE)

#SOURCE
file(GLOB SOURCES "SOURCE/*.cpp")
file(GLOB INCLUDES "INCLUDE/*.h")

#PROJECTNAME
set(PROJECTNAME "Trinity.Core")

#LINK ALL
add_library(${PROJECTNAME} ${SOURCES} ${INCLUDES})

set_target_properties(${PROJECTNAME} PROPERTIES 
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/LIB/${PLATFORM}/DEBUG" 
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/LIB/${PLATFORM}/RELEASE" 
)

target_link_libraries(${PROJECTNAME} 
LINK_PRIVATE Trinity.Graphics
LINK_PRIVATE Trinity.Platform
)

The other look the same.

I've tried PRIVATE instead of LINK_PRIVATE but the result is the same.

PuRe
  • 179
  • 2
  • 13

1 Answers1

2

You can't link static libraries against each other and it is normal that they only showing up at the executable. Does your code not compiling?

For more information about static and dynamic libraries I suggest this article.

If you want to change the library type in cmake specify the add_lib command:

 add_library(${LIB_NAME} ${LIB_TYPE} ${SOURCE})

 # with ${LIB_TYPE} = STATIC or SHARED 

more informations about cmake

If you have more problems or my answer answer to you is not enough please specify your question.

Community
  • 1
  • 1
Soeren
  • 1,725
  • 1
  • 16
  • 30
  • Thanks, I did not know that. Yea my code was not compiled and I thought it's because of this. But it's now working as I fixed the .lib.lib from zlib and libpng. Gonna look into it whether I'm gonna use a pre/post build to link the libraries or not – PuRe Jan 25 '17 at 18:14