简体   繁体   中英

Building C/C++ Maven NAR project from CLion terminal using Visual C++ compiler (msvc): Cannot deduce version number

I have a very simple C++ Maven NAR project and I want to compile it from CLion's terminal. This is my project's 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>

A simple main.cpp:

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

And this directory structure:

目录结构C / C ++ Maven NAR项目

I can compile it if I use the "Developer Command Prompt".

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

The problem arises when using CLion's terminal (ALT+F12) for building the project:

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 tries to make a system call to link.exe and/or cl.exe (if I recall correctly) with a flag like /version , so that it can determine the version of MSVS, so that it can pass arguments in the correct way for that version. This is necessary because different versions of MSVS are not backwards compatible when it comes to the command line syntax.

However, if the executable in question is not found, the command spits out nothing on stdout (again, IIRC), producing an empty string for the version output, which cannot be parsed.

It would certainly be nice to improve this error message to be more clear. In the meantime, you can try running with mvn -X to invoke debug mode, which will emit a lot more output from Maven, including a bunch more from NAR.

Anyway, the crux of the issue is that the CLion CLI environment (ie: which variables are set to what) must differ from the CLI environment of your Developer Command Prompt. You could try using set to list variables in each, then diff the outputs.

To fix this, you will probably need to either: A) tweak something in your CLion environment; or B) teach the NAR plugin about CLion and/or your MSVS configuration by patching it.

If you go the route of (B), feel free to submit a PR! And either way, adding something about CLion to the NAR wiki would be great.

It looks like someone don't like the Edit I put in @ctrueden answer https://stackoverflow.com/review/suggested-edits/10770206 , so I will post the answer here. First I recommend reading @ctrueden answer. This is a continuation of his answer.

For (A) (tweak something in your CLion environment), you will need to go to the Settings Panel and select Tools > Terminal, now you will have to configure the shell path as follows (this will work for Visual Studio 2012):

cmd.exe /k "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"

I am using Visual Studio 2012 and I obtained this from the Properties of the Developer Command Prompt . I assume this same step could be used with other versions of Visual Studio.

vs2012开发人员命令提示符的属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM