[CMake] CMAKE_SHARED_LIBRARY_PREFIX is blank on msvc?

Michael Wild themiwi at gmail.com
Sun Nov 15 05:56:14 EST 2009


On 15. Nov, 2009, at 1:01 , David Manura wrote:

> CMAKE_SHARED_LIBRARY_PREFIX is blank on MSVC, unlike on most platforms
> (MinGW included):
>
>  $ (cd cmake-2.8.0/Modules/Platform/ && grep -re  
> CMAKE_SHARED_LIBRARY_PREFIX .)
>  ./AIX.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")          # lib
>  ./BlueGeneL.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")          #  
> lib
>  ./Catamount.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")          #  
> lib
>  ./CYGWIN-g77.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")
>  ./CYGWIN.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "cyg")
>  ./Darwin-icc.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")
>  ./Darwin.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")
>  ./eCos.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")          # lib
>  ./Generic-SDCC-C.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "")           
> # lib
>  ./Windows-g77.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")           
> # lib
>  ./Windows-gcc.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")           
> # lib
>  ./Windows.cmake:SET(CMAKE_SHARED_LIBRARY_PREFIX "")          # lib
>
> The conflict I'm running into is as follows.  I have a scripting
> language (Lua) that loads a pluggable module "foo", which in turns
> loads and provides a scripting interface for a system library "foo".
> On most platforms, the system library is named "libfoo.so" and located
> in the system library search path, and the module is named "foo.so"
> and located in the scripting language's search path "modules" (which
> may or may not, typically not, be in the system library search path).
> Now, on Windows at least, the scripting language dynamically loads
> "modules/foo.dll", which in turns attempts to statically load the
> system library "foo.dll" (without a path name), but Windows sees that
> a "foo.dll" is already loaded and therefore returns "modules/foo.dll"
> instead, causing breakage.
>
> Now, there may be ways around this [2], but the simplest solution is
> to just rename the system library to "libfoo.dll".  CMake does that
> for MinGW, but why not MSVC?  I'd prefer not to add a prefix on the
> pluggable modules, which would be atypical.
>
> As a workaround, I may add this to a common file included in all my  
> projects:
>
>  if(MSVC)
>    set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
>  endif(MSVC)
>
> [1] http://msdn.microsoft.com/en-us/library/ms684179%28VS.85%29.aspx -
> "If lpFileName does not include a path and there is more than one
> loaded module with the same base name and extension, the function
> returns a handle to the module that was loaded first."
> [2] http://stackoverflow.com/questions/107888/is-there-a-windows-msvc-equivalent-to-the-rpath-linker-flag
>

You can also use the PREFIX target property to force a lib prefix on a  
single target

Michael



More information about the CMake mailing list