如何获取msvc所需的运行时库的位置 [英] How to get location of needed runtime libraries for msvc

查看:431
本文介绍了如何获取msvc所需的运行时库的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义包装CMake,其中执行配置,编译和创建distrib为各种平台(win32,SunOS等)和不同的编译器。我需要分配所有需要的运行时库(libgcc_s.so,libstdc ++,所以对于* nix像操作系统msvcr90.dll,msvcp100.dll为win32)。例如,gcc有机制,它允许获取这些库的完整名称:

 #获取libgcc_s的默认编译器位置
bash-3.2 $ g ++ -print-file-name = libgcc_s.so
/usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/../../。 4.5.3 -print文件名= ++的libstdc所以
/ U - 定制编译
的bash-3.2 $ G ++的libstdc ++的./libgcc_s.so

#获取地点/gccbuild/installed/gcc-4.5.3/lib/gcc/sparc-sun-solaris2.10/4.5.3/../../../libstdc++.so



所以我需要类似的机制为msvc(2008,2010),这是可能吗? (它可以是给定编译器的环境变量,或注册表值,或smth else)。

解决方案

您可以使用 InstallRequiredSystemLibraries cmake的模块。了解CMake的,这将增加MSVC的DLL(和舱单),以



作为一种替代方法,你可以编写自己的小cmake代码,它检查注册表中已安装的Visual Studio版本,并找到vcredist。然后,您可以将vcredist包添加到您自己的发行版中,并在您自己的安装程序中安装它的安装。



像下面将搜索vcredist_2010,并把它添加到NSIS安装程序:

 如果(CMAKE_CL_64)
组( CMAKE_MSVC_ARCH AMD64)
,否则(CMAKE_CL_64)
组(CMAKE_MSVC_ARCH 86)
ENDIF(CMAKE_CL_64)

#尝试并找到vcredist_XX.exe,通常这是在WindowsSDK文件夹。
如果(MSVC10)
find_program(MSVC_REDIST名字VC / vcredist _ $ {} CMAKE_MSVC_ARCH的.exe
PATHS
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\\ \\Microsoft SDKs\\Windows\\v7.1; InstallationFolder] /的Redist /

get_filename_component(vcredist_name$ {} MSVC_REDISTNAME)
ENDIF(MSVC10)

#如果我们找到一个vcredist包,我们只需将它添加到
#installation-folder并运行它与NSIS。
如果(vcredist_name)
消息(STATUS添加$ {vcredist_name}安装)
安装(程序$ {MSVC_REDIST}组分体系目标纸槽)
#添加/ ●为使vcredist安装无声
组(CPACK_NSIS_EXTRA_INSTALL_COMMANDSExecWait'\\\$ INSTDIR\\\\bin\\\\ $ {} vcredist_name \\\ \\\/ q')
endif(vcredist_name)


I have custom wrapper over CMake, which perform configuring, compilation, and creating distrib for various platforms (win32, SunOS and so on) and different compilers. I need to put into distrib all needed runtime libraries (libgcc_s.so, libstdc++.so for *nix like OS. msvcr90.dll, msvcp100.dll for win32). For example, gcc has mechanism, which allows to get full names of these libraries:

# get location of libgcc_s of default compiler
bash-3.2$ g++ -print-file-name=libgcc_s.so
/usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/../../../libgcc_s.so

# get location of libstdc++ of custom compiler
bash-3.2$ g++-4.5.3 -print-file-name=libstdc++.so
/u/gccbuild/installed/gcc-4.5.3/lib/gcc/sparc-sun-solaris2.10/4.5.3/../../../libstdc++.so

So i need similar mechanism for msvc (2008, 2010), is this possible? (It can be environment variable for given compiler, or registry value, or smth else). Or maybe there is some CMake mechanism for obtaining such information.

解决方案

You could use the InstallRequiredSystemLibraries cmake-module. for CMake which will add the msvc dlls (and manifests) to your cmake-install target.

As an alternative, you could write your own little cmake code which checks the registry for installed visual studio versions and finds the vcredist. You could then add the vcredist package to your own distribution and "slipstream" its installation in your own installer.

E.g. something like the following will search for vcredist_2010 and add it to the NSIS installer:

if(CMAKE_CL_64)
     set(CMAKE_MSVC_ARCH amd64)
   else(CMAKE_CL_64)
     set(CMAKE_MSVC_ARCH x86)
endif(CMAKE_CL_64)

# Try and find the vcredist_XX.exe, normally this is in the WindowsSDK folder.
if( MSVC10 )
    find_program(MSVC_REDIST NAMES VC/vcredist_${CMAKE_MSVC_ARCH}.exe
        PATHS
        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.1;InstallationFolder]/Redist/"               
        )
        get_filename_component(vcredist_name "${MSVC_REDIST}" NAME)
endif( MSVC10 )

# If we found a vcredist-package, we add it simply to the 
# installation-folder and run it with NSis.
if( vcredist_name )
    message( STATUS "    Adding " ${vcredist_name} " to Install" )
    install(PROGRAMS ${MSVC_REDIST} COMPONENT System DESTINATION bin)
    # Add /q to make the vcredist install silent
    set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '\\\"$INSTDIR\\\\bin\\\\${vcredist_name}\\\" /q'" )
endif( vcredist_name )

这篇关于如何获取msvc所需的运行时库的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆