gcc compile error for gnu readline() to read from stdin - gcc

HI, guys,
I write a small program, named "ioprogram.c", with gnu readline library, refering various documentation on the Internet. however, gcc reports the following errors. what is my problem?
#include <readline/readline.h>
#include <stdio.h>
int main()
{
char* c = readline("");
int len = strlen(c);
for(int i=0; i<len; i++)
{
printf("%c", *(c+i));
fflush(stdout);
}
free(c);
}
gcc errors:
In file included from /usr/include/readline/readline.h:37,
from ioprogram.c:1:
/usr/include/readline/rltypedefs.h:65: error: expected ‘)’ before ‘*’ token
In file included from ioprogram.c:1:
/usr/include/readline/readline.h:416: error: expected ‘)’ before ‘*’ token
/usr/include/readline/readline.h:532: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:533: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:555: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/readline/readline.h:823: error: expected specifier-qualifier-list before ‘FILE’
ioprogram.c: In function ‘main’:
ioprogram.c:7: error: ‘for’ loop initial declaration used outside C99 mode
Thanks in advance for any comments.

try compiling with
gcc ioprogram.c -o ioprogram -lreadline -lncurses

Related

error ‘underlying_type_t’ in namespace ‘std’ does not name a template type in example.cpp from project-OSRM

I try to execute the examle.cpp file of Project-OSRM. I did the following steps:
build OSRM from source as described here
in new terminal: cd osrm-backend/example
in the terminal: cmake ..
in the terminal: cmake --build .
in the terminal: sudo cmake --build . --target install
move the maps contractor, engine, extractor, partition, storage, util from /usr/local/include/osrm to /usr/local/include (else error maps are not in /usr/local/include)
in the terminal: g++ -std=c++11 example.cpp -o example
But I get the error
‘underlying_type_t’ in namespace ‘std’ does not name a template type
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>
Does anyone have a idea what I'm doing wrong or what is going wrong and how to solve this?
Error message
In file included from /usr/local/include/engine/api/match_parameters.hpp:31:0,
from /usr/local/include/osrm/match_parameters.hpp:31,
from example.cpp:1:
/usr/local/include/engine/api/route_parameters.hpp: In function ‘bool osrm::engine::api::operator&(osrm::engine::api::RouteParameters::AnnotationsType, osrm::engine::api::RouteParameters::AnnotationsType)’:
/usr/local/include/engine/api/route_parameters.hpp:144:26: error: ‘underlying_type_t’ in namespace ‘std’ does not name a template type
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(l
^
/usr/local/include/engine/api/route_parameters.hpp:144:43: error: expected ‘>’ before ‘<’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(l
^
/usr/local/include/engine/api/route_parameters.hpp:144:43: error: expected ‘(’ before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:144:43: error: expected primary-expression before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:144:76: error: expected primary-expression before ‘>>’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(lhs) &
^
/usr/local/include/engine/api/route_parameters.hpp:145:26: error: ‘underlying_type_t’ in namespace ‘std’ does not name a template type
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(r
^
/usr/local/include/engine/api/route_parameters.hpp:145:43: error: expected ‘>’ before ‘<’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(r
^
/usr/local/include/engine/api/route_parameters.hpp:145:43: error: expected ‘(’ before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:145:43: error: expected primary-expression before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:145:76: error: expected primary-expression before ‘>>’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(rhs));
^
/usr/local/include/engine/api/route_parameters.hpp:145:84: error: expected ‘)’ before ‘;’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(rhs));
^
/usr/local/include/engine/api/route_parameters.hpp:145:84: error: expected ‘)’ before ‘;’ token
/usr/local/include/engine/api/route_parameters.hpp: In function ‘osrm::engine::api::RouteParameters::AnnotationsType osrm::engine::api::operator|(osrm::engine::api::RouteParameters::AnnotationsType, osrm::engine::api::RouteParameters::AnnotationsType)’:
/usr/local/include/engine/api/route_parameters.hpp:152:26: error: ‘underlying_type_t’ in namespace ‘std’ does not name a template type
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(l
^
/usr/local/include/engine/api/route_parameters.hpp:152:43: error: expected ‘>’ before ‘<’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(l
^
/usr/local/include/engine/api/route_parameters.hpp:152:43: error: expected ‘(’ before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:152:43: error: expected primary-expression before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:152:76: error: expected primary-expression before ‘>>’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(lhs) |
^
/usr/local/include/engine/api/route_parameters.hpp:153:26: error: ‘underlying_type_t’ in namespace ‘std’ does not name a template type
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(r
^
/usr/local/include/engine/api/route_parameters.hpp:153:43: error: expected ‘>’ before ‘<’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(r
^
/usr/local/include/engine/api/route_parameters.hpp:153:43: error: expected ‘(’ before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:153:43: error: expected primary-expression before ‘<’ token
/usr/local/include/engine/api/route_parameters.hpp:153:76: error: expected primary-expression before ‘>>’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(rhs));
^
/usr/local/include/engine/api/route_parameters.hpp:153:84: error: expected ‘)’ before ‘;’ token
static_cast<std::underlying_type_t<RouteParameters::AnnotationsType>>(rhs));
^
/usr/local/include/engine/api/route_parameters.hpp:153:84: error: expected ‘)’ before ‘;’ token
underlying_type_t requires C++14. To be able to use it pass -std=c++14 to your compiler.
Don't forget to
#include <type_traits>
This missing directive also lead to the same (confusing) error message.

trec_eval's makefile generates errors on windows

Good morning,
I've got the same problem, here are the syntax errors mentionned bye the cygwin64 on windows7 :
$ make
gcc -g -I. -Wall -DVERSIONID=\"9.0\" -o trec_eval trec_eval.c ... m_Rprec_mult_avgjg.c m_P_avgjg.c -lm
In file included from sysfunc.h:21:0,
from m_ndcg.c:9:
m_ndcg.c:13:8: erreur : expected ‘)’ before ‘/’ token
double log2(double x);
^
In file included from sysfunc.h:21:0,
from m_ndcg_cut.c:8:
m_ndcg_cut.c:12:8: erreur : expected ‘)’ before ‘/’ token
double log2(double x);
^
In file included from sysfunc.h:21:0,
from m_Rndcg.c:9:
m_Rndcg.c:13:8: erreur : expected ‘)’ before ‘/’ token
double log2(double x);
^
In file included from sysfunc.h:21:0,
from m_ndcg_rel.c:9:
m_ndcg_rel.c:13:8: erreur : expected ‘)’ before ‘/’ token
double log2(double x);
^
In file included from sysfunc.h:21:0,
from m_binG.c:9:
m_binG.c:13:8: erreur : expected ‘)’ before ‘/’ token
double log2(double x);
^
In file included from sysfunc.h:21:0,
from m_G.c:9:
m_G.c:13:8: erreur : expected ‘)’ before ‘/’ token
double log2(double x);
^
make: *** [Makefile:54: trec_eval] Error 1
Is there someone that can help ?
Thanks

Building Python from source as a framework on Mac OS X Mountain Lion: error in headers

I was building Python (3.4 dev version) from source as a framework on OS X 10.8. I'm a relative newbie to Mac OS X internals and couldn't figure out why the OS X framework headers caused these errors. Can someone please give me some pointers?
I use the latest version of GNU gcc on my mac instead of the Apple supplied LLVM compiler. Perhaps, that's causing a compatibility problem.
gcc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -o FileSettings.o -c ./FileSettings.m
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:123:0,
from ./FileSettings.h:9,
from ./FileSettings.m:9:
/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:69:24: error: expected identifier or ‘(’ before ‘^’ token
#property (copy) void (^terminationHandler)(NSTask *) NS_AVAILABLE(10_7, NA);
^
/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:72:1: error: expected identifier before ‘end’
#end
^
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:159:0,
from ./FileSettings.h:9,
from ./FileSettings.m:9:
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:36:15: error: expected identifier or ‘(’ before ‘^’ token
typedef void (^NSUserScriptTaskCompletionHandler)(NSError *error);
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:37:1: error: unknown type name ‘NSUserScriptTaskCompletionHandler’
- (void)executeWithCompletionHandler:(NSUserScriptTaskCompletionHandler)handler;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:53:15: error: expected identifier or ‘(’ before ‘^’ token
typedef void (^NSUserUnixTaskCompletionHandler)(NSError *error);
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:54:1: error: unknown type name ‘NSUserUnixTaskCompletionHandler’
- (void)executeWithArguments:(NSArray *)arguments completionHandler:(NSUserUnixTaskCompletionHandler)handler;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:68:15: error: expected identifier or ‘(’ before ‘^’ token
typedef void (^NSUserAppleScriptTaskCompletionHandler)(NSAppleEventDescriptor *result, NSError *error);
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:69:1: error: unknown type name ‘NSUserAppleScriptTaskCompletionHandler’
- (void)executeWithAppleEvent:(NSAppleEventDescriptor *)event completionHandler:(NSUserAppleScriptTaskCompletionHandler)handler;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:86:15: error: expected identifier or ‘(’ before ‘^’ token
typedef void (^NSUserAutomatorTaskCompletionHandler)(id result, NSError *error);
^
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:87:1: error: unknown type name ‘NSUserAutomatorTaskCompletionHandler’
- (void)executeWithInput:(id <NSSecureCoding>)input completionHandler:(NSUserAutomatorTaskCompletionHandler)handler;
^
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:160:0,
from ./FileSettings.h:9,
from ./FileSettings.m:9:
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:46:11: error: expected identifier or ‘(’ before ‘^’ token
void (^_interruptionHandler)();
^
make[2]: *** [FileSettings.o] Error 1
make[1]: *** [install_PythonLauncher] Error 2
make: *** [frameworkinstallapps] Error 2
The errors correspond precisely to the 'block' extension Apple developed for C, C++ and Objective-C languages. GCC (the GNU version) doesn't recognize the block occurences and complains.

Error with new gcc48 on macos

I'm having serious problems running some standard commands such as sleep() with g++-mp-4.8 downloaded from macports. I don't have any of these problems compiling with llvm-g++-4.2.
This is quite annoying, because I'm trying to use C++11 features in this program.
Here is the read out from the compiler - I'm really sorry it's so long, I just have no idea what to do with it:
17:11:54 **** Incremental Build of configuration Debug for project BSDESimV2 ****
make all
Building file: ../TrueSolutions/TrueSoln.cpp
Invoking: GCC C++ Compiler
/opt/local/bin/g++ -g -O0 -Wall -I/opt/local/include -I/usr/include -I/usr/llvm-gcc-4.2 /lib/gcc/i686-apple-darwin11/4.2.1/include -I/Applications/Xcode.app/Contents/Developer/usr/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include -I/usr/include/c++/4.2.1 -I/usr/include/c++/4.2.1/backup -I/opt/local/bin -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"TrueSolutions/TrueSoln.d" -MT"TrueSolutions/TrueSoln.d" -o "TrueSolutions/TrueSoln.o" "../TrueSolutions/TrueSoln.cpp"
In file included from /usr/include/c++/4.2.1/bits/stl_algobase.h:72:0,
from /usr/include/c++/4.2.1/bits/char_traits.h:46,
from /usr/include/c++/4.2.1/ios:45,
from /usr/include/c++/4.2.1/istream:44,
from /usr/include/c++/4.2.1/fstream:45,
from ../TrueSolutions/TrueSoln.h:15,
from ../TrueSolutions/TrueSoln.cpp:8:
/usr/include/c++/4.2.1/bits/cpp_type_traits.h:381:12: error: expected identifier before '__is_pod'
struct __is_pod
^
/usr/include/c++/4.2.1/bits/cpp_type_traits.h:381:12: error: expected unqualified-id before '__is_pod'
/usr/include/c++/4.2.1/bits/cpp_type_traits.h:394:12: error: expected identifier before '__is_empty'
struct __is_empty
^
/usr/include/c++/4.2.1/bits/cpp_type_traits.h:394:12: error: expected unqualified-id before '__is_empty'
In file included from /usr/include/c++/4.2.1/memory:54:0,
from /usr/include/c++/4.2.1/string:48,
from /usr/include/c++/4.2.1/bits/locale_classes.h:47,
from /usr/include/c++/4.2.1/bits/ios_base.h:47,
from /usr/include/c++/4.2.1/ios:48,
from /usr/include/c++/4.2.1/istream:44,
from /usr/include/c++/4.2.1/fstream:45,
from ../TrueSolutions/TrueSoln.h:15,
from ../TrueSolutions/TrueSoln.cpp:8:
/usr/include/c++/4.2.1/bits/allocator.h:135:41: error: expected unqualified-id before '__is_empty'
template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value>
^
/usr/include/c++/4.2.1/bits/allocator.h:135:41: error: expected '>' before '__is_empty'
In file included from /usr/include/c++/4.2.1/vector:70:0,
from ../TrueSolutions/TrueSoln.h:23,
from ../TrueSolutions/TrueSoln.cpp:8:
/usr/include/c++/4.2.1/bits/stl_vector.h: In member function 'void std::vector<_Tp, _Alloc>::swap(std::vector<_Tp, _Alloc>&)':
/usr/include/c++/4.2.1/bits/stl_vector.h:740:34: error: template argument 2 is invalid
std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
^
/usr/include/c++/4.2.1/bits/stl_vector.h:740:45: error: invalid type in declaration before '(' token
std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
^
/usr/include/c++/4.2.1/bits/stl_vector.h:741:36: error: expression list treated as compound expression in initializer [-fpermissive]
__x._M_get_Tp_allocator());
^
In file included from /usr/include/c++/4.2.1/vector:71:0,
from ../TrueSolutions/TrueSoln.h:23,
from ../TrueSolutions/TrueSoln.cpp:8:
/usr/include/c++/4.2.1/bits/stl_bvector.h: In member function 'void std::vector<bool, _Alloc>::swap(std::vector<bool, _Alloc>&)':
/usr/include/c++/4.2.1/bits/stl_bvector.h:690:56: error: template argument 2 is invalid
std::__alloc_swap<typename _Base::_Bit_alloc_type>::
^
/usr/include/c++/4.2.1/bits/stl_bvector.h:691:10: error: invalid type in declaration before '(' token
_S_do_it(_M_get_Bit_allocator(), __x._M_get_Bit_allocator());
^
/usr/include/c++/4.2.1/bits/stl_bvector.h:691:61: error: expression list treated as compound expression in initializer [-fpermissive]
_S_do_it(_M_get_Bit_allocator(), __x._M_get_Bit_allocator());
^
make: *** [TrueSolutions/TrueSoln.o] Error 1
As suggested in the hints, I got rid of all the outdated -I/'s and set up the clang++ compiler as in Eclipse, Macos 10.8 and C++11
There were some clashes with between my code and the stl, but they were easy to hunt down from the console output.

Linux kernel programming

i want to catch pipe() syscall, so i've changed source code in pipe.c
static pipe_hook_t pipe_hook;
pipe_hook_t set_pipe_hook(pipe_hook_t hook)
{
pipe_hook_t old_hook = pipe_hook;
pipe_hook = hook;
printk(KERN_INFO, "pipe hook: %p", hook);
return old_hook;
}
EXPORT_SYMBOL_GPL(set_pipe_hook);
then i tried to define pipe_hook_t in file syscalls.h (included in pipe.c)
typedef void (*pipe_hook_t)(int *filedes);
pipe_hook_t set_pipe_hook(pipe_hook_t hook);
and i have error:
fs/pipe.c:1130: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pipe_hook’
fs/pipe.c:1131: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘set_pipe_hook’
fs/pipe.c:1138: error: ‘set_pipe_hook’ undeclared here (not in a function)
fs/pipe.c:1138: warning: type defaults to ‘int’ in declaration of ‘set_pipe_hook’
fs/pipe.c: In function ‘sys_pipe2’:
fs/pipe.c:1153: error: ‘pipe_hook’ undeclared (first use in this function)
fs/pipe.c:1153: error: (Each undeclared identifier is reported only once
fs/pipe.c:1153: error: for each function it appears in.)
fs/pipe.c:1154: error: implicit declaration of function ‘pipe_hook’
i've tried to create my own .h file and define pipe_hook_t there but the error was the same
Problem has been solved. I've just confused directory where header files are.

Resources