[CMake] How to install a shared library on a windows system

Ryan Pavlik rpavlik at iastate.edu
Fri Jun 11 12:34:54 EDT 2010


Stephen,

The catch is that windows searches for the DLL at runtime in specific 
locations: http://msdn.microsoft.com/en-us/library/7d83bc18%28VS.80%29.aspx

This is why, when you do an install(TARGETS some-shared-lib    you need 
both the RUNTIME DESTINATION (for the dll) and the ARCHIVE DESTINATION 
(for the import library).  Generally, to avoid headaches, just put the 
DLL in the same directory as the .exe.  I tend to set things up like 
this, if I had an executable and a shared library (which is needed by 
the exe, but also might be compiled against so we should install the 
import lib and headers if requested):

install(TARGETS MyEXETarget
     RUNTIME DESTINATION bin COMPONENT runtime)

install(TARGETS MySharedLibTarget
     EXPORT mysoftware-sdk
     RUNTIME DESTINATION bin COMPONENT runtime
     ARCHIVE DESTINATION lib COMPONENT devel
     PUBLIC_HEADER DESTINATION include COMPONENT devel)

Hope this helps!

Ryan

On 06/11/2010 10:59 AM, Torri, Stephen CIV NSWCDD, W15 wrote:
> I am running into a problem with a project that installs a shared library. The files for the project are all places in the correct directories. What I am finding is that when I compile a project with uses the shared library it compiles and links correctly but the library is not found when the executable is started. Here is my CPACK configuration for the project.
>
> Q 1:  Am I missing some command that is suppose to tell windows that in my installation directory is another shared library it should use?
>
> Q 2: How can I skip the page in the NSIS wizard to not ask the user if they want to add an entry to the start menu?
>
> Q 3: As a library do I need to have a page in the NSIS wizard asking the user if they want to add the installation directory to the system PATH? I thought that only applies to executables. This project does not install any EXE files.
>
> Stephen
> ------------------------------------------
>
> #-----------------------------------------------------
>
> # CPACK
>
> #-----------------------------------------------------
>
> #-----------------------------
>
> # CPACK DESCRIPTION INFORMATION
>
> #-----------------------------
>
> SET(CPACK_PACKAGE_NAME "Project")
>
> SET(CPACK_PACKAGE_VENDOR "Work")
>
> SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Does something")
>
> SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
>
> SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
>
> SET(CPACK_PACKAGE_VERSION "0.2.0")
>
> SET(CPACK_PACKAGE_VERSION_MAJOR "0")
>
> SET(CPACK_PACKAGE_VERSION_MINOR "2")
>
> SET(CPACK_PACKAGE_VERSION_PATCH "0")
>
> SET(CPACK_PACKAGE_INSTALL_DIRECTORY "PROJECT ${CPACK_PACKAGE_VERSION}")
>
> #-----------------------------
>
> # INSTALLATION INFORMATION
>
> #-----------------------------
>
> SET(CPACK_COMPONENTS_ALL libraries headers)
>
> SET(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
>
> SET(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Dynamic library used to build programs with Project interface")
>
> SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
>
> SET(CPACK_COMPONENT_HEADERS_DESCRIPTION "C++ header files for use with Project interface")
>
> SET(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
>
> SET(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
>
> SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
>
> SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "All of the tools necessary to develop against the Project interface")
>
> #-----------------------------
>
> # INSTALLATION TYPES
>
> #-----------------------------
>
> SET(CPACK_ALL_INSTALL_TYPES Full Developer)
>
> SET(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Full Developer)
>
> SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Full Developer)
>
> IF (WIN32)
>
> SET(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\InstallIcon.bmp")
>
> SET(CPACK_NSIS_MODIFY_PATH ON)
>
> SET(CPACK_GENERATOR "NSIS")
>
> ELSE (UNIX)
>
> SET(CPACK_GENERATOR "STGZ;TGZ;RPM")
>
> ENDIF(WIN32)
>
> # Always include this last.
>
> INCLUDE(CPack)
>
>
>    


-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik at iastate.edu
http://academic.cleardefinition.com



More information about the CMake mailing list