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)
3
  • Apparently a bug in MinGW: ehc.ac/p/mingw/bugs/2250 Nov 17, 2015 at 5:00
  • How can I get around this. I am using a third party library that uses math.h. Specifically the steinberg vst sdk.
    – Scorb
    Nov 17, 2015 at 5:07
  • so... how about a code sample? The makefile is irrelevant other than to show the CFLAGS
    – M.M
    Feb 2, 2016 at 22:18

1 Answer 1

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

1
  • 2
    linking to this, 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, 2016 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.