
# utils.platform

This module is used for some platform-related auxiliary operation interfaces

## utils.platform.gnu2mslib

- Convert mingw's libxxxdll.a to msvc's xxx.lib library

#### Function Prototype

::: tip API
```lua
gnu2mslib(outputlib: <string>, inputfile: <string>, options: <table>)
```
:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| outputlib | Required. Output .lib file path |
| inputfile | Required. Input .dll.a or .def file path |
| options | Optional. Option parameters, supports the following:<br>- `dllname` - DLL file name<br>- `arch` - Architecture (e.g. "x64") |

#### Return Value

No return value

#### Usage

This feature is particularly helpful for Fortran & C++ mixed projects, because VS does not provide the fortran compiler. You can only use MinGW's gfortran to compile the fortran part, and then link with the VS project.
Often such projects also have some other libraries provided in the vs format, so pure MinGW compilation is not possible, you can only use this function to mix compilation.

And cmake also has a similar [GNUtoMS](https://cmake.org/cmake/help/latest/prop_tgt/GNUtoMS.html).

For related issues, see: [#1181](https://github.com/xmake-io/xmake/issues/1181)

```lua
import("utils.platform.gnu2mslib")

gnu2mslib("xxx.lib", "xxx.dll.a")
gnu2mslib("xxx.lib", "xxx.def")
gnu2mslib("xxx.lib", "xxx.dll.a", {dllname = "xxx.dll", arch = "x64"})
```

Support to generate xxx.lib from def, and also support to automatically export .def from xxx.dll.a, and then generate xxx.lib

If you don’t want to automatically generate def from dll.a, but want to borrow the def generated by gnu linker, then configure it yourself through add_shflags("-Wl,--output-def,xxx.def") to generate def, and then pass in def to this interface. .

`{dllname = xxx, arch = "xxx"}` These are optional, according to your needs.

You can also directly xmake l utils.platform.gnu2mslib xxx.lib xxx.dll.a quick test verification
