"Too Many Segments" LINKing More than 128 Modules (45165)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1

This article was previously published under Q45165

SUMMARY

The linker error message L1049, "Too many segments," occurs when you are trying to LINK more than 128 modules into an .EXE program or a Quick library. The default number of segments for LINK.EXE is 128. To correct this problem, combine two or more of the modules (the .BAS source files).

If the modules are too large to combine, you must set the number of segments to more than 128 with the /SEGMENTS linker option. While /SEGMENTS:3072 is the highest allowed value in the LINK syntax, the true practical limit is about 1300 to 1500. If you compile and link within the QuickBasic environment instead of from the DOS command prompt, you can set the /SEGMENTS option by including the following line in your AUTOEXEC.BAT file:
   set link=/segments:<number of segments>
				
Note that there is no space before or after the = (equal sign). (If this fails, add one space after the equal sign.)

This information applies to Microsoft QuickBasic versions 4.0, 4.0b, and 4.5; to Microsoft Basic Compiler versions 6.0 and 6.0b; and to Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1.

MORE INFORMATION

To determine the number of segments you are generating, use the following guidelines. A module in QuickBasic is exactly the same as a .BAS file. Each module compiles to one code segment. All of the data in the program is combined at LINK time into one single data segment. There is only one data segment, no matter how many modules you compile; therefore, the number of segments is as follows:

NumberOfSegments = [number of .BAS files you start with] + 1

If you are using a library, each .BAS file that was compiled and put into the library must be included in the above formula.

The "Too many segments" error message can also occur when using the BUILDRTM utility of Basic 6.0 and 6.0b and Basic PDS 7.0 to combine more than 128 modules into a run-time module. This happens because BUILDRTM.EXE uses LINK.EXE to create a run-time module. The workarounds are the same as above; combine one or more modules or SET the LINK environment variable.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB45165