How can I compile example in ESP-IDF - windows

I've installed esp-idf and I'm trying to compile example build_system/cmake/idf_as_lib
and I got the error in the ESP-IDF CMD which not allow me to compile that example. The same problem is in Visual Studio Code.
Probably I should set environment path CMAKE_C_COMPILER but I don't know what should I point.
I've installed CMAKE on my windows
My actual environment paths:
IDF_PYTHON_ENV_PATH -> C:\esp\tools.espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe
IDF_TOOLS_PATH -> C:\esp\tools.espressif
IDF_PATH -> C:\esp\esp-idf
C:\esp\esp-idf\examples\build_system\cmake\idf_as_lib>idf.py build
Executing action: all (aliases: build)
Running cmake in directory c:\esp\esp-idf\examples\build_system\cmake\idf_as_lib\build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 -DCCACHE_ENABLE=1 c:\esp\esp-idf\examples\build_system\cmake\idf_as_lib"...
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/esp/esp-idf/examples/build_system/cmake/idf_as_lib/build/CMakeFiles/CMakeOutput.log".
See also "C:/esp/esp-idf/examples/build_system/cmake/idf_as_lib/build/CMakeFiles/CMakeError.log".
cmake failed with exit code 1
CMakeList
cmake_minimum_required(VERSION 3.5)
project(idf_as_lib C)
if("${TARGET}" STREQUAL "esp32")
# Include for ESP-IDF build system functions
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
# Create idf::esp32 and idf::freertos static libraries
idf_build_process(esp32
# try and trim the build; additional components
# will be included as needed based on dependency tree
#
# although esptool_py does not generate static library,
# processing the component is needed for flashing related
# targets and file generation
COMPONENTS esp32 freertos esptool_py
SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig
BUILD_DIR ${CMAKE_BINARY_DIR})
else()
# Create stubs for esp32 and freertos, stub::esp32 and stub::freertos
add_subdirectory(stubs/esp32)
add_subdirectory(stubs/freertos)
add_subdirectory(stubs/spi_flash)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
add_executable(${elf_file} main.c)
# Link the static libraries to the executable
if("${TARGET}" STREQUAL "esp32")
target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash)
# Attach additional targets to the executable file for flashing,
# linker script generation, partition_table generation, etc.
idf_build_executable(${elf_file})
else()
target_link_libraries(${elf_file} stub::esp32 stub::freertos stub::spi_flash)
endif()

Related

CMake Error: variable set to NOTFOUND even after defining it manually

I am new to cmake and attempting to build an existing repository that relies on GLEW. I have installed GLEW using Homebrew and am now trying to run cmake . The configuration step completes, but the generation step raises the following error:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_LIBRARY
I have checked/tried the following:
CMakeLists.txt contains a line find_package(GLEW REQUIRED) which does not fail. I even added the line FIND_LIBRARY(GLEW_LIBRARY NAMES libGLEW.dylib PATHS /opt/local/lib /usr/local/lib /usr/lib REQUIRED) to explicitly tell cmake where to look for the library and it finds the correct path.
There is a file FindGlew.cmake that was placed in /usr/local/Cellar/cmake/3.25.2/share/cmake/Modules (I assume during the homebrew install of GLEW). It contains a line unset(GLEW_LIBRARY). I'm a bit hesitant to mess with the file (it shouldn't be necessary, right?) but I tried commenting that line out and running cmake again, but it didn't have any effect.
CMakeCache.txt contains the variables GLEW_LIBRARY_DEBUG and GLEW_LIBRARY_RELEASE which were set to GLEW_LIBRARY_DEBUG-NOTFOUND etc. I edited them manually to the path of the libGLEW.dylib file and added an additional path which I called GLEW_LIBRARY, but to no avail.
CMakeCache.txt also contains a variable GLEW_DIR which is defined. There is a GLEW_LIBRARY_DIR which is also NOTFOUND.
I passed the variable as an explicit command using cmake . -DGLEW_LIBRARY=/usr/local/lib/libGLEW.dylib. I tried this both with and without first deleting the cache.
Statically define the library using the approach in this answer.
brew reinstall glew.
I do have OpenGL installed as wel, but built from source (not via Homebrew). Could It have something to do with them not being linked correctly? OpenGL is found properly by CMakeLists.txt, so cmake must have access to its path somehow.
Edit: this is (a MWE of) the CMakeLists.txt file:
cmake_minimum_required (VERSION 3.15)
project ("ProjectName" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(OpenGL REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} )
# set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(GLEW REQUIRED)
# set(CMAKE_FIND_DEBUG_MODE FALSE)
include_directories(${GLEW_INCLUDE_DIRS})
file(GLOB sources CONFIGURE_DEPENDS src/*.cpp src/*.hpp *src/.h)
add_executable(${PROJECT_NAME} ${sources})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES})
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_BINARY_DIR}/Resources)
Edit: for completeness, here is the full output / error message:
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenGL.framework
-- Found GLEW: /usr/local/lib/cmake/glew/glew-config.cmake
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_LIBRARY
linked by target "ProjectName" in directory /Users/user1/dev/project
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
EDIT2: According to FindGLEW you should use one of the imported targets - GLEW::GLEW i.e.
target_link_libraries(your_target GLEW::GLEW ... )
I would also kindly ask you to post the new errors that you are getting related to the MRE you posted. I will update my answer accordingly.
EDIT: Because you mentioned that some people can compile it and some people can't. Look at this line right here:
find_package(GLEW CONFIG QUIET)
if(GLEW_FOUND)
#...
This line tries to find the actual GLEWConfig.cmake file to configure this. Meaning that if you've installed the package OR they have in a way that you have this GLEWConfig.cmake file then you will get different results.
My recommendation is: Figure out exactly how they installed their GLEW (or if they compiled it) and recreate the exact same environment.
Here is the link to FindGLEW.cmake. On Lines 41-58 you can see the variables that you can use in your project. There is NO GLEW_LIBRARY.
If you look down in the file you'll see why:
if(GLEW_FOUND)
find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_CONFIG)
get_target_property(GLEW_INCLUDE_DIRS GLEW::GLEW INTERFACE_INCLUDE_DIRECTORIES)
set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS})
get_target_property(_GLEW_DEFS GLEW::GLEW INTERFACE_COMPILE_DEFINITIONS)
if("${_GLEW_DEFS}" MATCHES "GLEW_STATIC")
get_target_property(GLEW_LIBRARY_DEBUG GLEW::GLEW IMPORTED_LOCATION_DEBUG)
get_target_property(GLEW_LIBRARY_RELEASE GLEW::GLEW IMPORTED_LOCATION_RELEASE)
else()
get_target_property(GLEW_LIBRARY_DEBUG GLEW::GLEW IMPORTED_IMPLIB_DEBUG)
get_target_property(GLEW_LIBRARY_RELEASE GLEW::GLEW IMPORTED_IMPLIB_RELEASE)
endif()
get_target_property(_GLEW_LINK_INTERFACE GLEW::GLEW IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE) # same for debug and release
list(APPEND GLEW_LIBRARIES ${_GLEW_LINK_INTERFACE})
list(APPEND GLEW_LIBRARY ${_GLEW_LINK_INTERFACE})
select_library_configurations(GLEW)
if("${_GLEW_DEFS}" MATCHES "GLEW_STATIC")
set(GLEW_STATIC_LIBRARIES ${GLEW_LIBRARIES})
else()
set(GLEW_SHARED_LIBRARIES ${GLEW_LIBRARIES})
endif()
unset(_GLEW_DEFS)
unset(_GLEW_LINK_INTERFACE)
unset(GLEW_LIBRARY) #<-- here the temporary variable is unset
unset(GLEW_LIBRARY_DEBUG)
unset(GLEW_LIBRARY_RELEASE)
return()
endif()
GLEW_LIBRARY is a temporary variable used to set other variables.
What instead you want to use is: GLEW_LIBRARIES

CMake problem while assembling .asm files in CLion

I'm trying to run .asm files on Clion, and i've already installed NASM for it but i have a problem with specifying ASM Compiler:
CMake Error at CMakeLists.txt:4 (enable_language):
The CMAKE_ASM_NASM_COMPILER:
C:/Users/User/AppData/Local/bin/NASM
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "ASM_NASM" or the CMake cache entry CMAKE_ASM_NASM_COMPILER to the
full path to the compiler, or to the compiler name if it is in the PATH.
mingw32-make.exe: *** [Makefile:175: cmake_check_build_system] Error 1
-- The ASM_NASM compiler identification is unknown
-- Found assembler: C:/Users/User/AppData/Local/bin/NASM
-- Configuring incomplete, errors occurred!
The problem is with this "full path", but i don't quite understand, what is meant with it.
Here is my CMakeLists.txt :
cmake_minimum_required(VERSION 3.17)
project(untitled C)
set(CMAKE_ASM_NASM_COMPILER C:/Users/User/AppData/Local/bin/NASM)
enable_language(ASM_NASM)
set(ASM_SOURCES
test.asm)
set(SOURCES
${ASM_SOURCES})
set_source_files_properties(test.asm PROPERTIES LANGUAGE ASM_NASM)
add_executable(program ${SOURCES})
I've also read similar questions here (but about C/C++ Compiler), they weren't really helpful in my case.
Thank you for the answers!
Solution (using Compile ASM and C with ASM for debugging ) :
cmake_minimum_required(VERSION 3.17)
project(untitled ASM)
enable_language(ASM_NASM)
set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> \
<FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS} -g")
else()
set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS}")
endif()
set_source_files_properties(test.asm PROPERTIES LANGUAGE ASM_NASM)
add_executable(program test.asm)

Custom MPI Path in CMake Project

I'm building a project that uses MPI.
Here's the CMakeLists.txt
if(__OPENNN_MPI__)
find_package(MPI)
if(MPI_FOUND)
message("Using MPI")
set(CMAKE_CXX_COMPILER mpicxx)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_CXX_COMPILE_FLAGS "${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS}")
add_definitions(-D__OPENNN_MPI__ )
endif()
endif()
What argument to cmake do I pass to enable this block of code.
My MPI Installation is in a custom path, say /path/to/MPI
Do I simply add the MPI path to my $PATH and run cmake . or is there a flag that I should set, like we would set -DCMAKE_INSTALL_PREFIX:PATH
To tell CMakes FindMPI about a custom installation, it is sufficient to make sure that your custom mpicc and mpicxx is in $PATH. Alternatively, you can supply them as such:
cmake -DMPI_C_COMPILER=/path/to/bin/mpicc -DMPI_CXX_COMPILER=/path/to/bin/mpicxx
CMake will pick up the rest based on the compiler wrappers. You should however not set CMAKE_C_COMPILER / CMAKE_CXX_COMPILER to the MPI compiler wrappers. Instead:
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
And for each C++ target:
target_link_libraries(target ${MPI_CXX_LIBRARIES})
if(MPI_CXX_COMPILE_FLAGS)
set_target_properties(target PROPERTIES COMPILE_FLAGS "${MPI_CXX_COMPILE_FLAGS}")
endif()
if(MPI_CXX_LINK_FLAGS)
set_target_properties(target PROPERTIES LINK_FLAGS "${MPI_CXX_LINK_FLAGS}")
endif()
C targets similarly.

CMake Compiler Identification Error

I'm having the following problem when trying to build a project using CMake:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
I'm executing the following command: cmake . inside the CMake project folder.
The error also states that I shoulkd try to set the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER enviroment variables to the compiler paths. And so did I.
I've set the variables to the following paths, respectively: C:\MinGW\bin\gcc.exe and C:\MinGW\bin\g++.exe.
The error kept happening.
My CMakeLists looks like this:
cmake_minimum_required(VERSION 2.8.9)
project (hello)
add_executable(hello helloworld.cpp)
I have no CMake knowledge at all so consider that it is possible that I've forgotten some basic stuff.
What am I missing?
I found out what I was doing wrong.
I was not choosing the correct generator, and the following fixed it:
cmake -G "MinGW Makefiles" ..
After selecting MinGW generator, everything worked just fine.

Unable to specify the compiler with CMake

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

Resources