linux c++ development-05- Use CMake to create a dynamic library

Insert image description here
Contents in outer CMakeList.txt:

cmake_minimum_required(VERSION 3.16)
PROJECT(HELLO)
ADD_SUBDIRECTORY(lib bin)

Contents of CMakeLists.txt in lib:

SET(LIBHELLO_SRC hello.cpp)
ADD_LIBRARY(hello SHARED ${
    
    LIBHELLO_SRC})

hello.h:
Insert image description here

hello.cpp:

Insert image description here
Insert image description here

ADD_LIBRARY
ADD_LIBRARY(hello SHARED ${LIBHELLO_SRC})

  • hello: is the library name, the generated name will be preceded by lib, and the final generated file is libhello.so
  • SHARED: dynamic library STATIC, static library
  • $(LIBHELLO_SRC): source file

Guess you like

Origin blog.csdn.net/FairLikeSnow/article/details/132726796