I get an error when I try compiling with #include <cmath>, yes, I've tried with -lm, still does not work.

Compiler: MinGW

Compile.bat:

@echo off
echo Compiling...
g++.exe main.cpp -o "Distance.exe" -lm
pause

cmath IS in MinGw include folder. C:\MinGW\include\c++\3.4.5\cmath

Any ideas?

could you post the error that you are getting. or at least open your blinds ;)

Compiling...
In file included from main.cpp:6:
main.h:10: error: `double y1' redeclared as different kind of symbol
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/math.h:258: error: pre
vious declaration of `double y1(double)'
main.h:10: error: declaration of `double y1'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/math.h:258: error: con
flicts with previous declaration `double y1(double)'
Press any key to continue . . .

Note: I'll remove all my math functions, and i will STILL get that.

edit: I removed most of my code and i get that

Edited 6 Years Ago by fellixombc: n/a

main.h:

#include <iostream>
#include <cmath>

/* Namescapes */
using namespace std;

/* Varibles */
double x1;
double x2;
double y1;
double y2;
double answer;

main.cpp

/* 
* Copyright(c)Fellixombc 2010
*/

/* Includes */
#include "main.h"

int main() {
	/* Title */
	cout << "Fellixombc's Distance Formula Application (Geometry)\n" << "x1: ";
	
	/* Application Input/Output */
	cin >> x1;
	cout << "x2: ";
	cin >> x2;
	cout << "y1: ";
	cin >> y1;
	cout << "y2: ";
	cin >> y2;
	
	/* Calculations */
	answer = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	
	cout << answer;
	
	system("pause");
	
}

it could be that y1 is declared in the <cmath> header and since you declared them as global you are getting the error. what happens if you do this instead instead of having a main.h. I mean put all this in main.cpp

#include <iostream>
#include <cmath>

/* Namescapes */
using namespace std;

int main() {
        /* Varibles */
        double x1;
        double x2;
        double y1;
        double y2;
        double answer;
	/* Title */
	cout << "Fellixombc's Distance Formula Application (Geometry)\n" << "x1: ";
	
	/* Application Input/Output */
	cin >> x1;
	cout << "x2: ";
	cin >> x2;
	cout << "y1: ";
	cin >> y1;
	cout << "y2: ";
	cin >> y2;
	
	/* Calculations */
	answer = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	
	cout << answer;
	
	system("pause");
	
}

And yes those are common names. you should use real names for your variables.

Edited 6 Years Ago by NathanOliver: n/a

it could be that y1 is declared in the <cmath> header and since you declared them as global you are getting the error. what happens if you do this instead instead of having a main.h. I mean put all this in main.cpp

#include <iostream>
#include <cmath>

/* Namescapes */
using namespace std;

int main() {
        /* Varibles */
        double x1;
        double x2;
        double y1;
        double y2;
        double answer;
	/* Title */
	cout << "Fellixombc's Distance Formula Application (Geometry)\n" << "x1: ";
	
	/* Application Input/Output */
	cin >> x1;
	cout << "x2: ";
	cin >> x2;
	cout << "y1: ";
	cin >> y1;
	cout << "y2: ";
	cin >> y2;
	
	/* Calculations */
	answer = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	
	cout << answer;
	
	system("pause");
	
}

And yes those are common names. you should use real names for your variables.

Yeah that was it, thanks for helping!

Somebody else can probably illuminate this a little bit further, but there really is a y1 declared in math.h. It appears to be associated with an older version of the complex type(?). Seemingly, if you #define _NO_OLDNAMES before you #include <cmath> it should disregard those declarations. I couldn't tell you if this is a bad idea for any reason or not. Unless it's critical to your code it might be advantageous to just rename it (and an opportunity to make it more descriptive :) )

EDIT: Wow, the posts all cascaded over one another

Edited 6 Years Ago by jonsca: n/a

yeah i took a while to write my post and there was a couple of edits. for some reason my fingers don't want to work tonight.

This article has been dead for over six months. Start a new discussion instead.