C++ gnu gcc compiler error - c++

I am currently in the process of switching compilers.
From microtech to GNU GCC/G++ coldfire..
I keep receiving the following error and can not find a simple solution:
warning: ANSI C++ forbids declaration `interrupt' with no type
I know the line that it is failing on:
friend interrupt void IrqCtmMCSM2(void);
Could someone offer suggestions please?
Thanks for your time.

Related

unknown attribute `extern_c` warning in C++

I’m building a Cocos2d-x game for Android on a Mac, using Android NDK, and I get many warnings like this when compiling the C++ part:
/usr/include/module.map:1662:22: warning: unknown attribute 'extern_c' [-Wignored-attributes]
Is it dangerous? How can I fix it?
I'm guessing that extern_c is a compiler directive for the module map saying it is referencing functions from C++ that were written in the C language (different call frame structure).
The LLVM portion of the CLANG compiler is probably having a version mismatch.
http://clang.llvm.org/docs/Modules.html#module-maps
Try a command line $ clang -v
You may have to verify the compiler library version
xcode->preferences->locations->command line tools.
Ultimately you will want to clear this up so your stack frames match the arguments and your not referencing a C language function.

Brace-initialization of an array of structs in c++11

Here is my code:
#include <string>
struct A
{
int a;
std::string sa;
};
int main()
{
A arr[3]{};
}
When I compile it with gcc 4.8.2 (on Ubuntu 14.04) with -std=gnu++11 option I get the following error:
example.cpp: In function ‘int main()’:
example.cpp:11:14: internal compiler error: in gimplify_init_constructor, at gimplify.c:4271
A arr[3]{};
^
Why does it throw an internal compiler error? Is it a compiler bug?
An internal compiler error is always a compiler bug, and says nothing about whether the code is valid.
If the code is invalid, the compiler is supposed to give an error message telling you what's wrong with the code. An internal compiler error only tells you what's wrong with the compiler.
Given that this internal compiler error still exists in later versions (I just checked 4.9.2, as well as current sources as of January 29th), I would normally strongly encourage reporting this as a bug to the GCC developers, but a quick search reveals that it's already known to them.
You can work around it by writing A arr[3]{{}};, which means the same thing. It contains the same initialiser for the first element of arr that it would already get by default.
I encountered the same issue right out of blue with gcc 4.8.5 when I added an std::string to a content of the array struct. Adding extra {} as suggested above helped. Maybe this can give a clue why this compiler error happens.

Compile in c++14

So in my CSE course we are given a header file to use right now for our programs that we're writing.
Unfortunately I can't get terminal to compile using that header, it gives quite a few errors (compiling with just 'g++'). Also, when I'm at my university and I'm using PuTTY I get the same errors while using this header. However, I don't get the errors when I compile with 'g++ -std=c++14'.
I've tried compiling with this command on terminal on my mac, but it says it doesn't recognize the c++14 part.
dhcp-10-202-147-243:hw1pr1 Admin$ g++ -std=c++14 hw1pr1.cpp
error: invalid value 'c++14' in '-std=c++14'
Any help on how I could get this to work would be greatly appreciated. Hopefully this all made some sort of sense.
Here's the error I get when I compile with the header file I'm talking about in terminal with just g++.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/hash_map:212:5: warning:
Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
[-W#warnings]
# warning Use of the header <ext/hash_map> is deprecated. Migrate to ...
^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:43:20: error: no matching function for call to object
of type 'hash<char *>'
return hash<char*>()(s.c_str());
^~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/__hash:39:12: note:
candidate function not viable: 1st argument ('const value_type *'
(aka 'const char *')) would lose const qualifier
size_t operator()(char *__c) const _NOEXCEPT
^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:112:8: warning: comparison of unsigned expression < 0
is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
./std_lib_facilities_4.h:118:8: warning: comparison of unsigned expression < 0
is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
3 warnings and 1 error generated.
This error doesn't happen and the program will compile fully when I use PuTTY and 'g++ std=c++14'
There's lots of change between C++ standards, so what is valid in one revision need not be in another.
g++ defaults to -std=gnu++98 for C++, which is the decades old C++98-standard enhanced with GNU extensions (most of which are conformant).
Choose the proper revision: -std=c++1y -pedantic is a very close approximation to C++14.
What changes introduced in C++14 can potentially break a program written in C++11?
Looking at what you say you're having to use and the name format of that .cpp file, I think I'm in the same class. A year later, looks like, but here's my solution for archive's sake:
The std_lib_facilities.h header comes with the Bjarne Stroustrup textbook, "Programming: Principles and Practices Using C++". For those unaware, Bjarne Stroustrup invented C++ (he has a pretty good idea what he's talking about). Incidentally, the book is a fantastic way to learn C++, if one takes the time to actually read it. The std_lib_facilities.h header is just a convenient header file for beginners in C++, containing links to all the major standard libraries used in the textbook, as well as some helper functions that help account for potential mistakes or errors, or are just convenient for learning (such as an error() function that handles simple exception throwing for the student, or adding an "out of bounds" check for vectors). It's ultimately just a way to allow students to hop right into code without having to learn specifics about the header.
Stroustrup keeps updated with C++ and thus includes several libraries that require the c++11 standard. The CSCE department wants its students (at least in this early class) to connect to the department's Unix system and compile from there, in order to avoid confusion with downloading and updating compilers.
I happened to already have had a couple C++ classes beforehand, and thus already had g++ set up on my Ubuntu laptop. I avoided including the std_lib_facilities for as long as possible since I was getting the same error as Topic Creator Joe, where g++ didn't recognize the "c++11" part (manually including the required libraries worked fine until we had to use a class from the textbook that used one of the header's helper functions) . Eventually, I found a help topic online that advised me simply to update my g++ compiler to 4.7 or higher, since 4.6 and lower doesn't have support for C++11 (or, of course, C++14). It was oddly rather involved compared to updates one might be used to on Mac or Windows, and I doubt the exact process would apply, but that is (was?) likely the problem: it's just an older version of g++, and it needs an update to compile C++11 and later. I recommend searching for ways to update g++/gcc for Mac.
Should, y'know, anyone else with this problem stumble upon this and not have their problem solved yet.

Compilation GDB give error

Related to problem 16611678 I need a new version of gdb in my centos 6.5 64.
I try to compile GDB (7.7, 7.6.2 and 7.5), without success, the error is related to get_tty_state() in ser-unix.c:
ser-unix.c:118:1: error: conflicting types for ‘get_tty_state’
My gcc version is 4.8.2
Before the function declaration there is preprocessor directives for defining hardwire_ttystate if HAVE_TERMIOS is defined and I think the problem come from here (if needed I can post the piece of code), as HAVE_TERMIOS is undefined.
Any help would be appreciated!
Nathanaël

C++ Redis hiredis compiler error?

Thanks to someone on this site, I was able to use a sample C++ source file.
https://gist.github.com/1893378
When I compile this, I get a bunch of strange compiler errors:
/home/.../workspace/redis-hiredis-3c46b13/pipelineTest.cpp: In function ‘void redisTop(redisContext*)’:
/home/.../workspace/redis-hiredis-3c46b13/pipelineTest.cpp:142:32: error: invalid conversion from ‘void*’ to ‘redisReply*’
/home/../workspace/redis-hiredis-3c46b13/pipelineTest.cpp:162:25: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
/home/=.../workspace/redis-hiredis-3c46b13/pipelineTest.cpp: In function ‘int main(int, char**)’:
I realize I may be out of synch with hiredis libray but I am using the latest one. Any ideas how to properly build this C++ program?
Also, I am looking for a complete C++ tutorial of pipeline with Redis. Here is a really good example in Java:
http://www.cafebabe.me/2011/05/redis-pipelines-and-transactions.html
Is there no example tutorial like this for C++?
Thanks either way
Actually, it is a C program, not C++. The C++ compiler is usually more pedantic that a C compiler, and it complains. Minor adaptations are needed to compile with a C++ compiler.
I did them, and put the file online again:
https://gist.github.com/1893378
It now compiles fine with g++ 3.4 and 4.3
AFAIK, there is no C++ tutorial for Redis. I think the best way to deal with Redis in C++ is to develop your own wrapping classes on top of hiredis. It is not that hard.
Just cast redisCommand to redisReply
reply = (redisReply *)redisCommand(context, "PING");
This is a C program. You have to build it with a C compiler.