Total image size exceeds max

The warning you’re seeing, LNK4084: total image size exceeds max, indicates that the total size of your application exceeds the allowed limit set by the linker, which is 268,435,456 bytes (256 MB). This can happen in large applications …

warning LNK4084: total image size 526815232 exceeds max (268435456); image may not run

Hi @OURADA, welcome to the community! :blush: It’s great to see you here!

To help others better understand your issue and provide you with the best possible support, you might consider editing your post to make it a bit clearer. Here are a few tips:

  1. Use a Descriptive Title: A concise and descriptive title helps attract people familiar with the issue. For example, you could use something like:
    “LNK4084 Warning: Total Image Size Exceeds Limit”

  2. Format the Error Message: You can format your error message as a code block to make it easier to read. Simply wrap it in triple backticks (```), like this:

image

  1. Provide Context: Adding some context about the situation will help others diagnose the issue. For example:

    • What platform or development environment are you using?
    • What were you trying to do when you encountered this error?
    • Any relevant code snippets or configurations?
  2. Set the Category: If you’re looking for help, you can update the category of your post to Help so that others know you’re seeking assistance.

You can edit your post by clicking the pencil icon below it.

Thanks for contributing, and we’re here to help! :blush:

I can (probably) answer the intended question.

Windows has a hard 2GB limit on code and static data. (the limit is actually a bit below 2GB), even on 64-bit platforms. This is due to the design of the Windows EXE format. If the linker sees more than this amount of code and static data, you’ll get this error. Sometimes the linker won’t complain but the executable still will not run.

By “static data” I primarily mean, for Fortran, COMMON blocks. People sometimes declare enormous arrays in COMMON and trigger this problem. The usual solution is to make these arrays ALLOCATBLE instead and allocate them to the desired size at the beginning of execution. (That is, after you think about whether you really need arrays that big.) Keep in mind that this is the total size of the arrays, so if you have several that are, say, 500MB each, you can hit this restriction.

Linux has the option -mcmodel which can be set to medium or large, allowing larger static data (large allows more than 2GB code as well), but Windows does not.

@sblionel

Silverfrost FTN95 /64 Windows compiler has conveniently removed this restriction for non-initialised arrays.

The main value of 64-bit compilation is that the available address space has increased 
from 4GB to approximately 1.8 x 10^19 bytes! This means that for the foreseeable future 
(possibly forever!), the size of programs will be limited only by the amount of physical 
memory available on a system.

Arrays that are ALLOCATEd, or which are in COMMON or in MODULEs can exceed the 4GB 
limit, except that initialised arrays must fit within the .EXE or .DLL file to which 
they belong, and the the size of these files cannot extend beyond the 4GB limit. 
This is a Microsoft limit, but is fairly reasonable, since the time needed to load a 4GB 
file would be excessive!

COMMON blocks and MODULE arrays are allocated dynamically as a program starts in order to 
enjoy no 4GB restrictions. This is applied to all such storage blocks, because a program 
may exceed the 4GB limit even though each individual array lies within this limit.

This provides a useful extension for legacy codes.

1 Like

But the reported size here is about 500MB…

This reported figure can be inaccurate if the total size overflows a 32-bit integer. To be honest, I had not noticed before that the max reported is only 256MB - I suspect that this message hasn’t been updated in a while.