Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: '_hypot' was not declared in this scope

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)
like image 318
Scorb Avatar asked Nov 17 '15 04:11

Scorb


1 Answers

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

like image 183
Marware Avatar answered Oct 09 '22 18:10

Marware