Skip to content

C flags when not building tests  #7

Closed

Description

@codebot

I ran across this while building c_utilities on gcc 4.9.2:

[ 12%] Building C object CMakeFiles/c_utilities.dir/src/cmdline_parser.c.o
/home/chip/sros2/src/ros2/c_utilities/src/cmdline_parser.c: In function ‘cli_option_exist’:
/home/chip/sros2/src/ros2/c_utilities/src/cmdline_parser.c:22:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (size_t i = 0; i < (size_t)(end - begin); ++i) {
   ^
/home/chip/sros2/src/ros2/c_utilities/src/cmdline_parser.c:22:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
CMakeFiles/c_utilities.dir/build.make:62: recipe for target 'CMakeFiles/c_utilities.dir/src/cmdline_parser.c.o' failed
make[2]: *** [CMakeFiles/c_utilities.dir/src/cmdline_parser.c.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/c_utilities.dir/all' failed
make[1]: *** [CMakeFiles/c_utilities.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

I think this is because the line specifying C11 is here:
https://github.com/ros2/c_utilities/blob/master/CMakeLists.txt#L35
which is only executed when tests are being built. If a build is kicked off without tests, it fails (or at least it did for me). Moving the CMAKE_C_FLAGS and CMAKE_CXX_FLAGS definitions up in the file (outside the if (BUILD_TESTING) block) allowed the build to work for me.

Activity

  1. mikaelarguedas commented on Apr 2, 2017

    @mikaelarguedas
    Member

    that is a good point, I tried to address this on the compile_options branch but didn't have time to test it or open a PR accordingy.

    Although MSVC doesn't support it IIRC so all c code declare loop variable beforehand, very surprised that this passed on windows in the first place o_O. So unless MSVC is now c99 compliant 🎉 , I think that the c code should also be modified to declare size_t i; before the for loop.

  2. wjwwood commented on Apr 2, 2017

    @wjwwood
    Member

    Yeah, since MSVC doesn't support C11 I don't think we should try and turn it on. We don't need it really anyways. As @mikaelarguedas said, I think the code should be updated to declare the i outside the loop.

  3. codebot commented on Apr 2, 2017

    @codebot
    MemberAuthor

    implemented in #8

  4. dirk-thomas commented on Apr 3, 2017

    @dirk-thomas
    Member

    The code itself (not the tests) should be compiled with all warnings enabled. Currently that is still not the case (only when tests are enabled).

  5. added a commit that references this issue on Apr 20, 2019
  6. added a commit that references this issue on Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions