Mimick icon indicating copy to clipboard operation
Mimick copied to clipboard

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

Open grasmanek94 opened this issue 2 years ago • 0 comments

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 https://github.com/Snaipe/Mimick/pull/11

grasmanek94 avatar Nov 03 '21 14:11 grasmanek94