简体   繁体   中英

Why is compiler option /MD added when compiling static library with nar-maven?

When setting library.type to static , and running mvn -X clean compile , the DEBUG output shows:

[DEBUG] Execute:Java13CommandLauncher: Executing 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\cl' with arguments:
''
'/c'
'/nologo'
'/EHsc'
'/DNDEBUG'
'/MD'
'/GR'
...

including /MD which IMHO should not be present here. The same holds for compiling a test executable with test.link set to static and for compiling source files with test.link set to shared . The only case I would use /MD is when compiling an executable linked to shared libraries.

Even though maven produces a static library and the test is running without errors, setting the _DLL define inside the code mixes up my __declspec(dllexport/dllimport) macro for compiling shared libraries and is not necessary at all in the static case.

Can anybody give me a hint whether I'm overseeing something or this might be a plugin bug?

The example is taken and modified from the it0010-lib-static example from the com.github.maven-nar web site and the pom file stripped to the minimum:

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>

The /MD and /MT compiler flags are controlled by the <runtime/> property which I was overseeing and which specifies the dependency of the produced artifacts on the dynamic C runtime libraries (CRTs)

While checking the runtime type dependencies of the produced lib and test executable for the different combinations of the (runtime | library.type) property pairs it became clear that:

(static | static) : /MT used, static lib, test and lib have no CRT dep
(static | shared) : /MT used, dyn lib, test and lib have no CRT dep, test has rt dep on dll
(dynamic | static): /MD used, static lib, test and lib have CRT dep
(dynamic | shared): /MD used, dyn lib, test and lib have CRT dep, test has rt dep on dll

Remarks:

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