错误:在此范围内未声明'_hypot'

Sco*_*ttF 7 c++ windows gcc mingw g++

我正在尝试使用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)); }
Run Code Online (Sandbox Code Playgroud)

我读到包含在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)
Run Code Online (Sandbox Code Playgroud)

Mar*_*are 14

这是MinGW中的一个错误,没有找到固定但使用-D__NO_INLINE__或编辑math.h _hypot来解决问题,而不是正确的修复但是有效.

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

  • 链接到[this](http://stackoverflow.com/questions/29450016/o1-2-3-with-std-c1y-11-98-if-cmath-is-included-im-getting-error-hypo) ,因为它包含MinGW贡献者的答案.他建议编辑math.h或包含选项`-std = gnu ++`...以利用c ++库而不抑制GNU扩展,"特别是避免使用`__STRICT_ANSI__`. (2认同)