Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The infamous win32 X509_NAME #define problem

262 views
Skip to first unread message

Domingo Kiser

unread,
Oct 16, 2009, 9:11:36 PM10/16/09
to
Hello all,

I am working on porting a linux app that depends on OpenSSL to windows
and ran into the visual studio 2009 "c2226" unexpected type "LPCSTR".
The order of #includes that can generate this error is shown below.
Note that only ssl includes are used. Adding a #undef X509_NAME after
the rand include fixes the problem, BUT only if rand is included
before engine. I looked at both header files and noticed that rand
includes windows.h, which causes the problem. Also, engine.h includes
rand.h. Rand does not use the X509_NAME type within its header
definition, but engine does.

Long story short, I think rand.h should undefine X509_NAME immediately
after its include of windows.h....this seemed to fix my problems. The
other solution was to include rand, undefine the name, then include
engine.

I ran into a previous post on the net to use the NOCRYPT option which
forces visual studio to not include the windows crypto api's, which is
ultimately the culprit in redefining X509_NAME. This worked as well,
but I didn't feel it was the correct solution.

Chime in and let me know if I am off base here or if the rand.h header
fix is a valid one.

Code:
#include <openssl/ssl.h>
#include <openssl/rand.h>
// do the following if proposed fix to rand.h is not there
// this only works if engine.h follows rand.h, at least In
// my initial screwing around
// undef X509_NAME
#include <openssl/engine.h>
#incude <openssl/err.h>
#include <openssl/x503v3.h>
#include <openssl/fips.h>


Cheers,

--Domingo
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org

sandeep kiran p

unread,
Oct 18, 2009, 8:30:32 AM10/18/09
to
Same here. I too faced the same issue when I was trying to build the 'req' utility using Visual Studio. A short list of errors is as below

d:\ssl\openssl-0.9.8k\include\openssl\store.h(390) : error C2059: syntax error : 'type'
d:\ssl\openssl-0.9.8k\include\openssl\store.h(397) : error C2059: syntax error : ','
d:\ssl\openssl-0.9.8k\include\openssl\store.h(397) : error C2143: syntax error : missing ')' before '('
d:\ssl\openssl-0.9.8k\include\openssl\store.h(397) : error C2143: syntax error : missing ')' before '('
d:\ssl\openssl-0.9.8k\include\openssl\store.h(397) : error C2091: function returns function
d:\ssl\openssl-0.9.8k\include\openssl\store.h(397) : error C2091: function returns function
<SNIP>

All these errors seem to crop up because X509_NAME and X509_EXTENSIONS were defined in wincrypt.h. Though we seem to #undef them in x509.h for OPENSSL_SYS_WIN32. Is there any way out?

Thanks,
Sandeep

Domingo Kiser

unread,
Oct 19, 2009, 10:41:34 AM10/19/09
to
I think that fix is fine for the x509.h include chain, but the problem
also exists for the rand.h include chain depending on include order.

--Domingo

0 new messages