Building ruby-odbc on OpenBSD 3.8
Posted by Nicholas Tue, 26 Dec 2006 21:26:00 GMT
Today I was stuck with the unusually frustrating task of trying to get the ruby-odbc bridge to build on OpenBSD 3.8.
After a seemingly illogical amount of time spent fighting with extconf.rb, to recognize the ever ‘missing header files’ that could be found in /usr/local/include. These header files were sql.h, sqltypes.h, sqlext.h, odbcinst.h, and odbcinstext.h.
After ‘forcing’ the inclusion of these files, I was faced with another rather interesting issue. A stream of extraordinarily unhelpful errors, like the following exert, forced me to do a bit of digging.
gcc -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.8/i386-openbsd3.8 -I/usr/local/lib/ruby/1.8/i386-openbsd3.8 -I. -DHAVE_SQL_H -DHAVE_SQLEXT_H -DHAVE_ODBCINST_H -c odbc.c
In file included from odbc.c:33:
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:119: error: syntax error before "LPCSTR"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:124: error: syntax error before "LPCSTR"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:126: error: syntax error before "LPSTR"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:135: error: syntax error before "lpszInfFile"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:140: error: syntax error before "lpszPath"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:143: error: syntax error before "lpszBuf"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:146: error: syntax error before "lpszInfFile"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:151: error: syntax error before "WORD"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:155: error: syntax error before "lpszDSN"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:157: error: syntax error before "lpszDSN"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:158: error: syntax error before "lpszDSN"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:160: error: syntax error before "lpszSection"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:165: error: syntax error before "lpszSection"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:173: error: syntax error before "lpdwUsageCount"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:174: error: syntax error before "lpszInfFile"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:182: error: syntax error before "lpszTranslator"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:184: error: syntax error before "lpszDriver"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:188: error: syntax error before "WORD"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:235: error: syntax error before "WORD"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:240: error: syntax error before "DWORD"
/usr/local/lib/ruby/1.8/i386-openbsd3.8/odbcinst.h:244: error: syntax error before "WORD"
odbc.c: In function `conf_dsn':
odbc.c:1326: error: `WORD' undeclared (first use in this function)
odbc.c:1326: error: (Each undeclared identifier is reported only once
odbc.c:1326: error: for each function it appears in.)
odbc.c:1326: error: syntax error before "op"
odbc.c: At top level:
odbc.c:1333: error: syntax error before '(' token
odbc.c:1261:1: unterminated #ifdef
*** Error code 1
Stop in /usr/src/ruby-odbc-0.996.
Now a mess like this requires a bit of detective work. I started out by checking for the obvious errors. When none of my ideas solved my problem, I pinned the issue down to missing typedefs. After some investigation, I found out that the ‘windows.h’ header file that’s included with cygwin contains all of the missing typedefs. As quick as a bunny I opened ‘sqltypes.h’ and added the following directly above the ‘SQL portable types for C’ block comment:
#ifndef WIN32 typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef DWORD * LPDWORD; typedef char * LPSTR; typedef const char * LPCSTR; #ifndef BOOL typedef int BOOL; #endif #endif
As endlessly frustrating as today was, I hope this information can be of some use to somebody else. Now that it’s all said and done, and I can connect to sql server from openbsd, I’m a happy chappy. A day well spent I’d say.