7

I am trying to compile a c++ program on windows using GCC and a makefile.

I am getting the following error

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)); }

I read that any file that includes on GCC needs the -lm linker flag. So I have added this to my makefile, but it did not rectify the problem...

Here is my 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)
Scorb
  • 1,654
  • 13
  • 70
  • 144

1 Answers1

14

This is a bug in MinGW, haven't found a fixed but using -D__NO_INLINE__ or editing math.h _hypot to hypot solved the issue, not the right fix but worked.

Other possible issue: You might have multiple MinGW versions installed, verify you're using the right one

Marware
  • 461
  • 7
  • 17
  • 2
    linking to [this](http://stackoverflow.com/questions/29450016/o1-2-3-with-std-c1y-11-98-if-cmath-is-included-im-getting-error-hypo), since it contains an answer from a MinGW contributor. He suggests editing math.h or including the option `-std=gnu++`... to make use of the c++ library "without suppression of GNU extensions," particularly avoiding the use of `__STRICT_ANSI__`. – foszter Apr 14 '16 at 17:04