View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015058CMakeModulespublic2014-08-04 23:042015-01-05 08:39
ReporterNate Eldredge 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformLinux amd64OSUbuntuOS Version13.10
Product VersionCMake 3.0 
Target VersionCMake 3.1Fixed in VersionCMake 3.1 
Summary0015058: CheckIncludeFiles uses old-style function definition
DescriptionThe CheckIncludeFiles module uses a trivial C program that looks like

int main(){return 0;}

Note the absence of a prototype in the definition of main (modern C would use "int main(void)"). If appropriate warning are in effect, gcc will barf on this and cause the CHECK_INCLUDE_FILES test to fail.
Steps To Reproducenate@minerva:~/bugs/cmake$ ls
build CMakeLists.txt
nate@minerva:~/bugs/cmake$ cat CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
INCLUDE (CheckIncludeFiles)
PROJECT (Hello)
SET(CMAKE_C_FLAGS "-Wold-style-definition -Werror")
CHECK_INCLUDE_FILES(stdio.h HAVE_STDIO_H)
nate@minerva:~/bugs/cmake$ cd build
nate@minerva:~/bugs/cmake/build$ /tmp/bin/cmake --version
cmake version 3.0.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).
nate@minerva:~/bugs/cmake/build$ /tmp/bin/cmake ..
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for include file stdio.h
-- Looking for include file stdio.h - not found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nate/bugs/cmake/build

Note that it incorrectly reports that stdio.h was not found. CMakeFiles/CMakeError.log contains:

Determining if files stdio.h exist failed with the following output:
Change Dir: /home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec2688096886/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec2688096886.dir/build.make CMakeFiles/cmTryCompileExec2688096886.dir/build
make[1]: Entering directory `/home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp'
/tmp/bin/cmake -E cmake_progress_report /home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec2688096886.dir/CheckIncludeFiles.c.o
/usr/bin/cc -Wold-style-definition -Werror -o CMakeFiles/cmTryCompileExec2688096886.dir/CheckIncludeFiles.c.o -c /home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
/home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFiles.c: In function ‘main’:
/home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFiles.c:5:5: error: old-style function definition [-Werror=old-style-definition]
 int main(){return 0;}
     ^
cc1: all warnings being treated as errors
make[1]: *** [CMakeFiles/cmTryCompileExec2688096886.dir/CheckIncludeFiles.c.o] Error 1
make[1]: Leaving directory `/home/nate/bugs/cmake/build/CMakeFiles/CMakeTmp'
make: *** [cmTryCompileExec2688096886/fast] Error 2

Source:
/* */
#include <stdio.h>


int main(){return 0;}

Additional InformationI've attached the obvious patch to Modules/CheckIncludeFiles.cmake
TagsNo tags attached.
Attached Filespatch file icon CheckIncludeFiles.patch [^] (625 bytes) 2014-08-04 23:04 [Show Content]

 Relationships

  Notes
(0036551)
Brad King (manager)
2014-08-05 09:15

Applied, thanks:

 CheckIncludeFiles: Use modern C declaration for 'main'
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bf89f910 [^]

From a quick glance all the other checks already use "int main(void)", and only use "int main()" in C++ or when __CLASSIC_C__ is defined (left from an old HP compiler IIRC).
(0037607)
Robert Maynard (manager)
2015-01-05 08:39

Closing resolved issues that have not been updated in more than 4 months

 Issue History
Date Modified Username Field Change
2014-08-04 23:04 Nate Eldredge New Issue
2014-08-04 23:04 Nate Eldredge File Added: CheckIncludeFiles.patch
2014-08-05 09:15 Brad King Note Added: 0036551
2014-08-05 09:15 Brad King Assigned To => Brad King
2014-08-05 09:15 Brad King Status new => resolved
2014-08-05 09:15 Brad King Resolution open => fixed
2014-08-05 09:15 Brad King Fixed in Version => CMake 3.1
2014-08-05 09:15 Brad King Target Version => CMake 3.1
2015-01-05 08:39 Robert Maynard Note Added: 0037607
2015-01-05 08:39 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team