Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6110921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:34:16+00:00 2026-05-23T14:34:16+00:00

I am using Visual Studio 2010. I have read that in C++ it is

  • 0

I am using Visual Studio 2010. I have read that in C++ it is better to use <cmath> rather than <math.h>.

But in the program I am trying to write (Win32 console application, empty project) if I write:

#define _USE_MATH_DEFINES
#include <math.h>

it compiles, while if I write

#define _USE_MATH_DEFINES
#include <cmath>

it fails with

error C2065: ‘M_PI’ : undeclared identifier

Is it normal? Does it matter if I use cmath or math.h? If yes, how can I make it work with cmath?

UPDATE: if I define _USE_MATH_DEFINES in the GUI, it works. Any clue why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:34:17+00:00Added an answer on May 23, 2026 at 2:34 pm

    Interestingly I checked this on an app of mine and I got the same error.

    I spent a while checking through headers to see if there was anything undef’ing the _USE_MATH_DEFINES and found nothing.

    So I moved the

    #define _USE_MATH_DEFINES
    #include <cmath>
    

    to be the first thing in my file (I don’t use PCHs so if you are you will have to have it after the #include "stdafx.h") and suddenly it compile perfectly.

    Try moving it higher up the page. Totally unsure as to why this would cause issues though.

    Edit: Figured it out. The #include <math.h> occurs within cmath’s header guards. This means that something higher up the list of #includes is including cmath without the #define specified. math.h is specifically designed so that you can include it again with that define now changed to add M_PI etc. This is NOT the case with cmath. So you need to make sure you #define _USE_MATH_DEFINES before you include anything else. Hope that clears it up for you 🙂

    Failing that just include math.h you are using non-standard C/C++ as already pointed out 🙂

    Edit 2: Or as David points out in the comments just make yourself a constant that defines the value and you have something more portable anyway 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Visual Studio 2010, and I have a LINQ-to-SQL DBML file that
I have written a program in C# using Visual Studio 2010. At current it
I have a Setup project that I have build using Visual Studio 2010. The
I am using Visual Studio 2010 (c++), and Intellisense has stopped working. I've read
I have created my first dll using c# and visual studio 2010. I am
I'm currently using Visual Studio 2010 and have created a 'ASP.NET MVC 3 Web
I'm using MSTest in Visual Studio 2010 and have the need to restore my
I am using visual studio 2010 and believe I have a project settings issue.
I have an app in c# using Visual Studio 2010 express and realized the
I am coding in C# using Visual Studio 2010 and have a form whereby

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.