views:

62

answers:

2

I've inherited a few C++ files and an accompanying makefile, which I'm trying to bring into VS2010 as a solution. I've created an empty project and added the appropriate C++ and header (.hpp) files for one of the makefile targets.

When I try to compile the project, however, I immediately get a large number of C2061 (syntax error identifier) errors coming from cmath regarding acosf, asinf, atanf, etc.

The error line in cmath:

#pragma once
#ifndef _CMATH_
#define _CMATH_
#include <yvals.h>

#ifdef _STD_USING
   #undef _STD_USING
     #include <math.h>
   #define _STD_USING

#else /* _STD_USING */
   #include <math.h>
#endif /* _STD_USING */

#if _GLOBAL_USING && !defined(RC_INVOKED)

_STD_BEGIN
using _CSTD acosf; using _CSTD asinf;

The top block of the relevant C++ file (though named as a .C):

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

Followed by the main() function, which doesn't call any of the trig functions directly. This has to be something really obvious, but I'm missing it. Can anyone help?

Thanks!

A: 

Are you sure it's compiling as C++? Most compilers will compile .C file as C and .cpp files as C++, compiling a C++ file with a C-compiler will probably fail.

Also, that code mixes oldstyle ('c') headers and newstyle ('c++') headers. It should be more like this (I doubt that is the error however).

#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

That's all I can see with what you've given. But most of the time when you get errors in library files of C/C++ itself, it still is code of you that's wrong somewhere, like forgetting the ; after a class statement in a header file.

KillianDS
Actually, I think most compilers will compile .C files as C++ if the file system is case sensitive. But in Windows, the file system is not case sensitive. So you might be on to something here.
Fred Larson
well, I'd test it if I had a windows install nearby :). I do know you can specify the compile as ... setting in visual studio, but I don't know how it 'guesses' the initial value (project based, file based, ...).
KillianDS
its extension based - .c or .C files compile as C, and .cpp/.CPP or any other variation is compiled as CPP files, in visual studio. Its not compiling as CPP as the author thinks, it is compiling as C. As for the mixed C/CPP header inclusions, its not a killer.
Jay Kramer
Yep, this was it. Thanks! I knew it was a stupid question, but it's great to have a quick answer :) Renaming the files to .cpp solved it.
Mike O'Malley
A: 

Its probably NOT compiling as C++ code - as you assume. I am going to ask you to right click on the file in vs2010, click properties, go to 'Configuration Properties - C/C++ - Advanced', and make sure 'Compile As' is set to 'Compile as C++ Code (/TP)'.. If not, change it to that, then recompile.. you may have to recreate your Pre-compiled Headers, but I am going to be this fixes your 'problem' ;)

Jay Kramer
Yep, this was it. Thanks! I knew it was a stupid question, but it's great to have a quick answer :)
Mike O'Malley