C++ trying to use #ifndef and #include statements - c++

Ok, so I'm a HTML/Javascript/PHP professional, but I'm trying to learn C++. I'm still a newbie at it, and I have a C++ programming project that I have errors with.
The file that contains int main() is 'football.cpp', and I have .h and .cpp files for three classes that I have to use: Game, Team, and Date. Each instance of Team contains a vector of Games, and each Game contains a Date. Date does not contain instances of any other class.
I am trying to find a way to use #include and #ifndef statements at the tops of the files so that I don't get errors when I compile, but I haven't found a combination that works. I am not sure if there are other bugs. Here's my current #include sections, not counting other libraries:
football.cpp
#include "game.h"
#include "team.h"
#include "date.h"
team.h
#ifndef __game_h_
#define __game_h_
#endif
team.cpp
#include "team.h"
#ifndef __game_h_
#define __game_h_
#endif
game.h
#ifndef __date_h_
#define __date_h_
#endif
game.cpp
#include "game.h"
#ifndef __date_h_
#define __date_h_
#endif
date.cpp
#include "date.h"
I use Cygwin g++ compiler, and the line I use to compile it is:
g++ football.cpp team.cpp game.cpp date.cpp -o football.exe
Here are all the errors I get: (WARNING, WALL OF TEXT)
$ g++ football.cpp team.cpp game.cpp date.cpp -o football.exe
In file included from football.cpp:9:0:
game.h:15:96: error: ‘Date’ has not been declared
game.h:24:1: error: ‘Date’ does not name a type
game.h:37:1: error: ‘Date’ does not name a type
football.cpp: In function ‘int main(int, char*)’:
football.cpp:65:70: error: no matching function for call to ‘Game::Game(std::string&, std::string&, int [5], int [5], Date&)’
game.h:15:1: note: candidates are: Game::Game(std::string, std::string, const int, const int*, int)
game.h:14:1: note: Game::Game()
game.h:10:12: note: Game::Game(const Game&)
In file included from team.cpp:4:0:
team.h:24:8: error: ‘Game’ was not declared in this scope
team.h:24:12: error: template argument 1 is invalid
team.h:24:12: error: template argument 2 is invalid
team.cpp: In member function ‘float Team::getStat3()’:
team.cpp:36:26: error: request for member ‘size’ in ‘((Team*)this)->Team::games’, which is of non-class type ‘int’
team.cpp:37:21: error: invalid types ‘int[int]’ for array subscript
team.cpp:37:50: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:21: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:47: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:76: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:106: error: invalid types ‘int[int]’ for array subscript
team.cpp: In function ‘bool compare2(Team, Team)’:
team.cpp:45:39: error: request for member ‘size’ in ‘t1.Team::games’, which is of non-class type ‘const int’
team.cpp:46:39: error: request for member ‘size’ in ‘t2.Team::games’, which is of non-class type ‘const int’
team.cpp:50:17: error: request for member ‘size’ in ‘t1.Team::games’, which is of non-class type ‘const int’
team.cpp:50:35: error: request for member ‘size’ in ‘t2.Team::games’, which is of non-class type ‘const int’
team.cpp:52:24: error: request for member ‘size’ in ‘t1.Team::games’, which is of non-class type ‘const int’
team.cpp:52:43: error: request for member ‘size’ in ‘t2.Team::games’, which is of non-class type ‘const int’
team.cpp: In function ‘bool compare3(Team, Team)’:
team.cpp:62:29: error: passing ‘const Team’ as ‘this’ argument of ‘float Team::getStat3()’ discards qualifiers
team.cpp:63:29: error: passing ‘const Team’ as ‘this’ argument of ‘float Team::getStat3()’ discards qualifiers
In file included from game.cpp:5:0:
game.h:15:96: error: ‘Date’ has not been declared
game.h:24:1: error: ‘Date’ does not name a type
game.h:37:1: error: ‘Date’ does not name a type
game.cpp: In constructor ‘Game::Game()’:
game.cpp:26:3: error: ‘date’ was not declared in this scope
game.cpp:26:15: error: ‘Date’ was not declared in this scope
game.cpp: At global scope:
game.cpp:29:94: error: ‘Date’ has not been declared
game.cpp:29:1: error: prototype for ‘Game::Game(std::string, std::string, int*, int*, int)’ does not match any in class ‘Game’
game.h:10:12: error: candidates are: Game::Game(const Game&)
game.h:15:1: error: Game::Game(std::string, std::string, const int*, const int*, int)
game.cpp:13:1: error: Game::Game()
game.cpp: In member function ‘int Game::getVisitingScore(int) const’:
game.cpp:80:10: error: ‘visitingScores’ was not declared in this scope
game.cpp: At global scope:
game.cpp:94:1: error: ‘Date’ does not name a type
Will edit if further clarification is needed, although I don't think it will be.
Any help would be vastly appreciated.

I think that you're misunderstanding the use of include guards.
#ifndef __game_h_
#define __game_h_
// ...
#endif
The set of statements above would typically be used only in the header file describing your game interface, to prevent multiple-inclusion of that header file.
But in your code, you've added include guards to header and implementation, and also you seem to be confusing entities - unless I'm misunderstanding your file contents - for instance in team.h, you have what appear to be include guards for game.
My guess is that your misuse of include guards is actually preventing some types from being defined at all.
As others have mentioned, don't use names beginning with double underscores.
As an example, add include guards to your team header to prevent multiple-inclusion of that file, and give the include guards a name that reflects the module that they're guarding:
// team.h
#ifndef TEAM_H
#define TEAM_H
// ... code for team.h in here
#endif // TEAM_H

It looks like you have 2 problems here: The first is that you are using include guards in your source files; the second is that the order in which you have included your files is wrong.
First, include guards. Others have answered this question already, so I'll be brief. Include guards are used only in header files in order to prevent classes/types being declared more than once. For example if I had:
"game.h":
class Game {};
"game.cpp":
#include "game.h"
#include "game.h" // ERROR: class Game is declared twice.
To fix this I would use include guards in "game.h":
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
class Game {};
#endif
The first time the file is included, GAME_H_INCLUDED is not defined, so Game is declared. The second time it is include, GAME_H_INCLUDED is defined, so the declaration is skipped.
The problem you have is that your include guards in you source files will cause all of the implementation to be skipped:
broken "game.cpp":
#include "game.h"
#ifndef GAME_H_INCLUDED // This is defined in "game.h" so everything will be
// skipped until #endif is encountered.
#define GAME_H_INCLUDED
// Implementation of Game class
#endif
Second, the order in which you are including headers is incorrect. I'm guessing you have something like this:
"game.h"
#ifndef GAME
#define GAME
class Game
{
Date mDate; // Member of type Date, declared in "date.h"
};
#endif
"date.h"
#ifndef GAME
#define GAME
class Date
{
};
#endif
"game.cpp"
#include "game.h" // ERROR: Game relies on the Date class,
// which isn't included yet
#include "date.h"
To fix this either swap the order of the includes in "game.cpp":
"game.cpp"
#include "date.h"
#include "game.h" // Fine, we know what a Date is now.
Or include "date.h" in "game.h":
"game.h"
#include "date.h"
#ifndef GAME
#define GAME
class Game
{
Date mDate; // Member of type Date, declared in "date.h"
};
#endif
"game.cpp"
#include "game.h" // Still fine, "date.h" is included by "game.h"

you don't need the guards in your c++ files

The error is that you should use include guards only in your header files
If you have a
BaseClass.h
struct HumanEntity { }
and then have different classes use that base class, without the include guard you may run into issues. That is why you put a
#ifndef __MYGUARD
#define __MYGUARD
... // here is your header code
#endif

Related

How to resolve error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’?

Questions about incomplete type errors have already been asked here often, but all of the solutions provided there do not help in my case. Adding a forward declaration makes no sense, as GdkSurface has been forward declared already in the Gdk headers. Including the appropriate headers has already been done. Following the error producing code portion + includes.
#include <gdkmm/display.h>
#include <gdkmm/surface.h>
extern "C" {
#include <gdk/x11/gdkx.h>
#include <gdk/gdk.h>
}
extern "C" {
void surface_move(Gdk::Surface* psurface, int x, int y) {
#ifdef GDK_WINDOWING_X11
GdkSurface* surface = psurface->gobj();
GdkSurface *impl = GDK_X11_SURFACE(surface);
XMoveWindow(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
#endif
}
}
Here are the complete errors:
src/utils.cpp: In function ‘void Gdk::surface_move(Gdk::Surface*, int, int)’:
src/utils.cpp:9:83: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
src/utils.cpp:9:108: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
rface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
I built Gdk, Gtk, Gdkmm and Gtkmm with JHbuild.
It seems this type is private to GDK by design (only a forward declaration is provided). From the GDK4 documentation:
The GdkSurface struct contains only private fields and should not
be accessed directly.
See here for the header in which it is defined (which is not distributed). This is why you get these errors, all you have is a forward declaration to pass around pointers and references. All access to data members is forbidden.
To solve this, you have to use functions that work on surfaces (that are public), such as gdk_surface_get_scale_factor or something similar instead of trying to access data members directly.

Errors when building OpenCV program on OS X 10.11 via Xcode

I followed these instructions to install and build OpenCV 3 on my Mac: http://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/
I am successfully able to build the sample program (from the command-line) included at the bottom of that article.
I then followed the author's second article here: http://blogs.wcode.org/2014/11/howto-setup-xcode-6-1-to-work-with-opencv-libraries/ - I note that I'm using Xcode 7.2 instead of 6.1, but all of the dialogs and steps seemed to work fine.
...except for building.
With the simple C++ program included in the above article I get these build errors:
Xcode shows 20 errors all coming from cstring.h of the form:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:70:9: No member named 'memcpy' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:71:9: No member named 'memmove' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:72:9: No member named 'strcpy' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:73:9: No member named 'strncpy' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:74:9: No member named 'strcat' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:75:9: No member named 'strncat' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:76:9: No member named 'memcmp' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:77:9: No member named 'strcmp' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:78:9: No member named 'strncmp' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:79:9: No member named 'strcoll' in the global namespace; did you mean 'strtoll'?
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:80:9: No member named 'strxfrm' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:82:9: No member named 'memchr' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:84:9: No member named 'strchr' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:86:9: No member named 'strcspn' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:88:9: No member named 'strpbrk' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:90:9: No member named 'strrchr' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:92:9: No member named 'strspn' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:94:9: No member named 'strstr' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:98:87: No member named 'strchr' in the global namespace; did you mean simply 'strchr'?
It also gave me errors in the main.cpp file itself:
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:14:14: Invalid operands to binary expression ('ostream' (aka 'int') and 'const char *')
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:29:16: Variable has incomplete type 'string' (aka 'basic_string<char, char_traits<char>, allocator<char> >')
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:30:14: Invalid operands to binary expression ('ostream' (aka 'int') and 'const char *')
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:49:38: No viable conversion from 'cv::Mat' to 'const cv::_InputArray'
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:50:26: Invalid operands to binary expression ('ostream' (aka 'int') and 'const char *')
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:66:17: Variable has incomplete type 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >')
/Users/me/src/opencv-me-2/OpenCVTest/OpenCVTest/main.cpp:71:14: Invalid operands to binary expression ('ostream' (aka 'int') and 'const char *')
...I was able to eliminate those by adding #include <string> after the #include <stdio.h> line. However the "No member named 'memcpy' in the global namespace" errors still persist.
Update
Here is my minimal working example file:
main.cpp
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace cv;
using namespace std;
int main(int ac, char** av) {
return 0;
}
When I build it, I get the same 20 errors in cstring - which isn't referenced by my main.cpp file directly. Xcode reports the include-trace is:
main.cpp:1
opencv2/imgcodecs.hpp:46
opencv2/core.hpp:54
opencv2/core/base.hpp:53
Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:626

I am having issues with my heading in my function.cpp file

I have one .h which has the class in it and two .cpp, One being the main and the other holding the functions.
My complier is giving me theses errors
Functions.cpp: In member function âvoid Flandre::add()â:
Functions.cpp:10:3: error: âcinâ was not declared in this scope
Functions.cpp:12:33: error: âstrlenâ was not declared in this scope
Functions.cpp:16:6: error: âcoutâ was not declared in this scope
Functions.cpp:16:57: error: âendlâ was not declared in this scope
Functions.cpp:21:7: error: âcoutâ was not declared in this scope
Functions.cpp:21:53: error: âendlâ was not declared in this scope
Functions.cpp:27:9: error: name lookup of âiâ changed for ISO âforâ scoping [-f
Functions.cpp:27:9: note: (if you use â-fpermissiveâ G++ will accept your code)
Functions.cpp:27:16: error: âKYUUâ was not declared in this scope
Functions.cpp:32:6: error: âcoutâ was not declared in this scope
Functions.cpp:32:57: error: âendlâ was not declared in this scope
Functions.cpp:35:17: error: expected primary-expression before â[â token
Functions.cpp:37:14: error: expected unqualified-id before â[â token
Functions.cpp:38:14: error: expected unqualified-id before â[â token
Functions.cpp:39:14: error: expected unqualified-id before â[â token
I think it has something to do with the #include header in Functions
Newprogram2.cpp
>#include <iostream>
#include <string>
#include "newprogram2.h"
Functions.cpp
Some parts are missing but I just want it to complied so I can get add() to work first.
#include "newprogram2.h"
newprogram2.h
#ifndef NEWPROGRAM2_H
#define NEWPROGRAM2_H
#include<string>
using namespace std;
#endif
You have to include the proper headers for the functions you want to use.
For cin, cout and endl you need to #include <iostream>, you forgot to do that in your 2nd .cpp file
The compiler doesn't recognize strlen as a function because it is not in <string> (see http://www.cplusplus.com/reference/string/) but in <string.h> (see http://www.cplusplus.com/reference/cstring/strlen/).
I suggest you use either size() or length(), these are in <string>, both of these can be called on std::string objects.
Functions.cpp:27:16: error: âKYUUâ was not declared in this scope
This error shows because you try to access a variable you declared in another .cpp file. The .cpp file you are trying to access it in doesn't know this variable. You can fix that by moving the variable into the header file.
Functions.cpp:27:9: error: name lookup of âiâ changed for ISO âforâ scoping
This can be fixed by changing this
for(i=0;i<=KYUU;i++)
to this
for(int i=0;i<=KYUU;i++)
Functions.cpp:35:17: error: expected primary-expression before â[â token
Functions.cpp:37:14: error: expected unqualified-id before â[â token
Functions.cpp:38:14: error: expected unqualified-id before â[â token
Functions.cpp:39:14: error: expected unqualified-id before â[â token
These errors show because you try to call functions directly on a class instead of an object instantiated from that class, like this Flandre[i].getid(). You cannot do that, make an object instead and call the functions on the object.

Lots of errors when compiling project using FMOD with MinGW

I decided to use FMOD for sound playback in my project, but I'm getting lots of compiler errors which I am unsure of how to fix.
The header file of the class using FMOD looks more or less like this:
#ifndef PROJECTNAME_SOUNDMANAGER_H_
#define PROJECTNAME_SOUNDMANAGER_H_
#include <iostream>
#include <fmod.h>
#include <fmod.hpp>
#include <fmod_errors.h>
class SoundManager {
public:
static SoundManager &instance();
void play(char *data, size_t size, bool loop=false);
void stopAll();
private:
void ERRCHECK(FMOD_RESULT result);
SoundManager() : mSystem(nullptr) {
initFMOD();
}
SoundManager(const SoundManager &other);
SoundManager &operator=(const SoundManager &other);
void initFMOD();
FMOD::System *mSystem;
FMOD::Sound *mSound;
FMOD::Channel *mSoundChannel;
};
#endif // PROJECTNAME_SOUNDMANAGER_H_
And here are some of the compilation errors:
...../api/inc/fmod.h:1054:33: error: expected ')' before '*' token
...../api/inc/fmod.h:1056:33: error: expected ')' before '*' token
...../api/inc/fmod.h:1058:33: error: expected ')' before '*' token
...../api/inc/fmod.h:1059:33: error: expected ')' before '*' token
.....
...../api/inc/fmod.h:1465:5: error: 'FMOD_SOUND_PCMREADCALLBACK' does not name a type
...../api/inc/fmod.h:1466:5: error: 'FMOD_SOUND_PCMSETPOSCALLBACK' does not name a type
...../api/inc/fmod.h:1467:5: error: 'FMOD_SOUND_NONBLOCKCALLBACK' does not name a type
...../api/inc/fmod.h:1473:5: error: 'FMOD_FILE_OPENCALLBACK' does not name a type
.....
...../api/inc/fmod.h:1828:19: error: expected initializer before 'FMOD_Memory_GetStats'
...../api/inc/fmod.h:1829:19: error: expected initializer before 'FMOD_Debug_SetLevel'
...../api/inc/fmod.h:1830:19: error: expected initializer before 'FMOD_Debug_GetLevel'
...../api/inc/fmod.h:1831:19: error: expected initializer before 'FMOD_File_SetDiskBusy'
.....
...../api/inc/fmod.hpp:59:21: error: expected ';' at end of member declaration
...../api/inc/fmod.hpp:59:51: error: ISO C++ forbids declaration of 'release' with no type [-fpermissive]
...../api/inc/fmod.hpp:62:21: error: expected ';' at end of member declaration
...../api/inc/fmod.hpp:62:21: error: declaration of 'FMOD_RESULT FMOD::System::_stdcall'
...../api/inc/fmod.hpp:59:21: error: conflicts with previous declaration 'FMOD_RESULT FMOD::System::_stdcall'
...../api/inc/fmod.hpp:62:73: error: ISO C++ forbids declaration of 'setOutput' with no type [-fpermissive]
...../api/inc/fmod.hpp:63:21: error: expected ';' at end of member declaration
...../api/inc/fmod.hpp:63:21: error: declaration of 'FMOD_RESULT FMOD::System::_stdcall'
...../api/inc/fmod.hpp:59:21: error: conflicts with previous declaration 'FMOD_RESULT FMOD::System::_stdcall'
.....
If it makes any difference, I'm compiling with -std=c++0x.
I've tried searching but I wasn't able to find anything that helps me with these errors.
Please note that I'm using FMOD Ex 4.44.06.
EDIT: I seem to have found the problem. When I make a minimal example and compile it without -std=c++0x, everything compiles fine. However, if I add that flag, I get the same errors as with this project. Is there no way to make FMOD play nice with C++11?
My guess is that there's something defined as a macro or something not defined as a macro. Now, your task is to provide a minimal example. This can mean manually deleting large pieces of code or copying code from the header files. Do that until you can provide the offending code in a few lines. I guess that doing so, you will find the problem yourself.
There are a few things I noticed with the little code you provided:
fmod() is actually a function and I could imagine a few compilers providing this as a macro, which in turn conflicts with #include, but that doesn't seem to be your problem.
You include both fmod.h and fmod.hpp, which looks suspicious.
void ERRCHECK(FMOD_RESULT result); looks like a mix between function and macro.
play() should probably take a const char* data.
Under MSYS2 and GCC v5.4.0 I was facing the same problem.
The solution was add the compile flag -D__CYGWIN32__.
This is due the following in fmod.h:
#if defined(__CYGWIN32__)
#define F_CDECL __cdecl
#define F_STDCALL __stdcall
#define F_DECLSPEC __declspec
#define F_DLLEXPORT ( dllexport )
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
#define F_CDECL _cdecl
#define F_STDCALL _stdcall
#define F_DECLSPEC __declspec
#define F_DLLEXPORT ( dllexport )
...

C++: Maybe you know this pitfall?

I'm developing a game. I have a header GameSystem (just methods like the game loop, no class) with two variables:
int mouseX and int mouseY. These are updated in my game loop. Now I want to access them from Game.cpp file (a class built by a header-file and the source-file). So, I #include "GameSystem.h" in Game.h. After doing this I get a lot of compile errors. When I remove the include he says of course:
Game.cpp:33: error: ‘mouseX’ was not declared in this scope
Game.cpp:34: error: ‘mouseY’ was not declared in this scope
Where I want to access mouseX and mouseY.
All my .h files have Header Guards, generated by Eclipse.
I'm using SDL and if I remove the lines that wants to access the variables, everything compiles and run perfectly (*).
I hope you can help me...
This is the error-log when I #include "GameSystem.h" (All the code he is refering to works, like explained by the (*)):
In file included from ../trunk/source/domein/Game.h:14,
from ../trunk/source/domein/Game.cpp:8:
../trunk/source/domein/GameSystem.h:30: error: expected constructor, destructor, or type conversion before ‘*’ token
../trunk/source/domein/GameSystem.h:46: error: variable or field ‘InitGame’ declared void
../trunk/source/domein/GameSystem.h:46: error: ‘Game’ was not declared in this scope
../trunk/source/domein/GameSystem.h:46: error: ‘g’ was not declared in this scope
../trunk/source/domein/GameSystem.h:46: error: expected primary-expression before ‘char’
../trunk/source/domein/GameSystem.h:46: error: expected primary-expression before ‘bool’
../trunk/source/domein/FPS.h:46: warning: ‘void FPS_SleepMilliseconds(int)’ defined but not used
This is the code which try to access the two variables:
SDL_Rect pointer;
pointer.x = mouseX;
pointer.y = mouseY;
pointer.w = 3;
pointer.h = 3;
SDL_FillRect(buffer, &pointer, 0xFF0000);
In your GameSystem header, don't define those variables as:
int mouseX;
int mouseY;
instead, you should declare them:
extern int mouseX;
extern int mouseY;
Then in one of your .cpp files you define them:
int mouseX;
int mouseY;
The problem with defining them in a header file is that the compiler will try to instantiate them in every single .cpp where you include the header.