Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including in a cmake project with C standard 11 directive makes this project not compile #28

Open
grasmanek94 opened this issue Nov 3, 2021 · 0 comments

Comments

@grasmanek94
Copy link

grasmanek94 commented Nov 3, 2021

We encountered an issue where we could build the library separately, but including it into our project made it fail to compile.

The way we include the library (simplified form multiple cmake files into one working example):

CMakeLists.txt:

cmake_minimum_required(VERSION 3.13)

project(proj LANGUAGES C VERSION 0.1)

set(CMAKE_C_STANDARD 11)

add_subdirectory(libraries/mimick/)

set(TEST_SOURCES
  main.c
  test.c
)

add_executable( Test ${TEST_SOURCES} )

target_include_directories( Test PRIVATE . )
target_link_libraries( Test mimick )

This would cause multiple weird errors when building the library. To fix this we changed the mimick CMakeLists.txt:

(...)
project (Mimick C)

set(CMAKE_C_STANDARD 99) # this has been added

(...)

add_library (mimick STATIC ${SOURCE_FILES})
target_include_directories(mimick PUBLIC include) # this has been added

(...)
  • We forced the C standard to C99
  • We exposed the include directories from the library, so projects that link to mimick can use the include directories automagically.

This fixes the following errors:

  • fatal error: mimick.h: No such file or directory
  •  In file included from mimick/src/core.c:32:
     mimick/src/vitals.h:47:13: error: expected ‘;’ before ‘void’
        47 | mmk_noreturn void mmk_panic(const char *, ...);
           |             ^~~~~
           |             ;
    
    

It looks like the include directories issue has been addressed in PR #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant