Using CMake to generate dynamic link libraries based on static libraries

Source: Internet
Author: User

In the process of software development, it is sometimes necessary to generate dynamic library files based on static libraries.

When LD executes, the default will filter out unused functions in the static library, causing the generated dynamic library file to not contain all functions. So you need to configure the LD option--whole-archive.

Libsdk_api.a

SET (Src_sdk_api sdk_api.c)
add_library (Sdk_api STATIC ${src_sdk_api})

Libsdk_dev.a

SET (Src_sdk_dev sdk_dev.c)
add_library (Sdk_dev STATIC ${src_sdk_dev})

Libsdk_sys.a

SET (Src_sdk_sys sdk_memory.c)
add_library (Sdk_sys STATIC ${src_sdk_sys})

Libsdk.so

Add_subdirectory (API)
add_subdirectory (Dev)
add_subdirectory (SYS)
SET (src_sdk sdk_main.c) # Generating a dynamic library requires at least one source file
add_library (SDK SHARED ${src_sdk})


target_link_libraries (SDK 
 "-wl,--whole-archive" # The following libraries use the--whole-archive option
 sdk_api
 sdk_dev 
sdk_sys 
"-wl,--no-whole-archive")  # The following libraries do not use the--whole-archive option


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.