cmake Undefined reference to functions - cmake

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

Related

Linking problems with yaml-cpp

I am trying to incorporate yaml-cpp into my project.
I have a "Demes" class where I need to parse a YAML file.
This is the relevant method in Demes.cpp:
#include "Demes.hpp"
void Demes::parse(const std::string& fileName)
{
YAML::Node test = YAML::LoadFile(fileName);
}
where Demes.hpp includes the yaml-cpp headers and declares the 'parse' method.
Building with make -VERBOSE=1 (as suggested by #Tsyvarev) gives:
[100%] Linking CXX executable momentspp
cd /home/gvbarroso/Devel/momentspp/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/momentspp.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native CMakeFiles/momentspp.dir/Log.cpp.o CMakeFiles/momentspp.dir/PolymorphismData.cpp.o CMakeFiles/momentspp.dir/SumStatsLibrary.cpp.o CMakeFiles/momentspp.dir/Drift.cpp.o CMakeFiles/momentspp.dir/Migration.cpp.o CMakeFiles/momentspp.dir/Mutation.cpp.o CMakeFiles/momentspp.dir/Recombination.cpp.o CMakeFiles/momentspp.dir/Epoch.cpp.o CMakeFiles/momentspp.dir/Model.cpp.o CMakeFiles/momentspp.dir/OptimizationWrapper.cpp.o CMakeFiles/momentspp.dir/Demes.cpp.o CMakeFiles/momentspp.dir/main.cpp.o -o momentspp -Wl,-rpath,/home/gvbarroso/.local/lib: /home/gvbarroso/.local/lib/libbpp-phyl3.so.1.0.0 /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.74.0 /home/gvbarroso/.local/lib/libbpp-seq3.so.1.0.0 /home/gvbarroso/.local/lib/libbpp-core3.so.1.0.0
/usr/bin/ld: CMakeFiles/momentspp.dir/Demes.cpp.o: in function Demes::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Demes.cpp:(.text+0x4c): undefined reference to YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
/usr/bin/ld: Demes.cpp:(.text+0x12c): undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/momentspp.dir/build.make:277: src/momentspp] Error 1
make[2]: Leaving directory '/home/gvbarroso/Devel/momentspp/build'
make[1]: *** [CMakeFiles/Makefile2:125: src/CMakeFiles/momentspp.dir/all] Error 2
make[1]: Leaving directory '/home/gvbarroso/Devel/momentspp/build'
make: *** [Makefile:156: all] Error 2
I am using CMake to build my project, but I am still fairly unfamiliar with it.
EDIT: I forgot to mention that I have two CMakeLists.txt files, one inside src and the other inside the external build.
The start of my CMakeLists.txt file in the external build is:
cmake_minimum_required (VERSION 3.5.0)
project (momentspp CXX)
SET(CMAKE_CXX_FLAGS "-std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native")
And the part of it where I look for yaml-cpp is:
FIND_PACKAGE(yaml-cpp REQUIRED)
IF(yaml-cpp_FOUND)
INCLUDE_DIRECTORIES(${yaml-cpp_INCLUDE_DIRS})
SET(LIBS {yaml-cpp_LIBRARIES})
MESSAGE("-- yaml-cpp libraries found here:")
MESSAGE(" includes: ${yaml-cpp_INCLUDE_DIRS}")
ENDIF()
My full CMakeLists.txt file inside src is:
SET(momentspp_CPP
Log.cpp
PolymorphismData.cpp
SumStatsLibrary.cpp
Drift.cpp
Migration.cpp
Mutation.cpp
Recombination.cpp
Epoch.cpp
Model.cpp
OptimizationWrapper.cpp
Demes.cpp
main.cpp
)
ADD_EXECUTABLE (momentspp ${momentspp_CPP})
SET(momentspp-targets momentspp)
FOREACH (target ${momentspp-targets})
TARGET_LINK_LIBRARIES(${target} ${BPP_LIBS_SHARED} ${BOOST_LIBS_SHARED} ${EIGEN3_LIBS_SHARED} ${yaml-cpp_LIBS_SHARED})
TARGET_LINK_LIBRARIES (${target} ${LIBS})
ENDFOREACH (target)
INSTALL(TARGETS ${momentspp-targets} DESTINATION ${CMAKE_INSTALL_BINDIR})
and this was working prior to the inclusion of yaml-cpp.
This feels like a rather complicated CMake set-up, but I am copying and editing it from a previous project where someone else helped me with it.
How can I fix the linking issue?
I tried looking similar questions around here, but couldn't get their solutions to work for me (apparently those people where not using CMake to build their projects).
Thank you,
Gustavo

Include tensorflow lite libraries in CMakeLists.txt of C++ project giving errors "undefined reference to `ruy::ScopedSuppressDenormals"

I'm trying to include TensorFlow lite libraries in CMakeLists.txt of C++ project. I followed the instructure in https://www.tensorflow.org/lite/guide/build_cmake
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build && cd tflite_build
cmake ../tensorflow_src/tensorflow/lite -DTFLITE_ENABLE_XNNPACK=OFF
-DTFLITE_ENABLE_EXTERNAL_DELEGATE=OFF TFLITE_ENABLE_RUY=ON/OFF (tried both option)
cmake --build . --config release -j24
and added all the libs to the CmakeLists.txt file as follow
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(TENSORFLOW_SRC_DIR "test_cpp/tensorflow_src")
set(TFLITE_DIR "test_cpp/tflite_build")
find_package(OpenCV 4 REQUIRED)
file(GLOB SOURCE_FILES src/*.cpp src/*.h )
message(${SOURCE_FILES})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
include_directories(
${TENSORFLOW_SRC_DIR}
${TFLITE_DIR}/eigen
${TFLITE_DIR}/neon2sse
${TFLITE_DIR}/abseil-cpp
${TFLITE_DIR}/farmhash/src
${TFLITE_DIR}/flatbuffers/include
${TFLITE_DIR}/gemmlowp/public
${TFLITE_DIR}/gemmlowp
${TFLITE_DIR}/ruy
${TFLITE_DIR}/cpuinfo/include
)
target_link_libraries(
${CMAKE_PROJECT_NAME} PUBLIC
${OpenCV_LIBS}
${TFLITE_DIR}/_deps/farmhash-build/libfarmhash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/flags/libabsl_flags.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_functions.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_handle.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cordz_info.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cord.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_cord_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/strings/libabsl_strings.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_city.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_hash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/hash/libabsl_low_level_hash.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_civil_time.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_time_zone.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/time/libabsl_time.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/profiling/libabsl_exponential_biased.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/numeric/libabsl_int128.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_base.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_log_severity.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/status/libabsl_status.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a
${TFLITE_DIR}/_deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a
${TFLITE_DIR}/_deps/flatbuffers-build/libflatbuffers.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_ctx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_cpuinfo.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_frontend.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_blocking_counter.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx512.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_apply_multiplier.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_block_map.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_trmul.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/profiler/libruy_profiler_instrumentation.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_denormal.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_prepacked_cache.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_system_aligned_alloc.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_context_get_ctx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_allocator.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_wait.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_context.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx2_fma.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_thread_pool.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_arm.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_tune.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_kernel_arm.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_have_built_path_for_avx.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_prepare_packed_matrices.a
${TFLITE_DIR}/_deps/ruy-build/ruy/libruy_pack_avx512.a
${TFLITE_DIR}/_deps/fft2d-build/libfft2d_fftsg.a
${TFLITE_DIR}/_deps/fft2d-build/libfft2d_fftsg2d.a
${TFLITE_DIR}/_deps/clog-build/libclog.a
${TFLITE_DIR}/_deps/cpuinfo-build/libcpuinfo.a
${TFLITE_DIR}/libtensorflow-lite.a
dl
)
It worked on a windows machine but on Linux I'm getting error about
undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
[ 33%] Building CXX object CMakeFiles/main.dir/src/main.cpp.o
[ 66%] Building CXX object CMakeFiles/main.dir/src/ssd_mobilenet_tflite.cpp.o
[100%] Linking CXX executable main
/usr/bin/ld: ../tflite_build/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::Interpreter::Invoke()':
interpreter.cc:(.text+0x3ff): undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
/usr/bin/ld: interpreter.cc:(.text+0x523): undefined reference to `ruy::ScopedSuppressDenormals::~ScopedSuppressDenormals()'
/usr/bin/ld: ../tflite_build/libtensorflow-lite.a(interpreter.cc.o): in function `tflite::Interpreter::Invoke() [clone .cold]':
interpreter.cc:(.text.unlikely+0x5c): undefined reference to `ruy::ScopedSuppressDenormals::~ScopedSuppressDenormals()'
/usr/bin/ld: CMakeFiles/main.dir/src/ssd_mobilenet_tflite.cpp.o: in function `SSD_MOBILENET::loadModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
ssd_mobilenet_tflite.cpp:(.text+0x2b2): undefined reference to `tflite::ops::builtin::BuiltinOpResolver::BuiltinOpResolver()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:231: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I don't want to add the libs as "add_subdirectory" as it was given in the guide because it will compile every time I create a new project
So how can I solve the undefined reference to `ruy::ScopedSuppressDenormals::ScopedSuppressDenormals()'
UPDATE:
if I change the CMakeLists.txt to :
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(TENSORFLOW_SRC_DIR "test_cpp/tensorflow_src")
set(TFLITE_DIR "test_cpp/tflite_build")
find_package(OpenCV 4 REQUIRED)
find_package(TFLITE)
file(GLOB SOURCE_FILES src/*.cpp src/*.h )
message(${SOURCE_FILES})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
include_directories(
${TENSORFLOW_SRC_DIR}
)
target_link_libraries(
${CMAKE_PROJECT_NAME} PUBLIC
${OpenCV_LIBS}
${TFLITE_LIBS}
)
I take this error
from test_cpp/src/main.cpp:1:
test_cpp/tensorflow_src/tensorflow/lite/interpreter_builder.h:26:10: fatal error: flatbuffers/flatbuffers.h: No such file or directory
26 | #include "flatbuffers/flatbuffers.h" // from #flatbuffers
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/main.dir/build.make:63: CMakeFiles/main.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I found this repo that contains all needed libs for the project https://github.com/muhammedakyuzlu/tflite-cpp-package
I believe that the problem you have is the ordering of the libs.
Try putting the libtensorflow-lite.a before the ruy-*.a in your setup.
There is another trick that could help you getting started.
Just add this to your CMake File:
include(FetchContent)
FetchContent_Declare(
tensorflow
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
GIT_TAG v2.10.0
SOURCE_SUBDIR tensorflow/lite
)
FetchContent_MakeAvailable(tensorflow)
and link to the library:
target_link_libraries(${PROJECT_NAME} PRIVATE
tensorflow-lite
)
This is downloading all dependencies automatically and should make you ready to go.

CMakeLists - Make linker do not find files

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)

multiple definition of 'CGAL::Surface_mesh_parameterization::get_error_message(int)'

I am able to use CGAL surface mesh parametrization with given examples easily. Which means that CGAL is installed properly and is functional.
Ways to reproduce error:
Create a empty main file
Create a class file with appropriate modifications to CGAL square_border_parametrize.cpp
After I do cmake . and make this is the output
Scanning dependencies of target Main
[ 33%] Building CXX object CMakeFiles/Main.dir/SBP.cpp.o
:0:15: warning: missing whitespace after the macro name
:0:15: warning: missing whitespace after the macro name
[ 66%] Building CXX object CMakeFiles/Main.dir/main.cpp.o
:0:15: warning: missing whitespace after the macro name
:0:15: warning: missing whitespace after the macro name
[100%] Linking CXX executable Main
CMakeFiles/Main.dir/main.cpp.o: In function _mm_getcsr()':
/usr/local/include/CGAL/Interval_nt.h:202: multiple definition ofCGAL::Surface_mesh_parameterization::get_error_message(int)'
CMakeFiles/Main.dir/SBP.cpp.o:/usr/local/include/CGAL/Surface_mesh_parameterization/Error_code.h:53: first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/Main.dir/build.make:450: recipe for target 'Main' failed
make[2]: * [Main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Main.dir/all' failed
make[1]: * [CMakeFiles/Main.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
I am not able to find any multiple definition for CGAL::Surface_mesh_parameterization::get_error_message(int). My CMakeLists.txt file looks like this:
cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
PROJECT(LSCM)
FIND_PACKAGE( OpenCV REQUIRED )
find_package( PCL 1.7 REQUIRED COMPONENTS common io visualization filters )
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
include( CGAL_CreateSingleSourceCGALProgram )
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
SET(CMAKE_BUILD_TYPE "Debug")
SET(LIBRARY_OUTPUT_PATH "./lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
file(GLOB SOURCE_FILES ./*.cpp)
ADD_EXECUTABLE(Main ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(Main ${OpenCV_LIBS} ${PCL_LIBRARIES} ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} -lCGAL -lm )
install (TARGETS Main DESTINATION ~/bin)
A quick fix: In the file include/CGAL/Surface_mesh_parameterization/Error_code.h write inline in front of const char* get_error_message(int error_code).
The fix is in this pull request, that is now merged in CGAL-4.12.

Adding static dependency in CMake

I've got an example project:
.
├── CMakeLists.txt
└── src
└── test1.f90
where test1.f90 uses a specific version of Lapack (therefore I can't use FindLAPACK).
I am trying to compile this using CMake:
cmake_minimum_required(VERSION 2.5)
project(TEST)
file(GLOB_RECURSE sources src/*.f90)
add_executable(cmake.x ${sources})
enable_language(Fortran)
set(CMAKE_Fortran_COMPILER_ID "IBM")
if(CMAKE_Fortran_COMPILER_ID MATCHES "IBM")
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
MESSAGE(STATUS "IBM")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-allow-multiple-definition ")
set(CMAKE_Fortran_COMPILER mpixlf2008_r)
set(debug "-C")
endif()
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
MESSAGE( STATUS "cmake_module_path: " ${CMAKE_MODULE_PATH})
If I run make VERBOSE=1 this results in:
...
[100%] Building Fortran object CMakeFiles/cmake.x.dir/src/test1.o
mpixlf2008_r -c /work/jias12/jias1217/lapack_test/src/test1.f90 -o CMakeFiles/cmake.x.dir/src/test1.o
** main === End of Compilation 1 ===
1501-510 Compilation successful for file test1.f90.
Linking Fortran executable cmake.x
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmake.x.dir/link.txt --verbose=1
mpixlf2008_r -Wl,-allow-multiple-definition CMakeFiles/cmake.x.dir/src/test1.o -o cmake.x
CMakeFiles/cmake.x.dir/src/test1.o:(.text+0x5c): undefined reference to `sgesv'
make[2]: *** [cmake.x] Error 1
make[2]: Leaving directory `/work/jias12/jias1217/lapack_test'
make[1]: *** [CMakeFiles/cmake.x.dir/all] Error 2
make[1]: Leaving directory `/work/jias12/jias1217/lapack_test'
make: *** [all] Error 2
This obviously doesn't work, because I didn't include LAPACK, which I then can do manually:
mpixlf2008_r -Wl,-allow-multiple-definition CMakeFiles/cmake.x.dir/src/test1.o -o cmake.x -L$LAPACK_LIB -L/bgsys/local/lib -llapack -lesslbg
Which works fine. How can I achieve this using CMake? I want to add -L$LAPACK_LIB -L/bgsys/local/lib -llapack -lesslbg to the linker after the *.o files. All I've managed is to add them as flags before the *.o files, which fails. I've look at a number of examples on the web, but I cannot find something which works in my case. This is the test1.f90.
This is in the folders:
> ls $LAPACK_LIB
libblas_extra.a libcblas.a liblapack.a liblapacke.a libtmglib.a
ls /bgsys/local/lib/
BGeic.pm BG.pm libesslbg.a libesslsmpbg.a
As Tsyvarev correctly mentioned:
What is wrong with target_link_libraries which links with the
libraries (meaning of flag -l) and link_directories which specifies
libraries search path (meaning of flag -L)?
Those hase to be called in the right order, which leads to:
cmake_minimum_required(VERSION 2.5)
project(TEST)
file(GLOB_RECURSE sources src/*.f90)
link_directories($ENV{LAPACK_LIB} /bgsys/local/lib)
enable_language(Fortran)
add_executable(cmake.x ${sources})
target_link_libraries(cmake.x lapack esslbg)