cmake -A Win64 -G “Visual Studio 16 2019“ .. 错误

cmake -A Win64 -G “Visual Studio 16 2019“ ..

cmake  -G  “Visual Studio 16 2019  Win64 “ ..

使用上面两个命令构造64位系统架构的 VS 2019  sln项目时,都会出现如下错误:

PS E:\workForVS\Micro-XRCE-DDS-Agent\build> cmake  -G "Visual Studio 16 2019"  ..
CMake Error at CMakeLists.txt:122 (project):
  Failed to run MSBuild command:

    D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe

  to get the value of VCTargetsPath:

    用于 .NET Framework 的 Microsoft (R) 生成引擎版本 16.11.2+f32259642
    版权所有(C) Microsoft Corporation。保留所有权利。

    生成启动时间为 2023/3/30/周四 15:49:23。
    节点 1 上的项目“E:\workForVS\Micro-XRCE-DDS-Agent\build\CMakeFiles\3.20.21032501-MSVC_2\VCTargetsPath.vcxproj”(默认目标)。
    D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(820,5): error : The BaseOutputPath/OutputPath property is not set for project 'VCTargetsPath.vcxproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Debug'  Platform='Win64'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [E:\workForVS\Micro-XRCE-DDS-Agent\build\CMakeFiles\3.20.21032501-MSVC_2\VCTargetsPath.vcxproj]
    已完成生成项目“E:\workForVS\Micro-XRCE-DDS-Agent\build\CMakeFiles\3.20.21032501-MSVC_2\VCTargetsPath.vcxproj”(默认目标)的操作 - 失败。

    生成失败。

    “E:\workForVS\Micro-XRCE-DDS-Agent\build\CMakeFiles\3.20.21032501-MSVC_2\VCTargetsPath.vcxproj”( 默认目标) (1) ->
    (_CheckForInvalidConfigurationAndPlatform 目标) ->
      D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(820,5): error : The BaseOutputPath/OutputPath property is not set for project 'VCTargetsPath.vcxproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Debug'  Platform='Win64'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [E:\workForVS\Micro-XRCE-DDS-Agent\build\CMakeFiles\3.20.21032501-MSVC_2\VCTargetsPath.vcxproj]

        0 个警告
        1 个错误

    已用时间 00:00:00.15


  Exit code: 1



-- Configuring incomplete, errors occurred!
See also "E:/workForVS/Micro-XRCE-DDS-Agent/build/CMakeFiles/CMakeOutput.log".

上述Visual Studio 16 2019编译错误,需要命令改为:

E:\workForVS\Micro-XRCE-DDS-Agent\build> cmake -A x64 -G "Visual Studio 16 2019"  ..

Refer: Installation — eProsima Micro XRCE-DDS 2.1.1 documentation

Visual Studio 15 2017 编译,使用如下命令:

$ cmake -G "Visual Studio 15 2017 Win64" ..
$ cmake --build .
$ cmake --build . --target install

这里64位架构使用 x64,   取代以前版本的 Win64。

# vs2019以及更新版本 已经改了
cmake -G "Visual Studio 16 2019" -A Win32
cmake -G "Visual Studio 16 2019" -A x64
cmake -G "Visual Studio 16 2019" -A ARM
cmake -G "Visual Studio 16 2019" -A ARM64

# vs2018以及以前版本 
cmake -G "Visual Studio 15 2017 Win32" 
cmake -G "Visual Studio 15 2017 Win64" 
cmake -G "Visual Studio 15 2017 ARM" 
cmake -G "Visual Studio 17 2017 ARM64" 

# https://micro-xrce-dds.docs.eprosima.com/en/latest/installation.html
$ cmake -G "Visual Studio 15 2017 Win64" ..
$ cmake --build .
$ cmake --build . --target install

DLL Export Viewer下载链接:https://www.nirsoft.net/utils/dllexp-x64.zip

<think>嗯,用户要求详细解释一条CMake命令"cmake .. -G "Visual Studio 16 2019" -A x64"。这个命令看起来是Windows平台下用于生成VS2019解决方案的典型用法。 用户提供的两个引用很有价值:[^1]展示了标准构建流程,[^2]则补充了安装路径和依赖库设置的示例。不过用户更关注命令本身的分解说明,需要把每个参数都拆解清楚。 首先从路径部分看,".."表示CMakeLists.txt在上级目录,这是标准做法。关键在生成器参数:"-G"指定的"Visual Studio 16 2019"对应VS2019的IDE版本号,这里版本号容易混淆——实际上VS2019的内部版本就是16.x系列。而"-A x64"明确要求生成64位解决方案,避免默认Win32平台带来的兼容问题。 用户可能遇到的实际问题值得深挖: - 版本不匹配很常见,比如用VS2022执行此命令会失败,需要同步更新"-G"参数 - 如果项目依赖第三方库,缺少"-D"参数定义路径会导致配置失败 - 32/64位混淆可能引发LNK2019链接错误,需检查"-A"是否与依赖库一致 考虑到用户正在学习CMake,可以引申相关问题:交叉编译设置、多配置生成器选择、find_package机制等进阶内容。这些问题能帮助ta理解更复杂的构建场景。 最后要注意术语准确性:"Visual Studio 16 2019"的官方命名必须核对,避免说成VS2016CMake文档显示其生成器名称严格遵循"Visual Studio [版本] [年份]"格式[^1]。 </think>以下是对 `cmake .. -G "Visual Studio 16 2019" -A x64` 命令的详细解析: --- ### **命令结构与含义** ```bash cmake # 调用CMake程序 .. # CMakeLists.txt的路径(上级目录) -G "Visual Studio 16 2019" # 指定生成器(Generator-A x64 # 指定目标平台架构 ``` #### **1. `..`:源码路径** - 表示 **CMakeLists.txt 文件位于当前目录的上级目录** 例如:若在 `build/` 子目录执行命令,则 `..` 指向父目录中的项目根目录。 #### **2. `-G "Visual Studio 16 2019"`:生成器选择** - **作用**:明确要求生成 **Visual Studio 2019** 的解决方案文件(`.sln` 和 `.vcxproj`) - 关键细节: - `Visual Studio 16 2019` 是CMake官方定义的生成器名称(16 对应VS2019的内部版本号)[^1] - 必须与本地安装的VS版本严格匹配(若本地为VS2022,需改用 `"Visual Studio 17 2022"`) #### **3. `-A x64`:目标平台架构** - **作用**:指定生成 **64位(x64)** 解决方案(而非默认的32位 Win32) - 典型值: - `x64`:64位应用程序 - `Win32`:32位应用程序 - `ARM`/`ARM64`:ARM架构(跨平台开发) --- ### **使用场景** 1. **Windows平台原生开发** 需生成VS2019可直接打开的解决方案,用于: - 编译C++项目 - 调试/测试代码 - 集成MSVC编译器工具链 2. **跨平台项目适配Windows** 当项目原始设计支持Linux/MacOS时,通过此命令生成Windows构建配置。 3. **64位应用构建** 明确要求64位输出(如处理大内存、高性能计算)。 --- ### **常见问题与解决方法** #### **问题1:生成器名称错误** - **报错示例**: `Could not create named generator Visual Studio 16 2019` - **原因**:本地未安装VS2019,或CMake版本过低(需≥3.15) - **解决**: ```bash # 查看本地可用生成器 cmake --help # 使用正确版本(例如VS2022) cmake -G "Visual Studio 17 2022" -A x64 .. ``` #### **问题2:架构不兼容** - **报错示例**: `LNK1112: module machine type &#39;x64&#39; conflicts with target machine type &#39;Win32&#39;` - **原因**:依赖库与 `-A x64` 指定的架构不一致 - **解决**: 1. 确保所有依赖库编译为64位 2. 清除缓存重新生成:删除 `build/` 目录后重新执行命令 #### **问题3:第三方库路径缺失** - **报错示例**: `Could NOT find Boost (missing: Boost_INCLUDE_DIR)` - **解决**:通过 `-D` 添加路径变量 ```bash cmake .. -G "Visual Studio 16 2019" -A x64 -DBoost_ROOT="C:/local/boost_1_82_0" ``` #### **问题4:多配置支持** - **现象**:默认生成Debug配置,需手动切Release - **优化命令**:生成时指定Release模式 ```bash cmake .. -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release ``` --- ### **典型工作流** ```bash # 1. 创建构建目录 mkdir build && cd build # 2. 生成VS2019解决方案(64位) cmake .. -G "Visual Studio 16 2019" -A x64 # 3. 编译Release版本 cmake --build . --config Release ``` ---
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值