Friday, May 29, 2015

Compile PHP with unixODBC options

I have XAMPP 1.7 running, with php 5.2.8. Old yes but almost all of my running projects are
built on top of it. Recently i got a project that requires to use MSSQL-SQLEXPRESS.
I chose to use Codeigniter 2.1.2 as the framework to develop. One of teammate is using
MS-Windows environment and he used sqldrv as the database driver with ease.

While my part using GNU/linux Fedora19 64bit having problem. After while searching how to
connect to SQLExpress than the easy answer itu to use FreeTDS and unixODBC. Modify
php.ini of XAMPP 1.7 with no problem. After restart apache and run one of my test_odbc
file shows an error "undefined reference odbc_connect()"

More googling and ends up that i convincing my-self to compile the odbc library from scratch.
So i yum install  unixODBC-devel.i686 and so freetds-devel.i686 then download php 5.2.8
source file from Here. Done the extraction, now to build the extention.

$ pwd
/opt/php5-src/php-5.2.8-src/ext/odbc
$ /opt/lampp/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
configure.in:3: warning: prefer named diversions
configure.in:144: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:2031: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2052: AC_CACHE_CHECK is expanded from...
aclocal.m4:3535: AC_LIBTOOL_LINKER_OPTION is expanded from...
aclocal.m4:5473: _LT_AC_LANG_C_CONFIG is expanded from...
**(And bunch of messages, truncated for simplicity)**
$ sudo yum install glibc-devel.i686
You need the glibc-devel so you can build 32bit application on 64bit system
$ ./configure --with-php-config=/opt/lampp/bin/php-config --with-unixODBC=shared,/usr CFLAGS='-m32'
Then Error that saying
checking for Adabas support... cp: cannot stat '/usr/local/lib/odbclib.a': No such file or directory
configure: error: ODBC header file '/usr/local/incl/sqlext.h' not found!

You could solve this by modifying Makefile that being generated, goto line 4737 and removed
  ext_output="yes, shared"
  ext_shared=yes
  test "$PHP_ADABAS" = "no" && PHP_ADABAS=yes
I don't know what caused the double occurrences that simply override the previous check
and initialization. Re-run the configure
$ make
/bin/sh /opt/php5-src/php-5.2.8-src/ext/odbc/libtool --mode=compile gcc  -I. -I/opt/php5-src/php-5.2.8-src/ext/odbc -DPHP_ATOM_INC -I/opt/php5-src/php-5.2.8-src/ext/odbc/include -I/opt/php5-src/php-5.2.8-src/ext/odbc/main -I/opt/php5-src/php-5.2.8-src/ext/odbc -I/opt/php5-src/include/php -I/opt/php5-src/include/php/main -I/opt/php5-src/include/php/TSRM -I/opt/php5-src/include/php/Zend -I/opt/php5-src/include/php/ext -I/opt/php5-src/include/php/ext/date/lib -I/usr/local/incl  -I/opt/php5-src/include/php -DHAVE_CONFIG_H  -m32   -c /opt/php5-src/php-5.2.8-src/ext/odbc/php_odbc.c -o php_odbc.lo 
 gcc -I. -I/opt/php5-src/php-5.2.8-src/ext/odbc -DPHP_ATOM_INC -I/opt/php5-src/php-5.2.8-src/ext/odbc/include -I/opt/php5-src/php-5.2.8-src/ext/odbc/main -I/opt/php5-src/php-5.2.8-src/ext/odbc -I/opt/php5-src/include/php -I/opt/php5-src/include/php/main -I/opt/php5-src/include/php/TSRM -I/opt/php5-src/include/php/Zend -I/opt/php5-src/include/php/ext -I/opt/php5-src/include/php/ext/date/lib -I/usr/local/incl -I/opt/php5-src/include/php -DHAVE_CONFIG_H -m32 -c /opt/php5-src/php-5.2.8-src/ext/odbc/php_odbc.c  -fPIC -DPIC -o .libs/php_odbc.o
In file included from /opt/php5-src/php-5.2.8-src/ext/odbc/php_odbc.c:37:0:
/opt/php5-src/php-5.2.8-src/ext/odbc/php_odbc_includes.h:74:21: fatal error: WINDOWS.H: No such file or directory
 #include
                     ^
compilation terminated.
make: *** [php_odbc.lo] Error 1

Well at this point is strange if you open the php_odbc_includes.h:74 it says HAVE_ADABAS 
blabla, i just removed all off them until it reaches the #elif ... HAVE_UNIXODBC

$ make 
And success it says
Build complete.
Don't forget to run 'make test'.
   
At this point if you check the modules/ you will see odbc.so sits there, yeah!
I like the manual-way so i just copy and paste on my XAMPP extention folder.
/opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/

Restart the Apache service and run my script yeah! Now it connects like charm :))

Saturday, May 23, 2015

Compiling Antlr2

Compiling Antlr2 with no success. As of this article being written the latest version is 2.7.7.
The source is downloaded and configured but when `make` processing this errors comes in.

>> /usr/bin/make -C lib/cpp/src all                         

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

make[3]: Entering directory `/opt/antlr2/antlr-2.7.7/lib/cpp/src'

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ANTLRUtil.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ASTFactory.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ASTNULLType.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ASTRefCount.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/BaseAST.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/BitSet.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharBuffer.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharScanner.cpp

In file included from /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharScanner.cpp:10:0:

/opt/antlr2/antlr-2.7.7/scripts/../lib/cpp/antlr/CharScanner.hpp:474:30: error: ‘EOF’ was not declared in this scope

  static const int EOF_CHAR = EOF;

                              ^

/opt/antlr2/antlr-2.7.7/scripts/../lib/cpp/antlr/CharScanner.hpp: In member function ‘bool antlr::CharScannerLiteralsLess::operator()(const string&, const string&) const’:

/opt/antlr2/antlr-2.7.7/scripts/../lib/cpp/antlr/CharScanner.hpp:565:41: error: ‘strcasecmp’ was not declared in this scope

   return (strcasecmp(x.c_str(),y.c_str())<0 p="">                                         ^



xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

                      >> E R R O R <<

============================================================



g++ -O2 -DNDEBUG -felide-constructors -pipe -c  -I . -I /opt/antlr2/antlr-2.7.7/scripts/../lib/cpp /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharScanner.cpp



============================================================

Got an error while trying to execute  command  above.  Error

messages (if any) must have shown before. The exit code was:

exit(1)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

make[3]: *** [/opt/antlr2/antlr-2.7.7/lib/cpp/src/CharScanner.o] Error 1

make[3]: Leaving directory `/opt/antlr2/antlr-2.7.7/lib/cpp/src'

make[2]: *** [all] Error 1

make[2]: Leaving directory `/opt/antlr2/antlr-2.7.7/lib/cpp'

make[1]: *** [all] Error 1

make[1]: Leaving directory `/opt/antlr2/antlr-2.7.7/lib'

make: *** [all] Error 1

Includes some headers fixed the problems. Open the CharScanner.cpp and put this at the header.

#include   >fstream<
#include   >strings.h< // before
#include   >antlr/config.hpp<
// and

#include >antlr/exersharedinputstate.hpp< // after
#ifndef EOF
    #define EOF     std::ifstream::traits_type::eof()
#endif

Run `make clean` and the `make; make install`. Compile success, Yeah!

Saturday, May 9, 2015

Compile C++ BOOST Example

Playing around with Boost 1.58 library, i need to experience the compile and run the examples.
I go into libs/serialization/examples/ run b2 hummm seems to build everything. So give it a try
to compile it "by-hands"

$ pwd

/opt/c++/boost_1_58_0/libs/serialization/example

$ export LD_LIBRARY_PATH=/opt/c++/boost_1_58_0/stage/lib:$LD_LIBRARY_PATH

$ c++ demo.cpp -o demo -L /opt/c++/boost_1_58_0/stage/lib -lboost_serialization-mt

$ ./demo

** Throws some log meaning the application compiled and run successfully


Hurray!