gpt4 book ai didi

c++ - 使用 Visual C++ 编译器 (msvc) 从 CLion 终端构建 C/C++ Maven NAR 项目 : Cannot deduce version number

转载 作者:行者123 更新时间:2023-11-28 02:14:11 25 4
gpt4 key购买 nike

我有一个非常简单的 C++ Maven NAR 项目,我想从 CLion 的终端编译它。这是我项目的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>me.app.sample</groupId>
<artifactId>app-sample</artifactId>
<version>1.0</version>
<packaging>nar</packaging>

<build>
<defaultGoal>integration-test</defaultGoal>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0</version>
<extensions>true</extensions>
<configuration>
<libraries>
<library>
<type>executable</type>
<run>true</run>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
</project>

一个简单的 main.cpp:

#include <iostream>
using namespace std;
int main() {
cout << "Hello world" << endl;
return 0;
}

这个目录结构:

directory structure C/C++ Maven NAR project

如果我使用“开发人员命令提示符”,我可以编译它。

[INFO] -----------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------

使用CLion的终端(ALT+F12)构建项目时出现问题:

E:\...app-sample>mvn compile
...
[INFO] Using AOL: x86-Windows-msvc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal com.github.maven-nar:nar-maven-plugin:3.0.0:nar-validate (default-nar-validate) on project app-sample: Cannot deduce version number from: -> [Help 1]
...

最佳答案

Cannot deduce version number from: ->

NAR 尝试对 link.exe 进行系统调用和/或 cl.exe (如果我没记错的话)带有类似 /version 的标志,以便它可以确定 MSVS 的版本,以便它可以以正确的方式为该版本传递参数。这是必要的,因为在命令行语法方面,不同版本的 MSVS 不向后兼容。

但是,如果未找到有问题的可执行文件,则该命令不会在标准输出(同样是 IIRC)上输出任何内容,从而为版本输出生成一个空字符串,无法解析。

如果能够改进此错误消息使其更加清晰,那当然是件好事。同时,您可以尝试使用 mvn -X 运行调用 Debug模式,这将从 Maven 发出更多很多输出,包括更多来自 NAR 的输出。

无论如何,问题的症结在于 CLion CLI 环境(即:将哪些变量设置为什么)必须与开发人员命令提示符的 CLI 环境不同。您可以尝试使用 set列出每个变量,然后比较输出。

要解决此问题,您可能需要:A) 在您的 CLion 环境中进行一些调整;或 B) 通过打补丁向 NAR 插件传授有关 CLion 和/或您的 MSVS 配置的信息。

如果您走 (B) 的路线,请随时提交 PR!无论哪种方式,将有关 CLion 的内容添加到 NAR wiki会很棒。

关于c++ - 使用 Visual C++ 编译器 (msvc) 从 CLion 终端构建 C/C++ Maven NAR 项目 : Cannot deduce version number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34549004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com