[CMake] try using the "-03" option to gcc

Michael Wild themiwi at gmail.com
Wed Dec 23 04:02:36 EST 2009


On 23. Dec, 2009, at 9:56 , Water Lin wrote:

> Michael Wild <themiwi at gmail.com> writes:
> 
>> On 23. Dec, 2009, at 9:22 , Water Lin wrote:
>> 
>>> 
>>> I am trying to use the "-03" option to gcc. But after I use
>>> --------------------
>>> add_definitions(-03)
>>> --------------------
>>> 
>>> in CMakeLists.txt file and generate the Makefile, I make the project and
>>> gcc provides me a info:
>>> -----------
>>> c++: unrecognized option '-03'
>>> -----------
>>> 
>>> How can I add "-03" option by CMakeLists.txt?
>>> 
>>> Thanks
>>> 
>>> Water Lin
>> 
>> That's because the options is not called -03 ("dash zero three") but -O3 ("dash big-ooh three").
>> 
>> And you shouldn't do that anyways. Rather set the CMAKE_BUILD_TYPE option to "Release" in your cache (NOT the CMakeLists.txt file). E.g. if you're using the command line:
>> 
>> cmake -DCMAKE_BUILD_TYPE=Release /path/to/source
> 
> Do you mean that if I set -DCMAKE_BUILD_TYPE=Release, I will get the -O3
> option?
> 
> I tried it, it seems work that way. But while I run my code, it will get
> a segmentation fault.
> 
> Is this the correct way?
> 
> Thanks
> 
> Water Lin

Well, the segmentation fault is almost surely a programming error and nothing that CMake (close to impossible) or your compiler (very unlikely, but possible) caused. Does the program run if you don't use -O3? That usually indicates that you are messing with your memory (i.e. writing/reading past array boundaries, referring to deallocated objects/variables, etc.). On Linux you can use the tool called valgrind to find such errors.

Michael



More information about the CMake mailing list