【问题标题】:Why is compiler option /MD added when compiling static library with nar-maven?为什么使用nar-maven编译静态库时添加编译器选项/MD?
【发布时间】:2017-02-02 13:29:57
【问题描述】:

library.type 设置为static 并运行mvn -X clean compile 时,DEBUG 输出显示:

[DEBUG] 执行:Java13CommandLauncher:使用参数执行 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\cl':
''
'/c'
'/nologo'
'/EHsc'
'/DNDEBUG'
'/MD'
'/GR'
...

包括/MD,恕我直言,这里不应出现。这同样适用于编译带有test.link 设置为static 的测试可执行文件以及编译带有test.link 设置为shared 的源文件。我会使用/MD 的唯一情况是在编译链接到共享库的可执行文件时。

尽管 maven 生成了一个静态库并且测试运行没有错误,但在代码中设置 _DLL 定义会混淆我用于编译共享库的 __declspec(dllexport/dllimport) 宏,并且在静态情况下根本不需要。

谁能给我一个提示,我是否正在监督某些事情,或者这可能是一个插件错误?

该示例取自com.github.maven-nar网站的it0010-lib-static示例并对其进行了修改,并将pom文件剥离到最小:

pom.xml:

<build>
   <plugins>
      <plugin>
         <groupId>com.github.maven-nar</groupId>
         <artifactId>nar-maven-plugin</artifactId>
         <version>3.5.1</version>
         <extensions>true</extensions>
         <configuration>
            <libraries>
               <library>
                  <type>static</type>
               </library>
            </libraries>
            <linker>
               <name>msvc</name>
            </linker>
            <tests>
               <test>
                  <name>HelloWorldTest</name>
                  <link>static</link>
               </test>
            </tests>
         </configuration>
      </plugin>
   </plugins>
</build>

【问题讨论】:

    标签: c++ c visual-studio maven maven-nar-plugin


    【解决方案1】:

    /MD 和 /MT 编译器标志由我正在监督的 &lt;runtime/&gt; 属性控制,它指定生成的工件对动态 C 运行时库 (CRT) 的依赖性

    虽然为 (runtime | library.type) 属性对的不同组合生成的 lib 和测试可执行文件的 checking the runtime type dependencies 很明显:

    (static | static) : /MT used, static lib, test 和 lib 没有 CRT dep
    (静态 | 共享):使用 /MT,dyn lib、test 和 lib 没有 CRT dep,test 在 dll 上有 rt dep
    (动态|静态):使用/MD,静态库,测试和库有CRT dep
    (动态 | 共享):使用 /MD,dyn lib、test 和 lib 有 CRT dep,test 有 rt dep on dll

    备注:

    【讨论】:

      猜你喜欢
      • 2016-12-22
      • 2021-03-04
      • 1970-01-01
      • 2020-05-30
      • 2015-02-01
      • 2015-04-14
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多