[CMake] CHECK_TYPE_SIZE works incorrectly with LDFLAGS="-Wl, --gc-sections"

Brad King brad.king at kitware.com
Wed Aug 6 15:05:50 EDT 2008


Arfrever Frehtes Taifersar Arahesis wrote:
> 2008-08-06 14:06:47 Bill Hoffman napisał(a):
>> Arfrever Frehtes Taifersar Arahesis wrote:
>>
>>>> Can you do a find in your build tree and find CMakeError.log?
>>> `find -name CMakeError.log` doesn't return anything.
>>>
>> Can you do this:
>>
>> cmake --debug-trycompile
>>
>> Then tar up and zip the whole thing and email it to me off the list.
> 
> It doesn't contain any private data, so I'm attaching it here.

CMake checks the type size by compiling a source file that encodes a
string literal with the size of the type using the preprocessor.  See
"Modules/CheckTypeSizeC.c.in" for the actual code.  Then the string
literal is parsed out of the compiled file.  This avoids needing to run
the program so the test works for cross compiling.

The trick is to convince the compiler to put the string in the final
binary.  Getting this to happen on all compilers has required a few
iterations.  Basically we have to make sure the program return value
depends on the data.  It looks like we still need a better method to
prevent the string from being removed by --gc-sections.  Try editing
CheckTypeSizeC.c.in in your CMake installation, and replace the line

  return (&info_sizeof[0] != &info_sizeof[0]);

with

  return info_sizeof[0];

Then try building your project again.

-Brad



More information about the CMake mailing list