native-maven-plugin error with msvc compiler “The command line is too long.”

核能气质少年 提交于 2019-12-14 02:47:19

问题


I'm trying to build a cpp lib via maven using native-mvn-plugin. However, during the linking part, i'm encountering an error saying "The command line is too long"

As for the configuration, im having this:

<envFactoryName>org.codehaus.mojo.natives.msvc.MSVC2008x86EnvFactory</envFactoryName>
<compilerProvider>msvc</compilerProvider>
<compilerStartOptions>
    <compilerStartOption> /GL /EHsc </compilerStartOption>
</compilerStartOptions>

And for the linkerStartOptions, i have this:

<linkerStartOptions>
    <linkerStartOption>-g -Fo -lstdc</linkerStartOption>
</linkerStartOptions>

Would be glad if somebody can help me.


回答1:


I would really discourage the use of the maven native plugin, I had a lot of trouble configuring it, and I don't know if it is maintained as the main page says it was last published on 2011-03-09. What I did to handle the problem of building a C++ library with maven was to use the maven-exec plugin. I load the msbuild tool by calling:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"

from the command line. After that, msbuild will be available in your scope.

These are the contents of my pom file :

<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <executable>msbuild</executable>
        <sourceRoot>${basedir}/Library/</sourceRoot>
    </configuration>
    <executions>
        <execution>
            <id>clean</id>
            <phase>clean</phase>
            <configuration>
                <arguments>
                    <argument>${basedir}/Library/Library.vcxproj</argument>
                    <argument>/p:Configuration=Release</argument>
                    <argument>/p:Platform=x64</argument>
                    <argument>/t:Clean</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
                </goals>
            </execution>
        <execution>
            <id>build</id>
            <phase>compile</phase>
            <configuration>
                <arguments>
                    <argument>${basedir}/Library/Library.vcxproj</argument>
                    <argument>/p:Configuration=Release</argument>
                    <argument>/p:Platform=x64</argument>
                    <argument>/t:Build</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

That way the configuration will make that the project responds to both clean and compile goals. You can go even further and use the assembly plugin to pack your library and make it install the library in the local repository so it can be added as a dependency in other projects.



来源:https://stackoverflow.com/questions/17652649/native-maven-plugin-error-with-msvc-compiler-the-command-line-is-too-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!