views:

74

answers:

4

I have a batch file that tries to compile a static library using Borland C++ Builder 6.0

It is called from Borland make (makefile created with bpr2mak) which is called from a .bat file (used to compile the whole project with Visual Studio and some Borland C++ Builder legacy projects), which is called from a bash shell script running inside Cygwin.

When I run the .bat file directly from a Cygwin shell, it runs OK, but when its being run from a Program calling cygwin with Boost::Process::launcher I'm getting this error:

C:\ARQUIV~1\Borland\CBUILD~1\Bin\..\BIN\TLib /u bclibs.lib @MAKE0000.@@@
DOS-reported error: Bad file number
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
opening 'MAKE0000.@@@'
** error 1 ** deleting bclibs.lib

It's a complicated scenario, but this Program which calls cygwin is run whenever we need to build our software package which needs to be build for various Linux distos and Windows 32 and 64-bit.

Note: It's the only Borland Project failing, the other compile just fine (it's the only static library using borland also, so it can be some problem with the TLib tool.

+1  A: 

I'm just guessing here, but this may have to do with long filenames and/or spaces in paths.

1) Modify your makefile so it would save current environment to a file, immediately before executing the failing command (set > d:\env.txt & echo CD=%CD% >> d:\env.txt). Then run it both ways (directly and via program) and compare the environments of good run and bad run.

2) Using filemon from Sysinternals, capture logs of disk access in both cases (these logs are going to be huge, though you can uncheck everything except Open in the filter to reduce the size). Again, compare and check for clues...

3) Try instaling everything involved to paths conforming to 8.3 scheme.

atzz
For the 1) solution, The only differences are the environment variables set by the program using Boost::Process.
Vargas
A: 

This error is not related to C++ itself. It happens when your build script opens too much files (more than defined in DOS command processor environment). To resolve this issue try to set value of files variable to 253. For Windows XP this variable defined in the file %WINDIR%\system32\config.nt.

files=253
Sergey
I had already tried to set this to a higher value, but it didn't work either, I've set the value to 253 and it stays the same.
Vargas
A: 

Seems it is known bug in Borland C++ tools. Here is description and possible workaround for this issue:

Problem: Some static Lib projects will not link correctly when compiled. You might see something like this :

J:\Borland\CBUILD~1\bin\..\BIN\TLib /u debug\jpegD.lib @MAKE0000.@@@
DOS-reported error: Bad file number
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
opening 'MAKE0000.@@@'

** error 1 ** deleting debug\jpegD.lib
MAKE failed, returned : 1

Workaround : In some cases (where the "Bad file number" error is seen) it may be possible to work around this by specifying -tDEFLIB.BMK in the BPR2MAKE Options field, and Turning off the "Capture Make Output" option.

I have not tested it, but I hope that helps.

Sergey
I've tried this also, it didn't work.
Vargas
+2  A: 

The problem was that TLib does not like to have his output redirected (seen here) without having an input pipe as well. Solved by creating an input pipe to in the Boost::Process::launcher using set_stdin_behavior

Vargas