MSVC Compiler options with mojo-native in Maven
Posted
by graham.reeds
on Stack Overflow
See other posts from Stack Overflow
or by graham.reeds
Published on 2010-04-22T08:19:47Z
Indexed on
2010/04/22
8:23 UTC
Read the original article
Hit count: 1331
I'm trying to set up a test environment with Maven to build VC++ and I am way behind on this.
I have 3 source files that I builds a dll (once I get this fixed it should be a simple matter to add the unit-tests):
hook.cpp
hook.h
hook.def
This is compiled, on the command line, with the following:
C:\Develop\hook\src\main\msvc>cl -o hook.dll Hook.cpp /D HOOK_DLLEXPORT /link /DLL /DEF:"Hook.def"
Which produces the expected obj, dll, lib and exp files.
So now to get this working in Maven2 with the Mojo-native plugin.
With no options Maven w/Mojo gives me this (truncated) output:
[INFO] [native:initialize {execution: default-initialize}]
[INFO] [native:unzipinc {execution: default-unzipinc}]
[INFO] [native:javah {execution: default-javah}]
[INFO] [native:compile {execution: default-compile}]
[INFO] cmd.exe /X /C "cl -IC:\Develop\hook\src\main\msvc /FoC:\Develop\hook\targ
et\objs\Hook.obj -c C:\Develop\hook\src\main\msvc\Hook.cpp"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
Hook.cpp
[INFO] [native:link {execution: default-link}]
[INFO] cmd.exe /X /C "link.exe /out:C:\Develop\hook\target\hook.dll target\objs\
Hook.obj"
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1561: entry point must be defined
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing command line. Exit code:1561
mojo-native gives options for manipulating the compiler/linker options but gives no example of usage. No matter what I tweak in these settings I get the error of:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to configure plugin parameters for: org.codehaus.mojo:native-maven
-plugin:1.0-alpha-4
(found static expression: '-o hook.dll Hook.cpp /D HOOK_DLLEXPORT /link /DLL
/DEF:"Hook.def"' which may act as a default value).
Cause: Cannot assign configuration entry 'compilerStartOptions' to 'interface ja
va.util.List' from '-o hook.dll Hook.cpp /D HOOK_DLLEXPORT /link /DLL /DEF:"Hook
.def"', which is of type class java.lang.String
The relevant part of my pom.xml
looks like this:
<configuration>
<sources>
<source>
<directory>src/main/msvc</directory>
<includes>
<include>**/*.cpp</include>
</includes>
</source>
</sources>
<compilerProvider>msvc</compilerProvider>
<compilerExecutable>cl</compilerExecutable>
<!-- cl -o hook.dll Hook.cpp /D HOOK_DLLEXPORT /link /DLL /DEF:"Hook.def" -->
<compilerStartOptions>-o hook.dll Hook.cpp /D HOOK_DLLEXPORT /link /DLL /DEF:"Hook.def"</compilerStartOptions>
<!-- <compilerMiddleOptions></compilerMiddleOptions>
<compilerEndOptions></compilerEndOptions>
<linkerStartOptions></linkerStartOptions>
<linkerMiddleOptions></linkerMiddleOptions>
<linkerEndOptions></linkerEndOptions>
-->
</configuration>
How do I manipulate the compiler to produce a DLL like the command line version does?
Or should I give up and just use exec?
© Stack Overflow or respective owner