Shuai
Shuai

Reputation: 1133

Why I don't need the flag -lm in MinGW but in Linux I need that explicitly?

If I need to use the math library, I need to add -lm when I'm using GCC in Linux. But on Windows when I'm using GCC in MinGW-w64, I didn't use -lm and it works well.

I know the reason why it is necessary to link libm. But I don't really know why I can omit that in Windows?

Upvotes: 1

Views: 1435

Answers (2)

Steve Summit
Steve Summit

Reputation: 47952

In my opinion, it is a significant, longstanding bug in the Unix and Linux C library setup that you actually need to use -lm. I'd say you should thank MinGW for fixing this.

Upvotes: 2

user149341
user149341

Reputation:

Because, under MinGW, the math functions aren't actually defined in libm. "libm" is an empty library used as a placeholder; the math functions are actually defined in MSVCRT.DLL, which MinGW uses as its standard library.

(The validity of using the system's MSVCRT as a standard C library is debatable. Nevertheless, that's what MinGW does.)

Upvotes: 7

Related Questions