X509_NAME macro in C won't compile - c

This is a silly compilation error, but for the life of me I can't find out what's wrong. I have spent hours on it, but I have made no progress at all. And I certainly don't understand enough about OpenSSL to understand what an X509_NAME is.
I'm compiling a small C file whose function it is to print out an error message if anyone calls one of the 30 or so functions in the file, to indicate that the 30 SSL functions are not supported by the C program. Each function is about 3 lines long (see below). The calling interface is copied from the OpenSSL openssl/X509.h file for win32. (I'm running Windows10 x64, but compiling with VStudio 2017 command line set up for 32bits).
Here is the original interface from the openssl/x509.h include file:
int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len);
Since the original x509.h include file says inside that "the definition for X509_NAME on Win32 is located in wincrypt.h," I copied the definition for the X509_NAME macro directly into my source file as shown below.
The code for my simple error message function follows. I just copied the interface definition from the openssl/x509.h file and made it into a function:
#define X509_NAME ((LPCSTR) 7) /* copied from wincrypt.h */
int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) {
print_error (E_NO_SSL_SUPPORT);
return (-1);
}
When I try to compile the code with the VS 2017 command line compiler for 32bits, I get these error messages. Line 236 contains the troublesome code line int X509_NAME_....
cl /c /Od /nologo /MT /I. "-I..\s" ..\s\stubssl.c
stubssl.c
..\s\stubssl.c(236): error C2143: syntax error: missing ')' before '('
..\s\stubssl.c(236): error C2091: function returns function
..\s\stubssl.c(236): error C2059: syntax error: ')'
..\s\stubssl.c(236): error C2143: syntax error: missing ')' before 'constant'
..\s\stubssl.c(236): error C2143: syntax error: missing '{' before 'constant'
..\s\stubssl.c(236): error C2059: syntax error: 'constant'
..\s\stubssl.c(242): error C2059: syntax error: '<parameter-list>'
c:\stubssl\winxp\make.exe: *** [stubssl.obj] Error 2
I get the same kind of error with another function that is a bit simpler (but that also uses the X509_NAME macro). It starts on line 242 (see the error messages above).
X509_NAME *X509_get_subject_name(X509 *a) {
hio_oerror (E_NO_SSL_SUPPORT);
return (NULL);
}
Does anyone have any idea how I might try to resolve this problem? It seems so simple, yet it has been very elusive for me to solve. I can't imagine how I can be missing ')' before '(' in those lines.
EDIT: My include files in stubssl.c:
#define WIN32_LEAN_AND_MEAN
#include "openssl/ssl.h"
#include "openssl/x509.h"
#include "openssl/bio.h"
#include "openssl/pem.h"

In openSSL, X509_NAME is a type, but <wincrypt.h> defines it as a value (((LPCSTR) 7)). Don't define it yourself, but use the openSSL header, don't include <wincrypt.h> and #define WIN32_LEAN_AND_MEAN to avoid it being included through other windows headers.

Related

Error C2061: syntax error: identifier BLOBHEADER though wincrypt.h is included

I have a struct in C, but I'm encountering a syntax error stating:
C:\sv62w8\pc\sales\src\main\custom.c(2179) : error C2061: syntax error : identifier 'BLOBHEADER'
Here's my code:
sample.c
#include <windows.h>
#include <wincrypt.h>
//...more codes
struct ENCRYPT_KEY_STRUCT_TYPE {
BLOBHEADER sample_variable;
} EncryptKeyStruct;
//...more codes
By the way, I'm using Microsoft Visual C++.
Thanks!

GCC error: expected ‘)’ before <function protoyprmeter> parameter

In a header file
extern void Trace_Communication(communicationBlock_t mdbMessage);
gives error: expected ‘)’ before ‘mdbMessage’
I am sure that communicationBlock_t is in scope (and reliaze that it would be more efficient to pass a pointer)
If I copy the declaration of communicationBlock_t just before the extern offending line, the error is
error: conflicting types for ‘communicationBlock_t’
note: previous declaration of ‘communicationBlock_t’ was here
Which seems to imply that the offending line has access to the declaration of communicationBlock_t
I guess that I am overlooking something trivial and obvious, but I have been coding all night and can no longer think straight ...
What am I doing wrong? Thanks 1 ,000,000
Update: my guess is that it's an include file tangle ...
typedef struct
{
communicationMessage_t message;
uint8_t length;
#ifdef TESTING
char commandName[32]; // for testing porpoises
DoRunTimeChecks runTimeCheckCallback;
#endif
} communicationBlock_t;
Looks to me like you're using a variable as a type name. What does the declaration of communicationBlock_t look like?
Sorry, folks. It was, as I suspected a deady embrace in #include files

typedef definition not found

I can't figure why the following code gives compilation error as if the typedef definition not found. In fact, if I add the line 'typedef TCHAR my_tchar;' (which is already in win32def.h) in app.h the compilation goes well.
win32def.h
#ifndef win32def_h
#define win32def_h
#include <tchar.h>
typedef TCHAR my_tchar;
#endif
app.h
#include "win32def.h"
int my_function(const my_tchar *filename, ....)
compilation error at line of my_function:
error C2143: syntax error : missing ')' before '*'
what the compiler is used?
I'm not sure, but try to turn on the option "treat wchar_t as built-in type".

C visual studio undeclared identifier for define

Hello i have the following code..
#define VB_CHAR signed char
#define VB_UCHAR unsigned char
#if defined(VBISAM_NO_CISAM_CONFLICT)
#include "vbisam_rename.h"
#endif
#include "vbdecimal.h"
vbdecimal doesnt include any other header but fails to see it
Error 1 error C2065: 'VB_CHAR' : undeclared identifier c:\users\parhs\documents\visual studio 2010\projects\testdll4\vbdecimal.h
I have to define VB_CHAR in vbdecimal in order to work..
Any work-around for this?
Well. It could be that vbisam_rename.h '#undefs' VB_CHAR.

C error expected specifier-qualifier-list before ‘time_t’

I got the error
from error.c:31:
/usr/include/ap/mas.h:254: error: expected specifier-qualifier-list before ‘time_t’
make: *** [error.o] Error 1
Feedback
We at least need to see line 31 of error.c and line 254 of mas.h, with preferably a few lines of context around each. This error may have nothing to do with how time_t is being declared. – John Bode
Then I check
in error.c (line no 31) -- #include "mas.h"
then I check line no 254 in mas.h.
in mas.h
#include <sys/types.h>
typedef struct _x{
time_t time;
}x;
Can anybody suggest where I am going wrong?
Have you #included <time.h>?
You need to include time.h before including mas.h.

Resources