[comp.lang.c] TURBO C Linking Problem

smvorkoetter@watmum.waterloo.edu (Stefan M. Vorkoetter) (11/10/87)

I am having problems linking a program with TURBO C.  The program consists
of about 15 source files.  Each and every one compiles, but when I link,
I get an error when CH.LIB is being linked in that there is too much global
data defined in a file.  None of my files defines more than 64K of global
data.  As a matter of fact, the entire program uses less than 64K of global
data.  Unfortunately, it won't even tell me which file is the supposed
culprit.  I have double checked that the model is selected properly, and that
everything else is set right.  I am running under the integrated environment.

By the way, the program I am compiling is a C compiler that I am developing.
Perhaps this is Borland's way of preventing competition :-)

Any help on this matter would be appreciated.  The program compiles fine
under 4.3 BSD.  I am not doing anything the least bit esoteric anywhere.

Thanks in advance,
Stefan Vorkoetter
Symbolic Computation Group
University of Waterloo
(smvorkoetter@watmum.waterloo.edu)

jsin@CS.UCLA.EDU (11/11/87)

I also have a problem linking under TC. I have one file with few procedures,
and the program compiles ok. But when I link the .OBJ file to get .EXE file,
the Linker gives me "module _main unresolved" or some such nonsense.
Of course, main() is in my file and it compiles and runs fine using other
compilers, such as Mark Williams C compiler(I can't afford MSC).

I did get TC to link it using the TLINK (command line linker) finally.
Is this a known bug? Or did I do something wrong?

Thanks to all who respond.
                                                John


John (Jonghoon) Sin
UCLA SEASnet Facilities   ARPA:   jsin@seas.ucla.edu
2567 Boelter Hall         BITNET: jsin%seas.ucla.edu@wiscvm.wisc.edu
Los Angeles, CA. 90025    UUCP:   ...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jsin
(213) 206-6864

jep@oink.UUCP (James E. Prior) (11/13/87)

I have a solution to the TURBO C Linking Problem.

In article <2293@watcgl.waterloo.edu> smvorkoetter@watmum.waterloo.edu (Stefan M. Vorkoetter) writes:
>
>I am having problems linking a program with TURBO C.  The program consists
>of about 15 source files.  Each and every one compiles, but when I link,
>I get an error when CH.LIB is being linked in that there is too much global
>data defined in a file.  None of my files defines more than 64K of global
>data.  As a matter of fact, the entire program uses less than 64K of global
>data.  Unfortunately, it won't even tell me which file is the supposed
>culprit.  I have double checked that the model is selected properly, and that
>everything else is set right.  I am running under the integrated environment.
>
>By the way, the program I am compiling is a C compiler that I am developing.
>Perhaps this is Borland's way of preventing competition :-)
>
>Any help on this matter would be appreciated.  The program compiles fine
>under 4.3 BSD.  I am not doing anything the least bit esoteric anywhere.
>
>Thanks in advance,
>Stefan Vorkoetter
>Symbolic Computation Group
>University of Waterloo
>(smvorkoetter@watmum.waterloo.edu)

I had a similar problem with Turbo C, and have a way of coping with it.

I was working on a program with much data.  I was already using the
compact memory model (64K code, 1M data).  I added more and more
arrays of initialized structures.  Eventually, the linker complained
that I had too much global data.  I split the arrays into many modules,
so that every module was well under 64K of initialized data.  It still
croaked.  I changed from Turbo's TC environment to conventional command
line invokations of tcc and tlink.  Tlink would always croak.  I switched
to the huge model.  It is supposed to handle more than 64K of 
initialized data.  It still croaked, both in the tc environment and by
tcc and tlink.

I finally called Borland's technical support number, and they knew both
the problem and the solution.  The problem is a bug in their tlink
program.  The solution is to use the ordinary link program.  Their
support staff didn't waste anyone's time.  My entire call was under five
minutes.  They were smart.  They asked the right questions.

Following are excerpts from my makefile, that *do* work for me.

# huge memory model: 1M code, 1M data
MODEL=h
CFLAGS=-Ic:\tc -m$(MODEL) -c

jem2set.exe:			\
.
. dependencies omitted
.
	rem tlink /c /m /s ..\c0$(MODEL) @obj.lst, jem2set.exe,, ..\cusrc\a$(MODEL)curses ..\emu ..\math$(MODEL) ..\C$(MODEL)
	\msc4\link /NOI /STACK:4096 /SEGMENT:256 ..\c0$(MODEL) @obj.lst, $*,$*, ..\cusrc\a$(MODEL)curses ..\emu ..\math$(MODEL) ..\C$(MODEL)

BTW, I used Polymake since I have used it for years.  I didn't feel
like messing with Turbo make, so I can't say anything good or bad about
it.

Warning: There are an amazing number of link.exe's by Microsoft.  I used
the one that came with Microsoft C 4.0 .  I doubt that some of the older
versions will work, especially the ones supplied with DOS.
-- 
James E. Prior  {ihnp4|cbosgd}!n8emr!oink!jep

darrylo@hpsrlc.HP.COM (Darryl Okahata) (11/13/87)

In comp.lang.c, smvorkoetter@watmum.waterloo.edu (Stefan M. Vorkoetter) writes:

> I am having problems linking a program with TURBO C.  The program consists
> of about 15 source files.  Each and every one compiles, but when I link,
> I get an error when CH.LIB is being linked in that there is too much global
> data defined in a file.  None of my files defines more than 64K of global
> data.  As a matter of fact, the entire program uses less than 64K of global
> data.  Unfortunately, it won't even tell me which file is the supposed
> culprit.  I have double checked that the model is selected properly, and that
> everything else is set right.  I am running under the integrated environment.
     [ ... ]
> 
> Thanks in advance,
> Stefan Vorkoetter
> Symbolic Computation Group
> University of Waterloo
> (smvorkoetter@watmum.waterloo.edu)
> ----------

     How close to the 64K limit are you?  I don't know what memory model
your are using, but in the small memory model (and one or two other models
whose names I forget), your program's global data, the run-time library
global infomation, and the stack must ALL reside in 64K.  If your program's
global data is close to 64K (or if you've increased the stack size from the
default 2K), then you'll have problems.

     -- Darryl Okahata
	{hplabs!hpccc!, hpfcla!} hpsrla!darrylo
	CompuServe: 75206,3074

Disclaimer: the above is the author's personal opinion and is not the
opinion or policy of his employer or of the little green men that
have been following him all day.

darrylo@hpsrlc.HP.COM (Darryl Okahata) (11/13/87)

In comp.lang.c, jsin@CS.UCLA.EDU writes:

> I also have a problem linking under TC. I have one file with few procedures,
> and the program compiles ok. But when I link the .OBJ file to get .EXE file,
> the Linker gives me "module _main unresolved" or some such nonsense.
> Of course, main() is in my file and it compiles and runs fine using other
> compilers, such as Mark Williams C compiler(I can't afford MSC).
> 
> I did get TC to link it using the TLINK (command line linker) finally.
> Is this a known bug? Or did I do something wrong?
> 
> Thanks to all who respond.
>                                                 John
> 
> 
> John (Jonghoon) Sin
> UCLA SEASnet Facilities   ARPA:   jsin@seas.ucla.edu
> 2567 Boelter Hall         BITNET: jsin%seas.ucla.edu@wiscvm.wisc.edu
> Los Angeles, CA. 90025    UUCP:   ...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jsin
> (213) 206-6864
> ----------

     Did you tell Turbo C to NOT prepend an underscore ("_") to a name?
Normally (i.e., the default action), the compiler prepends underscores to a
name and stores these modified names in the .OBJ file.  I can't remember
the exact details, but, in the integrated environment, there is a compiler
switch (and possibly also a linker switch) under the "Options" menu.  Make
sure that it (they?) are set correctly.

     -- Darryl Okahata
	{hplabs!hpccc!, hpfcla!} hpsrla!darrylo
	CompuServe: 75206,3074

Disclaimer: the above is the author's personal opinion and is not the
opinion or policy of his employer or of the little green men that
have been following him all day.