I have some simple implementation of LinkedList in file list
.
To crate library out of it I'm using cmake, my CMakelists.txt looks like that:
cmake_minimum_required(VERSION 2.6)
project(LinkedList)
set(CMAKE_CXX_FLAGS "-o -Wall")
include_directories(${LinkedList_SOURCE_DIR})
link_directories(${LinkedList_BINARY_DIR})
add_executable(list list.c)
add_library(listStatic STATIC list.c)
add_library(listShared SHARED list.c)
Everything works fine. But now it comes to use my library in other programs.
As far as I know listShared.h
is required to use this library in my program and listStatic.h
for static library.
Is there a way to automatically generate header file in CMake, so I can #include
those libraries in other programs?
Or I just don't understand how it all works?
There is no need for specific headers for static and dynamic libraries. You have to provide only one header list.h
which can be used for both purposes. It contains a list of all functions and structures declarations you use in list.c
and which should be usable by other programs, too.
To create and use either type of libraries, you have to change the parameters for the compiler respectively the linker. In CMake this is done by passing add_library
the key word STATIC
or SHARED
.