I am trying to get running the GPIO_EXTI example from the STM32Cube_FW_F4_V1.24.0 using CMake and the actual GNU Tool Chain Version 9_2019_q4_major on Windows via Cygwin Terminal.
The Project shall run on the STM32F4-DISCOVERY board.
I have a CMakeLists.txt file, which based on Cmake File.
cmake_minimum_required (VERSION 3.5)
project(F4cmake)
enable_language(C ASM)
SET(TARGET F4cmake)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR arm)
# SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_definitions(-DSTM32F407xx)
add_definitions(-DUSE_STM32F4_DISCO)
add_definitions(-DUSE_HAL_DRIVER)
add_definitions(-D__MICROLIB)
add_definitions(-D_RTE_)
SET (STARTUP D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S)
message (STATUS "[DBG]: ${STARTUP}")
SET(SYSTEM D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/system_stm32f4xx.c)
SET(HAL_PATH D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver)
SET (CMSIS_SRCS
# ${CMAKE_CURRENT_SOURCE_DIR}/../../../Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_gcc.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_armcc.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_compiler.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_version.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/core_cm4.h
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/mpu_armv7.h
${HAL_PATH}/Src/stm32f4xx_hal_pwr.c
${HAL_PATH}/Inc/stm32f4xx_hal_pwr.h
${HAL_PATH}/Src/stm32f4xx_hal_cortex.c
${HAL_PATH}/Inc/stm32f4xx_hal_cortex.h
${HAL_PATH}/Src/stm32f4xx_hal_gpio.c
${HAL_PATH}/Inc/stm32f4xx_hal_gpio.h
${HAL_PATH}/Src/stm32f4xx_hal_flash.c
${HAL_PATH}/Inc/stm32f4xx_hal_flash.h
${HAL_PATH}/Src/stm32f4xx_hal_spi.c
${HAL_PATH}/Inc/stm32f4xx_hal_spi.h
${HAL_PATH}/Src/stm32f4xx_hal_rcc.c
${HAL_PATH}/Inc/stm32f4xx_hal_rcc.h
${HAL_PATH}/Src/stm32f4xx_hal_flash_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_flash_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_rcc_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_rcc_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_i2c.c
${HAL_PATH}/Inc/stm32f4xx_hal_i2c.h
${HAL_PATH}/Src/stm32f4xx_hal.c
${HAL_PATH}/Inc/stm32f4xx_hal.h
${HAL_PATH}/Src/stm32f4xx_hal_pwr_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_pwr_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_dma.c
${HAL_PATH}/Inc/stm32f4xx_hal_dma.h
${HAL_PATH}/Src/stm32f4xx_hal_i2c_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_i2c_ex.h
)
SET (BSP_SRCS
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.h
)
message (STATUS "[DBG]: ${BSP_SRCS}")
SET (APP_SRCS
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/stm32f4xx_it.c
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_hal_conf.h
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h
)
message (STATUS "[DBG]: ${APP_SRCS}")
include_directories (
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src
D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include
D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include
)
set_source_files_properties(D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S PROPERTY LANGUAGE C)
SET (LINKER_SCRIPT D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld)
message (STATUS "[DBG]: ${LINKER_SCRIPT}")
SET(USER_SOURCES ${STARTUP} ${SYSTEM} ${CMSIS_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
message(STATUS "[DBG]: ${USER_SOURCES}")
SET(COMPILER_PATH C:/GnuToolChain/9_2019_q4_major/bin)
SET(CMAKE_ASM_COMPILER "${COMPILER_PATH}/arm-none-eabi-as")
SET(CMAKE_C_COMPILER "${COMPILER_PATH}/arm-none-eabi-gcc")
SET(CMAKE_CXX_COMPILER "${COMPILER_PATH}/arm-none-eabi-g++")
SET(CMAKE_C_LINK_EXECUTABLE "${COMPILER_PATH}/arm-none-eabi-ld")
SET(CMAKE_OBJCOPY "${COMPILER_PATH}/arm-none-eabi-objcopy")
SET(CMAKE_OBJDUMP "${COMPILER_PATH}/arm-none-eabi-objdump")
SET(CMAKE_SIZE "${COMPILER_PATH}/arm-none-eabi-size")
SET(CMAKE_ASM_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
SET(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fno-common -fsigned-char -fmessage-length=0 -Wall -Wextra -Wshadow -Os -ffunction-sections -fdata-sections -g -std=c11")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl, --specs=nosys.specs --specs=nano.specs -Wl,--gc-sections -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mabi=aapcs -Wl,-T ${LINKER_SCRIPT}")#-Wl,-map=${TARGET}.map,--cref #-u _printf_float -u _scanf_float
add_executable(${TARGET}.elf ${USER_SOURCES})
set_target_properties(${TARGET}.elf PROPERTIES LINKER_LANGUAGE C)
add_custom_target (${TARGET}.bin
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin
)
add_custom_target (${TARGET}.lst
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst
)
The output from the CMakeLists.txt file is:
> $ cmake.exe -G"Unix Makefiles" ..
>
> -- The C compiler identification is unknown
> -- The CXX compiler identification is GNU 7.4.0
> -- Check for working C compiler: C:/cygwin/bin/cc
> -- Check for working C compiler: C:/cygwin/bin/cc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: C:/cygwin/bin/c++.exe
> -- Check for working CXX compiler: C:/cygwin/bin/c++.exe -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- The ASM compiler identification is unknown
> -- Found assembler: C:/cygwin/bin/cc
> -- Warning: Did not find file Compiler/-ASM
> -- [DBG]:
>
> D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.h
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Sr
> c/stm32f4xx_it.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_
> EXTI/Inc/stm32f4xx_hal_conf.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GP
> IO/GPIO_EXTI/Src/system_stm32f4xx.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/I
> nclude/stm32f407xx.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_gcc.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_armcc.h;D:/STM32Cube_FW_F4_V1.24 .0/Drivers/CMSIS/Core/Include/cmsis_compiler.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_version.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/core_cm4
> .h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/mpu_armv7.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;D:/STM32Cube_FW_F4_V1.24.0/Dri
> vers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_H
> AL_Driver/Inc/stm32f4xx_hal_cortex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/s
> tm32f4xx_hal_gpio.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_fla
> sh.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h;D:/STM32Cube_F
> W_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;D:/STM32Cube_FW_F4_V1.24.0/Driver
> s/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4
> xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver
> /Src/stm32f4xx_hal_i2c.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.
> c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;D:/STM32Cube_FW_F4
> _V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers /STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_D
> river/Inc/stm32f4xx_hal_i2c_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_disc
> overy.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/ stm32f4xx_it.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EX
> TI/Inc/stm32f4xx_hal_conf.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/
> Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld
> -- Configuring done
> -- Generating done
> -- Build files have been written to: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/build
After this I type in the Cygwin Terminal "make" and I get the following result:
$ make
Scanning dependencies of target F4cmake.elf
[ 5%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S.obj
[ 10%] Building C object CMakeFiles/F4cmake.elf.dir/Src/system_stm32f4xx.c.obj
[ 15%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c: In function 'HAL_PWR_EnterSLEEPMode':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c:365:38: warning: unused parameter 'Regulator' [-Wunused-parameter]
365 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
| ~~~~~~~~~^~~~~~~~~
[ 21%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c.obj
[ 26%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c.obj
[ 31%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c.obj
[ 36%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c.obj
[ 42%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c.obj
[ 47%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_MassErase':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:953:60: warning: unused parameter 'Banks' [-Wunused-parameter]
953 | static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
| ~~~~~~~~~^~~~~
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_OB_EnableWRP':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:1032:74: warning: unused parameter 'Banks' [-Wunused-parameter]
1032 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
| ~~~~~~~~~^~~~~
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_OB_DisableWRP':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:1068:75: warning: unused parameter 'Banks' [-Wunused-parameter]
1068 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
| ~~~~~~~~~^~~~~
[ 52%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c.obj
[ 57%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c.obj
[ 63%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.obj
[ 68%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c.obj
[ 73%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c.obj
[ 78%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c.obj
[ 84%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c: In function 'I2Cx_Error':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c:454:32: warning: unused parameter 'Addr' [-Wunused-parameter]
454 | static void I2Cx_Error(uint8_t Addr)
| ~~~~~~~~^~~~
[ 89%] Building C object CMakeFiles/F4cmake.elf.dir/Src/main.c.obj
[ 94%] Building C object CMakeFiles/F4cmake.elf.dir/Src/stm32f4xx_it.c.obj
[100%] Linking C executable F4cmake.elf.exe
C:\GnuToolChain\9_2019_q4_major\bin\arm-none-eabi-ld.exe: no input files
make[2]: *** [CMakeFiles/F4cmake.elf.dir/build.make:338: F4cmake.elf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/F4cmake.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
*** [Makefile:84: all] Error 2
I don't understand, why the linker says he has no input files.
In the CMakeLists.txt I explicitely added the linker (arm-none-eabi-ld.exe) because, if I do not add the linker, I got other failure and MAKE is using an other linker what I don't understand why.
[ 89%] Building C object CMakeFiles/F4cmake.elf.dir/Src/main.c.obj
[ 94%] Building C object CMakeFiles/F4cmake.elf.dir/Src/stm32f4xx_it.c.obj
[100%] Linking C executable F4cmake.elf.exe
c:/gnutoolchain/9_2019_q4_major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/F4cmake.elf.dir/build.make:338: F4cmake.elf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/F4cmake.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I don't see my failure.
Can someone tell me what I am doing wrong?
Why is make using different linker?
How to fix the CMakeLists.txt file, so Make can generate an *.elf output file?
Thank you
I answer to my own question.
It is important, that all parameters for e.g. CMAKE_C_FLAGS are in one line, otherwise creating of the make file will fail.
The code of the toolchain cmake file is:
include(CMakeForceCompiler)
# set the CMake-identifier of the target paltform to build for
set (CMAKE_SYSTEM_NAME Generic)
# set the CMake-identifier of the target architecture to build for
set (CMAKE_SYSTEM_PROCESSOR arm)
# set definitions
add_definitions(-DSTM32F407xx)
add_definitions(-DUSE_STM32F4_DISCO)
add_definitions(-DUSE_HAL_DRIVER)
# set toolchain path
set(TOOLCHAIN_DIR C:/GnuToolChain/9_2019_q4_major/bin)
# specify cross compiler
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_DIR}/arm-none-eabi-as.exe)
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/arm-none-eabi-gcc.exe)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/arm-none-eabi-g++.exe)
set(CMAKE_OBJCOPY ${TOOLCHAIN_DIR}/arm-none-eabi-objcopy.exe)
set(CMAKE_OBJDUMP ${TOOLCHAIN_DIR}/arm-none-eabi-objdump.exe)
set(CMAKE_SIZE ${TOOLCHAIN_DIR}/arm-none-eabi-size.exe)
# set C compiler flags
set(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
# set C++ compiler flags
set(CMAKE_CXX_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
# set Linker Script File
set(LINKER_SCRIPT D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld)
# set linker flags. The only important settings are -T ${} and -Wl,--gc-sections otherwise creating of makefile will not work
set(CMAKE_EXE_LINKER_FLAGS "-T ${LINKER_SCRIPT} -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=nosys.specs -specs=nano.specs -Wl,--gc-sections -o -lm")
# where is the target located
set(CMAKE_FIND_ROOT_PATH)
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
The code of the CMakeLists.txt is as following:
cmake_minimum_required (VERSION 3.15)
# set project name and enable the languages 'C' and 'ASM'
project(F4cmake C ASM)
# set the project name
set(TARGET F4cmake)
# set location of project
set(PRJ_DIR ../../../../..)
# set startup file
set(STARTUP ${PRJ_DIR}/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.s)
message (STATUS "[DBG]: ${STARTUP}")
# set system file for µController
set(SYSTEM ${PRJ_DIR}/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/system_stm32f4xx.c)
# set paths
set(HAL_PATH ${PRJ_DIR}/Drivers/STM32F4xx_HAL_Driver)
set(CMSIS_PATH ${PRJ_DIR}/Drivers/CMSIS)
set(BSP_PATH ${PRJ_DIR}/Drivers/BSP)
# set CMSIS files needed for the project
set(CMSIS_SRCS
${CMSIS_PATH}/Device/ST/STM32F4xx/Include/stm32f4xx.h
${CMSIS_PATH}/Device/ST/STM32F4xx/Include/stm32f407xx.h
${CMSIS_PATH}/Core/Include/cmsis_gcc.h
${CMSIS_PATH}/Core/Include/cmsis_armcc.h
${CMSIS_PATH}/Core/Include/cmsis_compiler.h
${CMSIS_PATH}/Core/Include/cmsis_version.h
${CMSIS_PATH}/Core/Include/core_cm4.h
${CMSIS_PATH}/Core/Include/mpu_armv7.h
)
# set HAL files needed for the project
set(HAL_SRCS
${HAL_PATH}/Src/stm32f4xx_hal_pwr.c
${HAL_PATH}/Inc/stm32f4xx_hal_pwr.h
${HAL_PATH}/Src/stm32f4xx_hal_cortex.c
${HAL_PATH}/Inc/stm32f4xx_hal_cortex.h
${HAL_PATH}/Src/stm32f4xx_hal_gpio.c
${HAL_PATH}/Inc/stm32f4xx_hal_gpio.h
${HAL_PATH}/Src/stm32f4xx_hal_flash.c
${HAL_PATH}/Inc/stm32f4xx_hal_flash.h
${HAL_PATH}/Src/stm32f4xx_hal_spi.c
${HAL_PATH}/Inc/stm32f4xx_hal_spi.h
${HAL_PATH}/Src/stm32f4xx_hal_rcc.c
${HAL_PATH}/Inc/stm32f4xx_hal_rcc.h
${HAL_PATH}/Src/stm32f4xx_hal_flash_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_flash_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_rcc_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_rcc_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_i2c.c
${HAL_PATH}/Inc/stm32f4xx_hal_i2c.h
${HAL_PATH}/Src/stm32f4xx_hal.c
${HAL_PATH}/Inc/stm32f4xx_hal.h
${HAL_PATH}/Src/stm32f4xx_hal_pwr_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_pwr_ex.h
${HAL_PATH}/Src/stm32f4xx_hal_dma.c
${HAL_PATH}/Inc/stm32f4xx_hal_dma.h
${HAL_PATH}/Src/stm32f4xx_hal_i2c_ex.c
${HAL_PATH}/Inc/stm32f4xx_hal_i2c_ex.h
)
# set BSP files needed for the project
SET (BSP_SRCS
${BSP_PATH}/STM32F4-Discovery/stm32f4_discovery.c
${BSP_PATH}/STM32F4-Discovery/stm32f4_discovery.h
)
message (STATUS "[DBG]: ${BSP_SRCS}")
# set Application files needed for the project
SET (APP_SRCS
Src/main.c
Src/stm32f4xx_it.c
Inc/main.h
Inc/stm32f4xx_hal_conf.h
Inc/stm32f4xx_it.h
)
message (STATUS "[DBG]: ${APP_SRCS}")
# include directories for the project
include_directories (
${CMSIS_PATH}/Device/ST/STM32F4xx/Source/Templates/gcc
Src
Inc
${BSP_PATH}/STM32F4-Discovery
${HAL_PATH}/Src
${HAL_PATH}/Inc
${HAL_PATH}/Inc/Legacy
${CMSIS_PATH}/Core/Include
${CMSIS_PATH}/Device/ST/STM32F4xx/Include
)
# configure assembler due to the startup file, which is an assembler file
set_source_files_properties(${STARTUP} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE ${STARTUP} PROPERTY LANGUAGE C)
# Summerize all sources
SET(USER_SOURCES ${STARTUP} ${SYSTEM} ${CMSIS_SRCS} ${HAL_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
message(STATUS "[DBG]: ${USER_SOURCES}")
#
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${TARGET}.map")
# create an *.elf output file
add_executable(${TARGET}.elf ${USER_SOURCES})
# create possibility to create a *.bin file
add_custom_target (${TARGET}.bin DEPENDS ${TARGET}.elf COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin)
# create possibility to create a *.list file
add_custom_target (${TARGET}.lst DEPENDS ${TARGET}.elf COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst)
Related
I have the following setup for my CMake project:
add_executable(exeA ${SOURCES})
target_link_libraries(exeA PRIVATE libB)
libB is a static library built separately in a different project and depends on shared libraries libC OR libD which provide equivalent API's but implemented differently and have different performance profiles.
In exeA's build I want to be able to link against either of libC or libD depending on a condition.
From reading RPATH handling, it seems I could use RPATH related CMake properties, however its unclear if I can use these properties to set the RPATH of an existing static library
Unfortunately there is no easy and fast way to change the RPATH of an
existing executable or shared library.
Is something like this possible to do in CMake?
Appreciate any recommendations to handle this use case.
Create a STATIC IMPORTED library for libB and SHARED IMPORTED libraries for libC and libD. Put the relevant one in the INTERFACE_LINK_LIBRARIES property of libB. CMake will set the RPATH correctly when exeA is built.
cmake_minimum_required(VERSION 3.23)
project(test)
# --------------------------------------------------
# The following code should probably be factored out
# into a proper Find module.
find_library(LIBB_LIBRARY NAMES B REQUIRED)
find_library(LIBC_LIBRARY NAMES C REQUIRED)
find_library(LIBD_LIBRARY NAMES D REQUIRED)
add_library(third-party::libC SHARED IMPORTED)
set_target_properties(
third-party::libC
PROPERTIES
IMPORTED_LOCATION "${LIBC_LIBRARY}"
)
add_library(third-party::libD SHARED IMPORTED)
set_target_properties(
third-party::libD
PROPERTIES
IMPORTED_LOCATION "${LIBD_LIBRARY}"
)
add_library(third-party::libB STATIC IMPORTED)
set_target_properties(
third-party::libB
PROPERTIES
IMPORTED_LOCATION "${LIBB_LIBRARY}"
)
option(LIBB_USES_LIBC "dummy option for demo" ON)
if (LIBB_USES_LIBC)
target_link_libraries(third-party::libB INTERFACE third-party::libC)
else ()
target_link_libraries(third-party::libB INTERFACE third-party::libD)
endif ()
# --------------------------------------------------
# --------------------------------------------------
# Project code
add_executable(exeA main.cpp)
target_link_libraries(exeA PRIVATE third-party::libB)
You can test this out with dummy files like so:
$ ls
CMakeLists.txt
$ mkdir -p prefix{1,2}/lib
$ touch prefix1/lib/lib{C,D}.so prefix2/lib/libB.a main.cpp
$ cmake -G Ninja -S . -B build "-DCMAKE_PREFIX_PATH=$PWD/prefix1;$PWD/prefix2"
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/build
$ cmake --build build -- -nv # dry run (n), verbose (v)
[1/2] /usr/bin/c++ -MD -MT CMakeFiles/exeA.dir/main.cpp.o -MF CMakeFiles/exeA.dir/main.cpp.o.d -o CMakeFiles/exeA.dir/main.cpp.o -c /home/alex/test/main.cpp
[2/2] : && /usr/bin/c++ CMakeFiles/exeA.dir/main.cpp.o -o exeA -Wl,-rpath,/home/alex/test/prefix1/lib ../prefix2/lib/libB.a ../prefix1/lib/libC.so && :
As you can see, the RPATH is set correctly to the directory containing libC.so.
TL;DR: Why moving stuff around from the CMakeLists.txt to a dedicated toolchain file plays a role for find_package?
Trying to cross-compile with cmake and compile/link against pthread, I have the following dummy source file and CMakeLists.txt which work as expected together:
main.cc
#include <iostream>
#include <bits/c++config.h> // needed in the real world
int main()
{
std::cout << "Hello World !\n";
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(test VERSION 0.0.1)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf)
add_compile_options(-mtune=cortex-a9)
add_compile_definitions(_ARM_GCC_)
# Looking for cross compiler includes; maybe looking for rootfs-like stuff would be better
file(GLOB cross_includes LIST_DIRECTORIES true "/usr/arm-linux-gnueabihf/include/c++/*/arm-linux-gnueabihf/")
include_directories(SYSTEM ${cross_includes})
include_directories(SYSTEM /usr/arm-linux-gnueabihf/include)
find_package(Threads REQUIRED) # Not strictly necessary in this example but needed in the real world
add_executable(test main.cc)
Test:
$> rm -rf build/ && cmake -B build/ && make VERBOSE=1 -C build/
-- The C compiler identification is Clang 11.0.1
-- The CXX compiler identification is Clang 11.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jp/sandbox/so/cmake/build
make: Entering directory '/home/jp/sandbox/so/cmake/build'
/usr/bin/cmake -S/home/jp/sandbox/so/cmake -B/home/jp/sandbox/so/cmake/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/jp/sandbox/so/cmake/build/CMakeFiles /home/jp/sandbox/so/cmake/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/jp/sandbox/so/cmake/build'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory '/home/jp/sandbox/so/cmake/build'
cd /home/jp/sandbox/so/cmake/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jp/sandbox/so/cmake /home/jp/sandbox/so/cmake /home/jp/sandbox/so/cmake/build /home/jp/sandbox/so/cmake/build /home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/DependInfo.cmake --color=
Dependee "/home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/DependInfo.cmake" is newer than depender "/home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/depend.internal".
Dependee "/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/jp/sandbox/so/cmake/build/CMakeFiles/test.dir/depend.internal".
Scanning dependencies of target test
make[2]: Leaving directory '/home/jp/sandbox/so/cmake/build'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory '/home/jp/sandbox/so/cmake/build'
[ 50%] Building CXX object CMakeFiles/test.dir/main.cc.o
/usr/bin/clang++ --target=arm-linux-gnueabihf -D_ARM_GCC_ -isystem /usr/arm-linux-gnueabihf/include/c++/10/arm-linux-gnueabihf -isystem /usr/arm-linux-gnueabihf/include -g -mtune=cortex-a9 -std=c++17 -o CMakeFiles/test.dir/main.cc.o -c /home/jp/sandbox/so/cmake/main.cc
[100%] Linking CXX executable test
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/clang++ --target=arm-linux-gnueabihf -g -rdynamic CMakeFiles/test.dir/main.cc.o -o test
make[2]: Leaving directory '/home/jp/sandbox/so/cmake/build'
[100%] Built target test
make[1]: Leaving directory '/home/jp/sandbox/so/cmake/build'
/usr/bin/cmake -E cmake_progress_start /home/jp/sandbox/so/cmake/build/CMakeFiles 0
make: Leaving directory '/home/jp/sandbox/so/cmake/build'
So far, everything works fine.
Now, the tricky part: I'd like to put the cross-compilation specific stuff in a toolchain.cmake file
toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf)
add_compile_options(-mtune=cortex-a9)
add_compile_definitions(_ARM_GCC_)
# Looking for cross compiler includes; maybe looking for rootfs-like stuff would be better
file(GLOB cross_includes LIST_DIRECTORIES true "/usr/arm-linux-gnueabihf/include/c++/*/arm-linux-gnueabihf/")
include_directories(SYSTEM ${cross_includes})
include_directories(SYSTEM /usr/arm-linux-gnueabihf/include)
new CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(test VERSION 0.0.1)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Threads REQUIRED) # Not strictly necessary in this example but needed in the real world
add_executable(test main.cc)
Test:
$> rm -rf build/ && cmake -B build/ -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake && make VERBOSE=1 -C build/
-- The C compiler identification is Clang 11.0.1
-- The CXX compiler identification is Clang 11.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - not found
CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.18/Modules/FindThreads.cmake:234 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:11 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeOutput.log".
See also "/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeError.log".
Actually, cmake finds pthread.h but clang cannot compile it (wrong floating point abi used; stubs-hard.h should be included)
build/CMakeFiles/CMakeError.log
Determining if the include file pthread.h exists failed with the following output:
Change Dir: /home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake cmTC_76e89/fast && /usr/bin/gmake -f CMakeFiles/cmTC_76e89.dir/build.make CMakeFiles/cmTC_76e89.dir/build
gmake[1]: Entering directory '/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_76e89.dir/CheckIncludeFile.c.o
/usr/bin/clang -D_ARM_GCC_ -isystem /usr/arm-linux-gnueabihf/include/c++/10/arm-linux-gnueabihf -isystem /usr/arm-linux-gnueabihf/include/gnu -isystem /usr/arm-linux-gnueabihf/include -mtune=cortex-a9 -o CMakeFiles/cmTC_76e89.dir/CheckIncludeFile.c.o -c /home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c
In file included from /home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:
In file included from /usr/arm-linux-gnueabihf/include/pthread.h:21:
In file included from /usr/arm-linux-gnueabihf/include/features.h:485:
/usr/arm-linux-gnueabihf/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-soft.h' file not found
# include <gnu/stubs-soft.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
gmake[1]: *** [CMakeFiles/cmTC_76e89.dir/build.make:85: CMakeFiles/cmTC_76e89.dir/CheckIncludeFile.c.o] Error 1
gmake[1]: Leaving directory '/home/jp/sandbox/so/cmake/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:140: cmTC_76e89/fast] Error 2
Some more Info:
I made sure the toolchain.cmake is considered (triggered a parse error to check)
$> cat toolchain.cmake CMakeLists.txt
produces the same output as the "original" CMakeLists.txt
pthread.h can be found on my System at the following locations:
$> find /usr/ -name pthread.h
/usr/arm-linux-gnueabi/include/pthread.h
/usr/arm-linux-gnueabihf/include/pthread.h
/usr/include/newlib/pthread.h /usr/include/pthread.h
As #Tsyvarev pointed out, the CMakeError.log contained useful information (the question was edited with its content).
The issue:
cmake finds pthread.h but clang cannot compile it
...
/usr/arm-linux-gnueabihf/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-soft.h' file not found
...
The clang invocation is interesting because of "/usr/bin/clang" (expected clang++) and no -target flag used
The solution:
Tell cmake to also use a specific -target flag for C cross-compilers supoorting it:
Add the following in target.cmake
set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabihf)
(Same target as CMAKE_CXX_COMPILER_TARGET)
Consider the following simple openMP program:
program hello
use OMP_LIB
implicit none
integer :: nthreads, tid
!$OMP PARALLEL PRIVATE(nthreads, tid)
tid = omp_get_thread_num()
nthreads = omp_get_num_threads()
! print *, "hello"
print *,"Thread:", tid, "of", nthreads
!$OMP END PARALLEL
end program hello
when i compile it as
gfortran -fopenmp hello.90 -o hello.x
I get output as:
Thread: 2 of 4
Thread: 1 of 4
Thread: 0 of 4
Thread: 3 of 4
as expected.
Now if i consider the following CMakeLists.txt file
cmake_minimum_required(VERSION 2.8.9)
project (hello Fortran)
enable_language(Fortran)
IF(NOT CMAKE_BUILD_TYPE)
message("NO BUILD TYPE PROVIDED")
message("DEFAULT BUILD TYPE SET TO 'Release'")
set(CMAKE_BUILD_TYPE 'Release')
ENDIF()
IF(${CMAKE_BUILD_TYPE} MATCHES RELEASE OR ${CMAKE_BUILD_TYPE} MATCHES Release)
message("MAKING RELEASE BUILD")
set(CMAKE_Fortran_FLAGS_RELEASE "-fopenmp")
message("FLAGS: ${CMAKE_Fortran_FLAGS_RELEASE}")
ENDIF()
add_executable(hello.x hello.f90)
Considering above file is right, it should add omp flag to make file and hence compile and run same, however
$ mkdir build; cd build
$ cmake ..
-- The Fortran compiler identification is GNU 6.1.0
-- Checking whether Fortran compiler has -isysroot
-- Checking whether Fortran compiler has -isysroot - yes
-- Checking whether Fortran compiler supports OSX deployment target flag
-- Checking whether Fortran compiler supports OSX deployment target flag - yes
-- Check for working Fortran compiler: /usr/local/bin/gfortran
-- Check for working Fortran compiler: /usr/local/bin/gfortran - works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/local/bin/gfortran supports Fortran 90
-- Checking whether /usr/local/bin/gfortran supports Fortran 90 - yes
NO BUILD TYPE PROVIDED
DEFAULT BUILD TYPE SET TO 'Release'
MAKING RELEASE BUILD
FLAGS: -fopenmp
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/user/Programs/omp/build
$
$ make
Scanning dependencies of target hello.x
[ 50%] Building Fortran object CMakeFiles/hello.x.dir/hello.f90.o
[100%] Linking Fortran executable hello.x
Undefined symbols for architecture x86_64:
"_omp_get_num_threads_", referenced from:
_MAIN__ in hello.f90.o
"_omp_get_thread_num_", referenced from:
_MAIN__ in hello.f90.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [hello.x] Error 1
make[1]: *** [CMakeFiles/hello.x.dir/all] Error 2
Which is same as missing -fopenmp flag. How to add it?
The set command for CMAKE_BUILD_TYPE take a "non-string" argument apparently.
Changing
set(CMAKE_BUILD_TYPE 'Release')
to
set(CMAKE_BUILD_TYPE Release)
solved the problem for me. I first dug into the cache system to understand why your setting would not work and there was no reason. I found a CMAKE_Fortran_FLAGS_'Release' entry in ccmake and looked again at the variable CMAKE_BUILD_TYPE in the docs, and it takes values empty, Debug, Release, RelWithDebInfo, MinSizeRel (which I understood as being unquoted).
I've to cross compile a 3rd party library which uses CMake.
In order to build something, I need to pass "-B path" flag to compiler.
foo.c :
void main(){}
Build command :
cross-gcc -B /path/to/somewhere -o foo.o foo.c
Without "-B path" option, the compiler simply does not work.
Hence I use the following lines in my cmake toolchain file :
SET(CMAKE_C_FLAGS "-B /path/to/somewhere")
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere")
But during the validation of compiler, CMake does not seem use the flags I set :
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /cross-path/cross-gcc
-- Check for working C compiler: /cross-path/cross-gcc -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "cross-path/cross-gcc" is not able
to compile a simple test program.
....
....
/cross-path/cross-gcc -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c CMakeFiles/CMakeTmp/testCCompiler.c
When I invoke CMake second time, cross-gcc passes the simple compilation test but this time cross-g++ fails :
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /cross-path/cross-gcc
-- Check for working C compiler: /cross-path/cross-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /cross-path/cross-g++
-- Check for working CXX compiler: /cross-path/cross-g++ -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:45 (MESSAGE):
The C++ compiler "/cross-path/cross-g++" is not
able to compile a simple test program.
....
....
/cross-path/cross-g++ -o CMakeFiles/cmTryCompileExec.dir/testCXXCompiler.cxx.o -c CMakeFiles/CMakeTmp/testCXXCompiler.cxx
And if I invoke CMake 3rd time, everything works fine with only a warning :
....
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHAIN_FILE
I'm using CMake 2.8.7 and aware that it is quite outdated but upgrade is not an option if this is the case.
Edit :
Toolchain file :
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_FLAGS "-B /path/to/somewhere")
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere")
# specify the cross compiler
SET(CMAKE_C_COMPILER /cross-path/cross-gcc)
SET(CMAKE_CXX_COMPILER /cross-path/cross-g++)
It looks that the problem of picking up the flags is very similar to one already discussed in SO in the past:
CMake cross-compiling: C flags from toolchain file ignored
Try the proposed solution, i.e. replace:
SET(CMAKE_C_FLAGS "-B /path/to/somewhere")
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere")
by
SET(CMAKE_C_FLAGS "-B /path/to/somewhere" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere" CACHE STRING "" FORCE)
Try also to check if replacing your toolchain file with a new one that uses INCLUDE(CMakeForceCompiler) as mentioned in
http://www.vtk.org/Wiki/CMake_Cross_Compiling and
How can I make Cmake use specific compiler and flags when final compilation stage instead of detection? and
Cmake cross compile flags
INCLUDE(CMakeForceCompiler)
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_FLAGS "-B /path/to/somewhere")
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere")
# specify the cross compiler
CMAKE_FORCE_C_COMPILER(/cross-path/cross-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(/cross-path/cross-g++ GNU)
...
has the same effect as the first hack. The second option seems a cleaner solution.
Here's the relevant part of my project structure
iNode
├── CMakeLists.txt
├── src
| └──iNode.c
├── include
| └──iNode.h
└── test
└──tests.cpp
cmake can't find function definitions from iNode.c
I don't know why they don't get added when I add_library
I've tried several permutations of linking libraries
cmake_minimum_required (VERSION 2.8)
project(iNode)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wshadow -Wpedantic -D_XOPEN_SOURCE=700")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wshadow -Werror -g -D_XOPEN_SOURCE=700")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
include_directories(${f16fs_INCLUDE_DIRS} ${dyn_array_INCLUDE_DIRS} include)
add_library(${PROJECT_NAME} SHARED src/${PROJECT_NAME}.c)
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
install(FILES include/${PROJECT_NAME}.h DESTINATION include)
add_executable(${PROJECT_NAME}_test test/tests.cpp)
target_link_libraries(${PROJECT_NAME}_test gtest pthread ${PROJECT_NAME})
set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE)
The error
$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/syg84/project3_syg84/build
[ 10%] Built target dyn_array_tester
[ 20%] Built target dyn_array
[ 30%] Built target bitmap_tester
[ 40%] Built target bitmap
[ 50%] Built target block_store
[ 60%] Built target block_store_test
[ 70%] Built target iNode
[ 80%] Built target f16fs
[ 90%] Built target f16fs_test
Scanning dependencies of target iNode_test
[ 95%] Linking CXX executable iNode_test
CMakeFiles/iNode_test.dir/test/tests.cpp.o: In function `getDirectoryContents_rootDirectory_Test::TestBody()':
/home/syg84/project3_syg84/iNode/test/tests.cpp:6: undefined reference to `createNewINodeArray(unsigned long)'
/home/syg84/project3_syg84/iNode/test/tests.cpp:8: undefined reference to `getDirectoryContents(iNode**, unsigned char)'
/home/syg84/project3_syg84/iNode/test/tests.cpp:10: undefined reference to `destroyINodeArray(iNode**, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [iNode/iNode_test] Error 1
make[1]: *** [iNode/CMakeFiles/iNode_test.dir/all] Error 2
make: *** [all] Error 2