error: '_hypot' was not declared in this scope

error: '_hypot' was not declared in this scope

我正在尝试使用 GCC 和 makefile 在 windows 上编译一个 c++ 程序。

我收到以下错误

c:\mingw\include\math.h: In function 'float hypotf(float, float)':
c:\mingw\include\math.h:635:30: error: '_hypot' was not declared in this scope
 { return (float)(_hypot (x, y)); }

我读到 GCC 中包含的任何文件都需要 -lm 链接器标志。所以我已经将它添加到我的 makefile 中,但它并没有解决问题...

这是我的 makefile

CC := g++
CFLAGS := -std=c++0x -g -O2 -static-libgcc -static-libstdc++
LFLAGS := -lm
BIN_DIR := bin
BUILD_DIR := build
SRC_DIR := src
MAIN := MyFirstVstMain
TARGET := MyFirstVstMake
SOURCES := $(wildcard src/*.cpp)
OBJECTS := $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)

$(BIN_DIR)/$(TARGET): CREATE_DIRS $(BUILD_DIR)/$(MAIN).o $(OBJECTS) 
    $(CC) $(OBJECTS) $(CFLAGS) -o $@ $(LFLAGS)

$(BUILD_DIR)/$(MAIN).o: $(SRC_DIR)/MyFirstVstMain.cpp
    $(CC) $(CFLAGS) -c -o $@ $< $(LFLAGS)

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h
    $(CC) $(CFLAGS) -c -o $@ $< $(LFLAGS)

CREATE_DIRS: 
    if not exist $(BIN_DIR) mkdir $(BIN_DIR)
    if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)

CLEAN:
    if exist $(BUILD_DIR) rmdir /Q /S $(BUILD_DIR)

这是 MinGW 中的一个错误,尚未找到修复方法,但使用 -D__NO_INLINE__ 或编辑 math.h _hypot 到 hypot 解决了问题,不是正确的修复方法,但有效。

其他可能的问题:您可能安装了多个 MinGW 版本,请确认您使用的是正确的版本