You can either construct such an imported target manually in the find script, or have CMake do it for you. Exposure of the public include directories for both power.h and power_export.h via that imported target.Association of the library name of the import library (the power.lib file) via that imported target.Providing of an imported target power for consumption by the target_link_libraries call.That call is now responsible for providing all the information that was previously handled by the lines for building the library: ![]() With all the magic here happening in the find_package call. If you want to build the dll externally (which is not strictly necessary, but since that's what your question is about.), we have to modify the CMake file to something like: cmake_minimum_required(VERSION 3.5) Note that generare_export_header allows you to customize the generated export header extensively.īe sure you get the project to build and run from this baseline. POWER_EXPORT double power(double number) noexcept To make sure the function gets properly exported, change your header as follows: #ifndef POWER_H Since generated files go to the binary directory tree, we have to adjust the include directories for the library accordingly. Note the use of the generate_export_header function, which instructs CMake to generate macros for exporting functions on shared library interfaces in a portable way. ![]() Target_link_libraries(test PRIVATE power) ![]() Target_include_directories(power PUBLIC $) Your modelling of the dynamic library is incorrect, both on CMake and on the source level.Īs a starting point, try building the dll as part of the same CMake project as the consuming executable: cmake_minimum_required(VERSION 3.5)Īdd_library(power SHARED power_sources.cpp power.h)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |