SciNim / flambeau

Nim bindings to libtorch
85 stars 3 forks source link

define NOMINMAX when compiling your program on Windows #28

Closed HugoGranstrom closed 3 years ago

HugoGranstrom commented 3 years ago

When trying to run the nn test I got this error on Windows:

C:\Users\hugog\code\nim\flambeau\vendor\libtorch\include\c10/util/C++17.h(28): fatal error C1189: #error:  Macro clash with min and max -- define NOMINMAX when compiling your program on Windows

It was solved by passing this with the compiler: -t:-DNOMINMAX Not sure where and how to define it so that it is applied to all files in Flambeau. :/

Clonkk commented 3 years ago

You need to import a file that re-export that contains {.passC:"-DNOMINMAX.}. We could reuse config.nim or create a specific file for this purpose (either is fine with me).

So for example add to flambeau.nim (and other "exporting" files)

import flambeau/config
export config

and to config.nim / a dedicated file add :

when defined(windows):
  {.passC: "-DNOMINMAX".}

THat should do the trick

HugoGranstrom commented 3 years ago

Oh right, that's true 😄

HugoGranstrom commented 3 years ago

Doing it in config.nim sounds sounds most straightforward 👍 We will probably have to add more flags in the future if we stumble upon more of these.

Clonkk commented 3 years ago

That's how I did it in nimjl : https://github.com/Clonkk/nimjl/blob/master/nimjl/config.nim

HugoGranstrom commented 3 years ago

Nice, it works like a charm now :)