Shared libraries and .h files

后端 未结 4 1966
自闭症患者
自闭症患者 2020-12-12 19:52

I have some doubt about how do programs use shared library.

When I build a shared library ( with -shared -fPIC switches) I make some functions available from an exte

4条回答
  •  伪装坚强ぢ
    2020-12-12 20:36

    If you use CMake to build your project, you can use

    TARGET_LINK_LIBRARIES(targetname libraryname)
    

    As in:

    TARGET_LINK_LIBRARIES(myprogram mylibrary)
    

    To create the library "mylibrary", you can use

    ADD_LIBRARY(targetname sourceslist)
    

    As in:

    ADD_LIBRARY(mylibrary ${mylibrary_SRCS})
    

    Additionally, this method is cross-platform (whereas simply passing flags to gcc is not).

提交回复
热议问题