Building PostgreSQL client library using Borland C++ Compiler (BCC) under WinXP

Preface

We already know how to build client library for PostgreSQL using MinGW from my previous post.

Today we’re going to play with Borland C++ Compiler (which is free by the way). Some people might find this very useful. Actually it was fun, for me it was some kind of a puzzle.

Installing BCC

You can download Borland C++ Compiler from here. Run installer. By default C:BorlandBCC55 path is used. I assume you used default path.

At last, you need to add C:BorlandBCC55Bin value to system PATH variable.

Getting sources

I decided to use fresh 8.4beta sources instead of official released 8.3 branch. Thus I need to get them using CVS. Comprehensive manual “Getting The Source Via Anonymous CVS” is a part of PostgreSQL documentation.

In my case E:pgsql is the repository folder.

Show Time!

According to PostgreSQL manual building client library using BCC is a two step action:

  • change current directory to the src
  • $ cd E:pgsqlsrc
  • and executing command:
  • $ make -N -DCFG=Release /f bcc32.mak

Let’s check output:

E:pgsql>cd src

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak
MAKE Version 5.3  Copyright (c) 1987, 2008 CodeGear
        cd include
        if not exist pg_config.h copy pg_config.h.win32 pg_config.h
        1 file(s) copied.
        if not exist pg_config_os.h copy portwin32.h pg_config_os.h
        1 file(s) copied.
        cd ..
        cd interfaceslibpq
        make -N -DCFG=Release /f bcc32.mak
MAKE Version 5.3  Copyright (c) 1987, 2008 CodeGear
You must edit bcc32.mak and define BCB at the top
Fatal bcc32.mak 12: Error directive: misssing BCB

** error 1 ** deleting ALL

Frak! One more step.

Open E:pgsqlsrcinterfaceslibpqbcc32.mak in your favorite text editor and change

# BCB=c:BorlandBcc55

line to

BCB=c:BorlandBcc55

So, we uncommented line where BCB variable defined and check appropriate path.

Repeat from the beginning:

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak
...

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
....portdirent.c:
Error E2451 ....portdirent.c 35:
Undefined symbol 'INVALID_FILE_ATTRIBUTES' in function opendir

...

What the fudge!

One more step

As you can see compiler have no idea what INVALID_FILE_ATTRIBUTES is. OK, we’ll teach it. Open E:pgsqlsrcportdirent.c and add these lines after includes:

#if !defined (INVALID_FILE_ATTRIBUTES)
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#endif

One more try:

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak
...

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
....portdirent.c:
Error E2451 ....portdirent.c 56:
  Undefined symbol 'dirname' in function opendir

...

Oh, not again!

And one more step

Frankly speaking I spent almost three hours trying to fix this. And when I was ready to gave up suddenly solution came from the Internet. Do not remember where I read it, however that article have nothing common with PostgreSQL or BCB stuff, as like as chalk and cheese. Anyway. The idea was to exclude header file with the same name shipped with compiler from compiling.

Indeed. There is dirent.h header in the C:BorlandBCC55Include folder. Let’s just renamed it to _dirent.h.

Let’s make it:

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak
...

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
....portopen.c:
Error E2451 ....portopen.c 88: Undefined symbol 'O_RANDOM' in function pgwin32_open
Error E2451 ....portopen.c 89: Undefined symbol 'O_SEQUENTIAL' in function pgwin32_open
Error E2451 ....portopen.c 90: Undefined symbol '_O_SHORT_LIVED' in function pgwin32_open
Error E2451 ....portopen.c 91: Undefined symbol 'O_TEMPORARY' in function pgwin32_open

...

Heh! Why I’m not even surprised? 🙂

And even one more step

Have no idea why, but compiler complains on undefined symbols. I checked fcntl.h and didn’t find these constants. OK, let’s make it happy. Edit E:pgsqlsrcportopen.c file. Add these lines after includes:

#ifndef O_RANDOM

#define O_RANDOM                0x0010  // File access is primarily random
#define O_SEQUENTIAL            0x0020  // File access is primarily sequential
#define O_TEMPORARY             0x0040  // Temporary file bit
#define O_SHORT_LIVED           0x1000  // Temporary storage file, try not to flush
#define _O_SHORT_LIVED           O_SHORT_LIVED

#endif

Let’s make it:

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak

Despite the numerous warnings we have one fatal error remain:

...
Fatal: 'libpq-dist.rc' does not exist - don't know how to make it
...

The Final Step?

Nobody knows what libpq-dist.rc is… but libpq.rc.in is present at E:pgsqlsrcinterfaceslibpq. Rename it.

In God we trust:

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak
...
Borland Resource Compiler  Version 5.40
Copyright (c) 1990, 1999 Inprise Corporation.  All rights reserved.
Fatal: 'blibpqdll.def' does not exist - don't know how to make it
...

The Final Step!

I’m seek and tired of this puzzle. 🙂 I found 4-year old blibpqdll.def. And put it to E:pgsqlsrcinterfaceslibpq.

The last chance:

E:pgsqlsrc>make -N -DCFG=Release /f bcc32.mak

MAKE Version 5.3  Copyright (c) 1987, 2008 CodeGear
        cd include
        if not exist pg_config.h copy pg_config.h.win32 pg_config.h
        if not exist pg_config_os.h copy portwin32.h pg_config_os.h
        cd ..
        cd interfaceslibpq
        make -N -DCFG=Release /f bcc32.mak
MAKE Version 5.3  Copyright (c) 1987, 2008 CodeGear
Building the Win32 DLL and Static Library...

Configuration "Release"

        brcc32.exe -l 0x409 -ic:BorlandBcc55include
             -fo".Releaselibpq.res" libpq-dist.rc
Borland Resource Compiler  Version 5.40
Copyright (c) 1990, 1999 Inprise Corporation.  All rights reserved.
        ilink32.exe @MAKE0000.@@@
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
        implib -w ".Releaseblibpqdll.lib" blibpqdll.def ".Releaseblibpq.dll"

CodeGear Implib Version 3.1.0 Copyright (c) 1991-2007 CodeGear
Name: 'blibpqdll' Ext: '.dll' Base: 0x00000000
Name: 'BLIBPQ' Ext: '.dll' Base: 0x00000000
        cd ....
        echo All Win32 parts have been built!
All Win32 parts have been built!

Yahoo!

It’s alive! Alive!

The conclusion is: you must be the Master of Drums and Whistles to build PostgreSQL client library using Borland C++ Compiler. We have abnormal tendency here. There is only one compiler under Windows which may be used for PostgreSQL sources compiling – MS Visual Studio. Meanwhile using MinGW (GCC) and Borland C++ Compiler associated with troubles.

I want to appeal to PostgreSQL community for help. I think it is very important that open-source PostgreSQL database may be compiled with free compilers like MinGW (GCC) and Borland C++ Compiler.

Regards.

14 thoughts on “Building PostgreSQL client library using Borland C++ Compiler (BCC) under WinXP

  1. seriously ? who uses borland anyway ?
    few folks from austria, germany and czech rep I know, and that’s about it…
    Come on, world has moved since, lets be honest, whole borland stuff was a pile of crap. Didn’t stand test of time.
    Why support it ?
    Maybe we should support also bunch of other random unix c compilers ?

    Like

    1. Well, I don’t mind if PostgreSQL community will discontinue BCC support. But as I can see there IS chapter in manual where BCC support is stated.

      And what about MinGW? How much Billy paid for MSVC to be the only compiler for PG under Windows? 😉

      Like

      1. Trust me, “Billy” hasn’t paid anything for the work done to move toward MSVC; that decision has been made by the active developers who work in the Windows space, who find the MinGW tools hard to work with and not as effective.

        Note we do have current MinGW buildfarm member (although no Borland member), so it isn’t like that platform is abandoned at all. If you’re willing to help with any troubles that arise, I’m sure it would be appreciated.

        Like

  2. There is an express version of Visual Studio which is free. I can’t imagine why you would want to use something different.

    Like

  3. Thanks for the work you did. I have been bulding libpq with Borland C++ for my pgtcl-ng project (see pgfoundry.org) for a number of years now. Since bcc32.mak is not supported by the core developers, I usually needed to apply patches for each PostgreSQL release. Thanks to your patch submission, I was able to build the PostgreSQL-8.4.0 release of libpq from the unmodified sources. And it passed my pgtcl test suite so I know it works.

    Like

Leave a reply to pashagolub Cancel reply