3

I'm trying to build a c++ program using the allegro library for school, but I can't seem to get past a massive list of compile errors dealing with cstdint and stdint.h

Removing all the code from my files gives me a header file with just this

#pragma once
#include <allegro.h>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <fstream>

and my main file just containing

#include "Trivia.h"

and here are the errors I'm trying to deal with

1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): error C2632: 'char' followed by 'char' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(17): warning C4091: 'typedef ': ignored on left of 'signed char' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(18): error C2632: 'short' followed by 'short' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(18): warning C4091: 'typedef ': ignored on left of 'short' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): error C2632: 'int' followed by 'int' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(19): warning C4091: 'typedef ': ignored on left of 'int' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(20): error C2632: '__int64' followed by '__int64' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(20): warning C4091: 'typedef ': ignored on left of '__int64' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): error C2632: 'char' followed by 'char' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(21): warning C4091: 'typedef ': ignored on left of 'unsigned char' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): error C2632: 'short' followed by 'short' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(22): warning C4091: 'typedef ': ignored on left of 'unsigned short' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): error C2632: 'int' followed by 'int' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(23): warning C4091: 'typedef ': ignored on left of 'unsigned int' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): warning C4114: same type qualifier used more than once
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): error C2632: '__int64' followed by '__int64' is illegal
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\stdint.h(24): warning C4091: 'typedef ': ignored on left of 'unsigned __int64' when no variable is declared
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(18): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(18): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(19): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(19): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(20): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(20): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(21): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(21): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(33): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(33): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(34): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(34): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(37): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(37): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(38): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(38): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(39): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(39): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(40): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(40): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(52): error C2589: 'signed': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(52): error C2059: syntax error: '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(53): error C2589: 'unsigned': illegal token on right side of '::'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\cstdint(53): error C2059: syntax error: '::'

I can get the errors to disappear if I remove all of stdio.h, sstream and fstream but I kinda need those for my assignment.

bentup
  • 41
  • 1
  • 5
  • 3
    Unrelated to your problem, but your use or `#pragma once` indicates that the code you show is from a header file, in which case `using namespace std` is wrong and perhaps even dangerous (not that it's good in a source file either). I recommend you take some time to read [Why is “using namespace std” considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice), and really takes the time to read *all* answers. – Some programmer dude Oct 02 '17 at 23:23
  • As for your errors, what are you doing *before* the code you show us? Where do you include your header file? What are you doing there? You *really* need to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) and show us! – Some programmer dude Oct 02 '17 at 23:25
  • remove `using namespace std;` – Richard Critten Oct 02 '17 at 23:28
  • Again, what are you doing *before* `#include "Trivia.h"`? Where's the [Minimal, ***Complete***, and Verifiable Example](http://stackoverflow.com/help/mcve)? – Some programmer dude Oct 02 '17 at 23:52
  • Creating an empty C++ project, adding a Trivia.h and a Trivia.cpp and typing in exactly what's above gives these errors. – bentup Oct 03 '17 at 00:11
  • So there is *nothing* above the `#include "Trivia.h"`? Not even including the precompiled header? No comments? Really *nothing*? That single `#include` really is the ***complete*** code you try to compile? – Some programmer dude Oct 03 '17 at 00:16
  • I'm not using a precompiled header. This is it – bentup Oct 03 '17 at 00:23

2 Answers2

2
#include <stdlib.h>
#include <stdio.h>

they are C headers, you need C++ ones:

#include <cstdlib>
#include <cstdio>

EDIT:

First you have a bunch of errors from stdint.h (C header!), then from cstrint. Just a guess, but if allegro is a C library (not C++), you also need to change

#include <allegro.h>

to

extern "C"
{
    #include <allegro.h>
}
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
  • Tried this, it doesn't seem to have changed anything. Still getting the same errors. – bentup Oct 02 '17 at 23:24
  • Allegro is designed to work with C++, doing this gives me "C linkage function cannot return C++ class 'fix' errors. – bentup Oct 02 '17 at 23:42
0

Apparently I can solve the problem by including allegro.h after sstream and fstream. I don't know why this fixes the problem (and I've seen other code including allegro.h first) but at least it works.

bentup
  • 41
  • 1
  • 5