Error compiling freertos for nucleo stm32f767 - cmake

I have generated code using cubeMX and while compiling it gives me the following errors. I have already tried several fixes but none of them is working.
/tmp/ccvxTV8U.s: Assembler messages:
/tmp/ccvxTV8U.s:758: Error: selected processor does not support `vstmdbeq r0!,{s16-s31}' in Thumb mode
/tmp/ccvxTV8U.s:760: Error: instruction not allowed in IT block -- `stmdb r0!,{r4-r11,r14}'
/tmp/ccvxTV8U.s:782: Error: selected processor does not support `vldmiaeq r0!,{s16-s31}' in Thumb mode
/tmp/ccvxTV8U.s:784: Error: instruction not allowed in IT block -- `msr psp,r0'
CMakeLists.txt
IDE: CLion 2019.3
#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.13)
# specify cross compilers and tools
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER arm-none-eabi-gcc)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_AR arm-none-eabi-ar)
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
set(SIZE arm-none-eabi-size)
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F767ZITx_FLASH.ld)
#Uncomment for hardware floating point
SET(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
#Uncomment for software floating point
#SET(FPU_FLAGS "-mfloat-abi=soft")
SET(COMMON_FLAGS
"-mcpu=cortex-m7 ${FPU_FLAGS} -mthumb -mthumb-interwork -ffunction-sections -fdata-sections \
-g -fno-common -fmessage-length=0 -specs=nosys.specs -specs=nano.specs")
SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} -std=gnu99")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-gc-sections,--print-memory-usage -T ${LINKER_SCRIPT}")
PROJECT(freertos_test C CXX ASM)
set(CMAKE_CXX_STANDARD 11)
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
add_definitions(-D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F767xx)
file(GLOB_RECURSE SOURCES "Middlewares/*.*" "startup/*.*" "Drivers/*.*" "Core/*.*")
include_directories(Core/Inc Drivers/STM32F7xx_HAL_Driver/Inc Drivers/STM32F7xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32F7xx/Include Drivers/CMSIS/Include Middlewares/Third_Party/FreeRTOS/Source/include Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1)
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
I'm using the NUCLEO-F767ZI with a STM32F767

file(GLOB_RECURSE SOURCES "Middlewares/*.*"
You are compiling FreeRTOS for all possible implementations for all possible cpus, so you are also compiling sources not compatible at all with your current cpu. You should compile sources only for your destination cpu.
That would most probably be, assuming the folder Middlewares is taken from cubemx:
file(GLOB src1
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/*.c
Middlewares/Third_Party/FreeRTOS/Source/*.c
)
And add only the needed include path:
target_include_directories(YOUR_TARGET PUBLIC
Middlewares/Third_Party/FreeRTOS/Source/include
)

Related

fortran defined macro ignored with cmake

I am trying to create a new macro in a Fortran file. Such file is one of many in a bigger project. It is compiled through a CMake file and gfortran.
For its simplicity I just included a simple example:
#define hello call
module SIO_ncDimBounds_mod
use SIO_ncParams_mod, only: MAX_DIMLEN_NAME
...
logical, parameter :: ISDEBUG = .false.
hello -> not recognized as Macro
When It is compiled it is ignored so it raises an error:
../soulio/src/ncDimBounds_mod.F90:34:2:
34 | hello
| 1
Error: Unclassifiable statement at (1)
As far as I understand, with upper case file extension should be enough to execute the preprocessor. I also checked the '-cpp' flag is enabled. I doubled checked with verbose mode to ensure it is enabled:
[ 22%] Building Fortran object src/CMakeFiles/soulio_lib.dir/ncDimBounds_mod.F90.o
cd ../soulio/build/src && /usr/bin/gfortran -DENABLE_MPI -I../projects/soulio/src/soulshared_lib -I../soulio/extern/Library/include -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/x86_64-linux-gnu/openmpi/lib -ffree-form -std=f2008 -fimplicit-none -cpp -g -fbounds-check -pedantic -ffpe-trap=zero,invalid,overflow,underflow -O0 -Wall -fcheck=all -fbacktrace -Wextra --coverage -fprofile-arcs -ftest-coverage -J../../lib -c ../soulio/src/ncDimBounds_mod.F90 -o CMakeFiles/soulio_lib.dir/ncDimBounds_mod.F90.o
I also include the CMakeFile:
cmake_minimum_required(VERSION 3.9)
project(soulio)
enable_language(Fortran)
find_program(FYPP fypp)
if(NOT FYPP)
message(FATAL_ERROR "Preprocessor fypp could not be found")
endif()
# custom compiler flags
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(dialect "-ffree-form -std=f2008 -fimplicit-none -cpp")
set(debugMode "-fbounds-check -pedantic -ffpe-trap=zero,invalid,overflow,underflow -O0 -Wall -fcheck=all -fbacktrace -Wextra")
set(optimizedMode "-ftree-vectorize" )
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(dialect "-stand f08 -free -implicitnone")
set(debugMode "-check bounds")
set(optimizedMode "-O3 -xHost")
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "PGI")
set(dialect "-Mfreeform -Mdclchk -Mstandard -Mallocatable=03")
set(debugMode "-C")
set(optimizedMode "")
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${optimizedMode}")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${debugMode}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}")
# Place lib and binary files
# dynamic libraries
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# static library
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
# target files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# Have the .mod files placed in the lib folder
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(CMAKE_Fortran_MODULE_DIRECTORY ${LIB})
# include cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(soulioUtils)
message(status ${CMAKE_SOURCE_DIR})
# call for netcdf library
if (NOT HAS_SOULSM)
set (NETCDF_C "YES")
set (NETCDF_F90 "YES")
set (NETCDF_INCLUDES ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_C ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_F77 ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_F90 ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_INCLUDES_CXX ${CMAKE_SOURCE_DIR}/extern/Library/include)
set (NETCDF_LIBRARIES_F77 ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdff.so)
set (NETCDF_LIBRARIES_F90 ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdff.so)
set (NETCDF_LIBRARIES_C ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdf.so)
set (NETCDF_LIBRARIES ${CMAKE_SOURCE_DIR}/extern/Library/lib/libnetcdf.so)
find_package (NetCDF REQUIRED)
endif()
if (ENABLE_MPI)
find_package (MPI REQUIRED)
add_definitions(-DENABLE_MPI)
endif()
message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
if(BUILD_TESTING)
enable_testing()
SET( CMAKE_BUILD_TYPE Debug )
include( cmake/CodeCoverage.cmake )
SET(coverageMode "--coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${coverageMode}")
add_subdirectory(tests)
endif()
if (NOT HAS_SOULSM)
add_subdirectory(soulshared)
endif()
add_subdirectory(src)
I did a simple and isolated test with a fortran file with an uppercase extension, as expected it works.
Why is the macro not replaced with CMake? It seems to me the preprocessor it is not called.
Edit:
'hello' is changed to lowercase
If we change the example to
subroutine silly()
print *, 'It works'
return
end subroutine silly
#define hello call
program main
hello silly
stop
end program main
and build using
gfortran -cpp macro.f90
This builds without any problems. If I just have hello on its own, then I get a syntax error.
First, make sure your program is valid. call on its own will generate an error. You need to call something.
Could you try building without cmake? If it works without cmake and doesn't work with cmake then it is a cmake problem. Otherwise, you just have a problem with your code.

What is a correct way to solve undefined reference to undefined reference to `LLVMInitializeAArch64TargetInfo'

In Clion when i build llvm project I got following message:
CMakeFiles/codegen_llvm.dir/main.cpp.o: In function `llvm::InitializeAllTargetInfos()':
/usr/lib/llvm-9/include/llvm/Config/Targets.def:26: undefined reference to `LLVMInitializeAArch64TargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:27: undefined reference to `LLVMInitializeAMDGPUTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:28: undefined reference to `LLVMInitializeARMTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:29: undefined reference to `LLVMInitializeBPFTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:30: undefined reference to `LLVMInitializeHexagonTargetInfo'
/usr/lib/llvm-9/include/llvm/Config/Targets.def:31: undefined reference to `LLVMInitializeLanaiTargetInfo'
And My CmakeLists is here:
cmake_minimum_required(VERSION 3.15)
project(codegen_llvm)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
set(CMAKE_CXX_STANDARD 14)
add_executable(codegen_llvm main.cpp)
llvm_map_components_to_libnames(llvm_libs support core irreader executionEngine)
target_link_libraries(codegen_llvm ${llvm_libs})
...
What should I do?
cmake solution
cmake_minimum_required(VERSION 3.10)
project(project_name )
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
link_libraries()
execute_process(COMMAND llvm-config --libs OUTPUT_VARIABLE LIBS)
execute_process(COMMAND llvm-config --system-libs OUTPUT_VARIABLE SYS_LIBS)
execute_process(COMMAND llvm-config --ldflags OUTPUT_VARIABLE LDF)
#message(STATUS "Found LLVM" ${LIBS})
string(STRIP ${LIBS} LIBS)
string(STRIP ${SYS_LIBS} SYS_LIBS)
string(STRIP ${LDF} LDF)
link_libraries(${LIBS} ${SYS_LIBS} ${LDF})
execute_process(COMMAND llvm-config --cxxflags OUTPUT_VARIABLE CMAKE_CXX_FLAGS)
string(STRIP ${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
add_executable(project_name toy.cpp)
one liner
clang++ -g toy.cpp $(llvm-config --cxxflags --ldflags --system-libs --libs) -O3 -o toy
If you still do not have a solution for this error, try to add ${LLVM_TARGETS_TO_BUILD} to your link libraries.
I am using CLion too, and I solved this by changing:
llvm_map_components_to_libnames(llvm_libs support core irreader codegen mc mcparser option)
to:
llvm_map_components_to_libnames(llvm_libs ${LLVM_TARGETS_TO_BUILD} support core irreader codegen mc mcparser option)
In your last but one line config is not an llvm component, so you'd want to remove it. To see the list of official components, use the llvm-config --components command.

Correcting the Linker Flags for CMake

I am trying to convert an embedded gcc arm- project to use ARMClang instead of GCC.
My focus was to use CMake to automate the task of generating the make files, but I could
not figure out why I can not enforce the linker flags and I always get
following error during build
[ 96%] Building ASM object CMakeFiles/CLION-f103-armclang.elf.dir/startup/startup_stm32f103xb.o
Fatal error: A9912E: No --cpu selected
The contents of my CMakeLists.txt file is as below
#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.15)
# specify cross compilers and tools
#SET(CMAKE_C_COMPILER_ID ARMClang)
#SET(CMAKE_CXX_COMPILER_ID ARMClang)
#SET(CMAKE_ASM_COMPILER_ID ARMClang)
SET(TARGET "arm-arm-none-eabi")
SET(CMAKE_C_COMPILER_TARGET ${TARGET})
SET(CMAKE_CXX_COMPILER_TARGET ${TARGET})
SET(CMAKE_ASM_COMPILER_TARGET ${TARGET})
SET(CMAKE_SYSTEM_PROCESSOR Cortex-M3)
SET(CMAKE_C_COMPILER_ID ARMClang)
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER armclang)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER armclang)
SET(CMAKE_ASM_COMPILER_WORKS 1)
set(CMAKE_ASM_COMPILER armasm)
#set(CMAKE_AR arm-none-eabi-ar)
#set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
#set(CMAKE_OBJDUMP arm-none-eabi-objdump)
#set(SIZE arm-none-eabi-size)
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F103RBTx_FLASH.ld)
#Uncomment for hardware floating point
#SET(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
#Uncomment for software floating point
#SET(FPU_FLAGS "-mfloat-abi=soft")
SET(COMMON_FLAGS
"${FPU_FLAGS} -mthumb -ffunction-sections -fdata-sections \
-g -fno-common -fmessage-length=0")
SET(WARNING_FLAGS "-Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes \
-Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path \
-Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command \
-Wno-documentation -Wno-license-management -Wno-parentheses-equality")
SET(COMPILER_OPT_FLAGS "-flto -Ofast -ffunction-sections ")
SET(TCPU_FLAGS "--target=arm-arm-none-eabi -mcpu=cortex-m3")
SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} -std=c++11 -fno-rtti -funsigned-char -fshort-enums -fshort-wchar -gdwarf-3")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} -std=gnu99 -fno-rtti -flto -funsigned-char -fshort-enums -fshort-wchar -gdwarf-3")
#SET(CMAKE_EXE_LINKER_FLAGS_INIT "--info sizes --info totals --info unused --info veneers -g --lto -Wl,-gc-sections,--print-memory-usage -T ${LINKER_SCRIPT}")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "--info sizes --info totals --cpu Cortex-M3\
--info unused --info veneers -g\
--lto -gc-sections,--print-memory-usage\
-T ${LINKER_SCRIPT}" CACHE INTERNAL "" FORCE)
PROJECT(CLION-f103-armclang C CXX ASM)
set(CMAKE_CXX_STANDARD 11)
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
add_definitions(-D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F103xB)
file(GLOB_RECURSE SOURCES "startup/*.*" "Drivers/*.*" "Core/*.*")
include_directories(Core/Inc Drivers/STM32F1xx_HAL_Driver/Inc Drivers/STM32F1xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32F1xx/Include Drivers/CMSIS/Include)
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map" CACHE INTERNAL "" FORCE)
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
Firstly what are the necessary changes for the CMakeLists.txt file to make the script to build and link properly!?
Secondly how to make the linker output flags looks like following as much as possible.
--cpu Cortex-M3 -g
-I.\RTE\_stm32f103rbt6-LCD-CubeMX
-IC:\Users\U1\AppData\Local\Arm\Packs\ARM\CMSIS\5.5.1\CMSIS\Core\Include
-IC:\Users\U1\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.3.0\Device\Include
--pd "__UVISION_VERSION SETA 528"
--pd "_RTE_ SETA 1"
--pd "STM32F10X_MD SETA 1"
--list *.lst
--xref -o stm32f103rbt6-LCD-CubeMX\*.o
--depend stm32f103rbt6-LCD-CubeMX\*.d
Any help is really appreciated

From makefile to Cmake - stm32

I would like to test CLion for my stm32 project since it now support remote debugging! To do so I need to setup Cmake for my project and it is my issue.
I tried using this link which seems to be depreciated so I made some changes. It almost builds but there is a problem with the .elf .bin .hex.
CMakeLists.txt:
project(F466cmake)
cmake_minimum_required(VERSION 3.10)
add_definitions(-DSTM32F446xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
Drivers/CMSIS/Device/Src/system_stm32f4xx.c
Drivers/CMSIS/Device/Src/startup_stm32f446xx.s)
include_directories(Inc)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Drivers/CMSIS/Inc)
include_directories(Drivers/CMSIS/Device/Inc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
terminal output:
[ 95%] Building C object CMakeFiles/F466cmake.elf.dir/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c.o
[100%] Linking C executable F466cmake.elf
/home/flo/bin/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000008000000
Building /home/flo/STM32Cube/Testing/build/F466cmake.hex
Building /home/flo/STM32Cube/Testing/build/F466cmake.bin
/usr/bin/objcopy: Unable to recognise the format of the input file `/home/flo/STM32Cube/Testing/build/F466cmake.elf'
CMakeFiles/F466cmake.elf.dir/build.make:563: recipe for target 'F466cmake.elf' failed
make[2]: *** [F466cmake.elf] Error 1
make[2]: *** Deleting file 'F466cmake.elf'
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/F466cmake.elf.dir/all' failed
make[1]: *** [CMakeFiles/F466cmake.elf.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Got it to work, thanks to Chris for the guidance. The issue was the ASM was not build and I had to link arm object copy.
CMakeLists.txt:
project(F466cmake C ASM)
cmake_minimum_required(VERSION 3.10)
add_definitions(-DSTM32F446xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
Drivers/CMSIS/Device/Src/system_stm32f4xx.c)
add_library(STARTUP
Drivers/CMSIS/Device/Src/startup_stm32f446xx.s)
set_source_files_properties(Drivers/CMSIS/Device/Src/startup_stm32f446xx.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE Drivers/CMSIS/Device/Src/startup_stm32f446xx.s PROPERTY LANGUAGE C)
include_directories(Inc)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Drivers/CMSIS/Inc)
include_directories(Drivers/CMSIS/Device/Inc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS STARTUP)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")

Linking error -- openSSL to libcurl

I'm doing C++ using libcURL. I got the task to test functions in Travis CI. So I used .travis.yml to get libcurl-dev and libssl-dev to connect to the project. I installed them and checked cURL configuration:
SSL support: enabled (OpenSSL)
But as I was trying to make main test file i got list of errors (example)
`Linking CXX executable ../bin/TechProject_example
/usr/local/lib/libcurl.a(libcurl_la-openssl.o): In function ossl_recv:
openssl.c:(.text+0xf3): undefined reference to ERR_clear_error
openssl.c:(.text+0x11c): undefined reference to SSL_read
openssl.c:(.text+0x163): undefined reference to SSL_get_error`
and so on...
The only thing I was able to check is that libcurl is working properly. I placed
--without-ssl flag and got protocol error.
Also I used
`- sudo ln -fs /usr/lib/libcurl.so.4 /usr/local/lib/`
to avoid cmake error. (I'm not very good at UNIX command, so this can be a problem)
So how should properly connect openSSL to C++ project that has <curl/curl.h> ?
EDIT:
Here is CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project (TechProject)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(HEADERS ${PROJECT_SOURCE_DIR}/include/testclass.h)
set(HEADERS ${PROJECT_SOURCE_DIR}/include/catch.hpp)
set(SOURCES ${PROJECT_SOURCE_DIR}/sources/testclass.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
include_directories(${PROJECT_SOURCE_DIR}/include)
add_library (${PROJECT_NAME} STATIC ${SOURCES})
add_subdirectory(example)
add_subdirectory(tests)
find_library(FOO_LIB libcurl.a)
target_link_libraries(TechProject "${FOO_LIB}")
And CMakeLists.txt in tests subdir:
cmake_minimum_required(VERSION 2.8)
set(TESTS_FOR_PROJECT TechProject)
project(${TESTS_FOR_PROJECT}_tests)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
file(GLOB ${PROJECT_NAME}_sources "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
find_package(${TESTS_FOR_PROJECT})
include_directories(${${TESTS_FOR_PROJECT}_INCLUDE_DIRS}})
include_directories(${CPM_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_sources} ${${PROJECT_NAME}_headers})
target_link_libraries(${PROJECT_NAME} ${TESTS_FOR_PROJECT})
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/fixtures $<TARGET_FILE_DIR:${PROJECT_NAME}>)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${PROJECT_NAME} -s -r compact WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)