Jump to content

Weird error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
Okay so heres a problem for you guys.

After writing some code today, i tried to compile the project and got :

1>c:\ohjelmia\visual studio\vc\include\math.h(29) : error C2144: syntax error : 'int' should be preceded by ';'

1>c:\ohjelmia\visual studio\vc\include\math.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Naturally I thought that I just forgot closing bracket or semicolon.
Well apparently thats not the case, after alot of trial and error I
figured that wx widgets app.h header caused that, wich is weird
given that it compiled fine yesterday. :/

So next I thought that I had modified some of the wx sources by
accident, so I reinstalled wx widgets. That didnt help.

Before you say that I got the error source wrong, this code causes 2144 & 4430

#include <iostream>

#include <iomanip>


#include <wx/setup.h>

#include <wx/app.h> // if i remove this itll run as expected


int main( int argc, char** argv )

{

	std::cout << "test" << std::endl;


	return 0;

}


Is there something Iam missing ?
Any and all help would be appreciated. (:

edit:
After tracing it a bit heres where the math.h is included :

#ifndef _WX_MATH_H_

#define _WX_MATH_H_


#include "wx/defs.h"


#include <math.h>


And error happens in math.h :

#ifdef __cplusplus

extern "C" {

#endif


Doesnt make sense to me.

edit:
In fact it propably got nothing to do with wx widgets

#include <math.h>



int main( int argc, char** argv )

{

	return 0;

}

This does not compile for me. :/

Edited by julmuri, 28 January 2009 - 07:36 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
First of all, your include should be:
#include <math>

That said, it looks like you got a bad library. What version of MSVC++ are you using?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts

WingedPanther said:

First of all, your include should be:
#include <math>

That said, it looks like you got a bad library. What version of MSVC++ are you using?
Im using msvc 9 pro. That lib im using is latest wx widgets gui framework.
It seems its not the problem though, I dont have a clue why I can not
compile math.h. It worked fine yesterday.

edit:
Mmh dont seem have this problem with msvc 8. Guess I'll use that till I figure this out :p

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I meant I think your math.h is screwed up, not the wxWidgets library.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts

WingedPanther said:

I meant I think your math.h is screwed up, not the wxWidgets library.
Ah ofcourse, thank you.

#6
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
#ifdef __cplusplus
extern "C" {
#endif

This is a common technique to make C head file compatible with C++.

Without that, eg, when a C++ compiler sees
float sin(float r);

It will add name mangling things to the function name sin, then when you try to link with the C runtime libary, the link will not be able to find the name-mangled sin. To avoid that, C++ introduced extern "C", so you can declare it as
extern "C" float sin(float r);

and if you have many functions you don't want the name mangling things, you can put them in a extern "C" block
[code]
extern "C"{

// function prototypes goes

}
[code]

However, the C language doesnot understand extern "C", so to make both happy, macro is introduced to switch on/off that depending on whether you're using C or C++ compilers.



This, however, has nothing to do with your compiling error. I guess your compiler should have a switch to preprocess a c/cpp file. Eg, in Borland C++ and GCC, there is -E (/E) switch to generate preprocessed source file, you can analyse its output to see what's going wrong. Or if you are sure certain header file is corrupted, you can try to find a working one and replace it with the good one.

Edited by Lance, 28 January 2009 - 11:29 AM.
!


#7
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
Thanks Lance, but I got it. Finally realized that my math.h was just screwed.
No idea how that happened, but replaced it and it works now. (: