Why is alarm and SIGALRM undeclared? - alarm

I am trying to compile the sources of a chess program which includes these, I think, relevant lines:
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include "timectrl.h"
#include "search.h"
#include "plp.h"
#include "uci.h"
#include "util.h"
#include <winsock2.h>
...
signal(SIGALRM, timectrl_alarm);
However, the compilation fails and I get these messages:
timectrl.c: In function 'timectrl_go':
timectrl.c:59:12: error: 'SIGALRM' undeclared (first use in this function); did you mean 'SIGABRT'?
59 | signal(SIGALRM, timectrl_alarm);
| ^~~~~~~
| SIGABRT
timectrl.c:59:12: note: each undeclared identifier is reported only once for each function it appears in
timectrl.c:63:5: warning: implicit declaration of function 'alarm' [-Wimplicit-function-declaration]
63 | alarm(1);
| ^~~~~
I don't understand why these are undeclared when they must be in the included libraries.
Can you help please?

Related

ntsecapi.h:594:22: error: expected unqualified-id before string constant

I'm building a small project (I'm running windows 7 with cygwin64 ). here is how my "header of program" looks like
#ifndef Win32_H
#define Win32_H
#define USE_LSA
#include <winsock2.h>
#include <windows.h>
#include <psapi.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <string.h>
#define SECURITY_WIN32
#include <ntstatus.h>
#include <Sspi.h>
#include <Ntsecapi.h>
#include <Ntsecpkg.h>
#include <sddl.h>
#include <algorithm>
#include "Class1.h"
#include "Class2.h"
#include <Class3.h>
#include <errno.h>
I downloaded this project to examine. But the problem I have is that I ran into a compiling error which says
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/Sspi.h:10:0,
from main.cpp:61:
/usr/i686-w64-mingw32/sys-root/mingw/include/ntsecapi.h:594:22: error: expected unqualified-id before string constant
typedef LSA_STRING STRING,*PSTRING;
^
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/Sspi.h:10:0,
from TokenServer.cpp:61:
/usr/i686-w64-mingw32/sys-root/mingw/include/ntsecapi.h:707:5: error: expected unqualified-id before string constant
STRING CaseSensitiveChallengeResponse;
^
/usr/i686-w64-mingw32/sys-root/mingw/include/ntsecapi.h:708:5: error: expected unqualified-id before string constant
STRING CaseInsensitiveChallengeResponse;
^
/usr/i686-w64-mingw32/sys-root/mingw/include/ntsecapi.h:718:5: error: expected unqualified-id before string constant
STRING AuthenticationInfo1;
^
/usr/i686-w64-mingw32/sys-root/mingw/include/ntsecapi.h:719:5: error: expected unqualified-id before string constant
STRING AuthenticationInfo2;
^
I've googled a little bit but found nothing that would help me this is the same problem as mine. and also this one. But as I've said they didn't help. Hope you can help me. thanks.

Compilation errors with socket bind function

At the very beginning I include the following files and everything goes fine with the bind function
#include "stdafx.h"
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
bind function
iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
Things start messing up when I include the mysql libraries as well
#include "stdafx.h"
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
//mysql connections
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
I started debug and it give me this error
IntelliSense: no suitable conversion function from "std::_Bind<false, void, SOCKET &, sockaddr *&, int>" to "int" exists
error C2440: '=' : cannot convert from 'std::_Bind<false,void,SOCKET &,sockaddr *&,int>' to 'int'
Please help.
I guess the problem is not in including the Mysql library, i got this problem once and i fixed it removing the
using namespace std;
or another solution is to call bind from the global namespace to avoid this kind of problems;
i forgot to write that calling bind from the global namespace is done like this :
::bind(...);
Hope this helps.

reordering includes causes runtime error

One of my script file(.scnp)included the following headers as follows.
#include <stdio.h>
#include "kel.h"
#include "process.h"
#include "sigtypes.h"
#include "ScriptInterface.h"
#include "../saf/SAF_Scripts.h"
This type of header files include gives an error in GDB saying
"symbol lookup error: /xxx/xxxx.so: undefined symbol:
_Z16KEL_MEM_AllocateP19KEL_MEM_tPoolHandlej.
Included file after
#include <stdio.h>
#include "ScriptInterface.h"
#include "kel.h"
#include "process.h"
#include "sigtypes.h"
#include "../saf/SAF_Scripts.h"
ScriptInterface.h
extern "C"
{
#include "kel.h"
#include "process.h"
#if defined()
#include "sigtypes.h"
#endif
}
The scripts run successfully. What could be the problem? I have found the responsible method for this problem by using "c++filt" but don't know how to proceed further. Please help

problem using boost in c++ app

Once I added the following include to my app:
#include <boost/regex.hpp>
It spits out some errors I have no idea what they are about (newbie to c++):
In file included from /usr/include/boost/regex/regex_traits.hpp:27,
from /usr/include/boost/regex/v4/regex.hpp:39,
from /usr/include/boost/regex.hpp:31,
from my_app.c:28:
/usr/include/boost/regex/v4/regex_traits.hpp:80:1: error: macro "test" passed 2 arguments, but takes just 1
/usr/include/boost/regex/v4/regex_traits.hpp:80: error: template declaration of âchar (& boost::re_detail::test)[2]â
/usr/include/boost/regex/v4/regex_traits.hpp:80: error: expected unqualified-id before â...â token
/usr/include/boost/regex/v4/regex_traits.hpp:80: error: expected `)' before â...â token
/usr/include/boost/regex/v4/regex_traits.hpp:80: error: expected `)' before â...â token
/usr/include/boost/regex/v4/regex_traits.hpp:80: error: expected unqualified-id before â(â token
/usr/include/boost/regex/v4/regex_traits.hpp:80: error: âboost::re_detail::has_boost_extensions_tag<T, fallback_>::valueâ is not a valid template argument for type âboolâ because it is a non-constant expression
I installed boost on centos using:
yum install boost boost-devel boost-doc
I compile the app using:
g++ -o my_app my_app.c $(mysql_config --libs --cflags
Headers:
#include <stdio.h>
#include <my_global.h>
#include <mysql.h>
#include <string.h>
#include <stdlib.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <dirent.h>
#include <regex.h>
#include <iterator>
#include <boost/regex.hpp>
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
Can someone help me out?
Is this accidential or are you compiling C code with a C++ compiler?
Try to rename your file to my_app.cc or so to see if that helps.

error C2065: 'socklen_t' : undeclared identifier

The whole error is:
Error 1 error C2065: 'socklen_t' : undeclared identifier c:\users\richard\documents\visual studio 2010\projects\server\server\server.cpp 41 1 Server
This is the problematic line:
int iRcvdBytes=recvfrom(iSockFd, buff, 1024000, 0, (struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);
I have these headers included:
#include <winsock2.h>
#include <windows.h>
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
I have also added WS2_32.lib to the linker in Visual Studio 2010.
What else could cause this problem? I'm just trying to rewrite my simple UDP program to work under Windows.
The socklen_t type is defined inside of WS2tcpip.h in windows. This is not transitively included from winsock2.h (AFAICT). You'll need to include WS2tcpip.h manually in order to use the socklen_t type.
Visual Studio can't find the type socklen_t. MSDN says that this function takes an int* as the last parameter, so cast to that.