I am working on getting a piece of legacy software to build with gcc 4.7 on Debian stable (which currently also requires libstdc++5 3.2 for some reason), and currently g++ is hung up on crypto++'s md5.h
My c++ skills are rusty, and I've been staring at this for a couple days now. Does anyone have any ideas on how I can fix this?
The full source of the version of cryto++ I'm using:
http://www.filedropper.com/cryptolegacy
the error:
compiling md5.cpp (g++)
compiling md5.cpp (g++)
In file included from md5.cpp:5:0:
md5.h:10:32: error: expected template-name before '<' token
md5.h:10:32: error: expected '{' before '<' token
md5.h:10:32: error: expected unqualified-id before '<' token
md5.cpp:109:1: error: expected '}' at end of input
md5.h
#ifndef CRYPTOPP_MD5_H
#define CRYPTOPP_MD5_H
#include "iterhash.h"
NAMESPACE_BEGIN(CryptoPP)
/// MD5
/** 128 Bit Hash */
class MD5 : public IteratedHash<word32, false, 64>
{
public:
enum {DIGESTSIZE = 16};
MD5() : IteratedHash<word32, false, 64>(DIGESTSIZE) {Init();}
static void Transform(word32 *digest, const word32 *data);
protected:
void Init();
void vTransform(const word32 *data) {Transform(digest, data);}
};
NAMESPACE_END
#endif
Related
Trying to compile the sqlpp17 codebase with gcc 8.2.1 and clang 6.0.1 have been a really strange experience. The code pushes the compilers to the limits and I hit probably a few compiler bugs in the meantime.
From the GCC Docs, [[maybe_unused]] is implemented since version 7, but if used this way:
struct foo {
foo([[maybe_unused]] bool thing1)
{
}
};
I hit this specific error:
<source>:2:9: error: expected unqualified-id before '[' token
foo([[maybe_unused]] bool thing1)
^
<source>:2:9: error: expected ')' before '[' token
foo([[maybe_unused]] bool thing1)
~^
)
Compiler returned: 1
Now, I know too little about C++17 to know if this error is correct, I know that clang 6 compiles that part fine (and fails somewhere else).
So, who's right, clang or gcc? (flags are -std=gnu++17 for both clang and gcc, generated by CMake)
This is a known bug in g++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 G++ doesn't parse correctly [[maybe_unused]] attribute for first argument of the constructor.
I've got this class definition in a .h file, and the implementation in a .cpp file. When I try to compile this, the header file gives some errors and warnings:
/home/don/BerthaApex/apex/src/lib/apexmain/apexloader.h:6: error: variable 'APEX_EXPORT ApexLoader' has initializer but incomplete type
class APEX_EXPORT ApexLoader
^
/home/don/BerthaApex/apex/src/lib/apexmain/apexloader.h:6: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/home/don/BerthaApex/apex/src/lib/apexmain/apexloader.h:9: error: expected primary-expression before 'public'
public:
The code in which this error occurs is:
#ifndef _APEXLOADER_H
#define _APEXLOADER_H
#include "global.h"
class APEX_EXPORT ApexLoader
{
public:
int Load( int argc, char *argv[]);
};
#endif
With the "class APEX_EXPORT ApexLoader" being the line with the error and the warning.
The APEX_EXPORT is defined in a header file that is included from this same file.
EDIT:
The APEX_EXPORT is defined in "global.h" as follows:
#ifdef APEX_MAKEDLL
#define APEX_EXPORT APEX_EXPORT_DECL
#else
#define APEX_EXPORT APEX_IMPORT_DECL
#endif
Does anyone know why these errors are there? And how can I get rid of them?
Thank you in advance!
Compiler: gcc 4.8.4
OS: Ubuntu 14.04
My psychic debugging skills tell me that APEX_EXPORT isn't #defined and thus the compiler thinks you're trying to declare a variable of that type.
If you think you've included all the right headers the best way to go is to just run the preprocessor on your source file and see what it generates (for example g++ -E).
I am receiving these errors while attempting to compile my program with GCC and i'm not sure whats causing them.
functions.h:21: error: expected ')' before '[' token
functions.h:22: error: expected ')' before '[' token
functions.h:23: error: expected ')' before '[' token
functions.h:25: error: expected ')' before '[' token
functions.h:26: error: expected ')' before '[' token
functions.h:27: error: expected ')' before '[' token
My program compiles fine in visual studio 2012.
Heres the header file that seems to be causing the errors.
struct subject
{
char year[5];
char session;
char code[8];
char credit[3];
char mark[4];
};
struct data
{
char name[30];
char id[30];
char cc[30];
char course[80];
struct subject subjects[30];
int gpa;
};
void displayRecord(data [], int);
int nameSearch(data [], char [], int [], int);
void editRecord(data [], int, int);
char getChar(const char [], int);
int getData(data []);
void displayData(data []);
void deleteRecord(data [], int, int);
I'm invoking the compiler like this:
gcc -o test functions.cpp functions.h main.cpp
I'm stumped so any help would be appreciated!
My psychic debugging powers tell me that your visual studio is compiling the code as C++ while gcc is compiling it as C. Since you're missing the struct keyword before data in your function parameters the C compiler doesn't know what to do. Try running it through g++ instead of gcc (and possibly make sure your including source file's extension is .C or .cpp.
The problem is that you are passing functions.h to the compiler. That is an include file and you should just let the two .cpp files include it. There's no need to pass it in your command line invocation of the compiler. Simply remove functions.h from your command line invocation of gcc.
Since this is C++, you should be using g++ rather than gcc to compile. Since you used gcc, the compiler treated functions.h as being C, and the code not valid C.
So, I think your compilation should be
g++ -o test functions.cpp main.cpp
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 )
...
#ifndef UNO_ACTION_
#define UNO_ACTION_
namespace Uno
{
namespace Game
{
class Game;
}
} // namespace
namespace Uno
{
namespace Action
{
using ::Uno::Game::Game;
class Action
{
public:
virtual bool isDisposeable() = 0;
virtual void takeAction(Game* game) = 0;
virtual ~Action() {}
};
}
}
#endif
I compile these code on ubuntu 12.04 and it returns to set of error:
action.h:4:1: error: unknown type name ‘namespace’
action.h:4:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
action.h:8:1: error: unknown type name ‘namespace’
action.h:8:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
How do I solve these errors?
It sounds like you're trying to compile your C++ code with a C compiler. Try using g++ instead of gcc and giving your file a C++ extension such as .cpp (rather than .c).
Had this issue with YCM and clang. Turns out, the missing flag was "-x", "c++".
From the official clang documentation:
-x <language> : Treat subsequent input files as having type language.
I had a similar issue and found this question but the solutions don't match mine completely, so I'm adding mine here.
In my case, I was including a header file in .cpp files and .c files.
The solution was to split off the namespace part of the header since that was obviously only needed in the .cpp files.