CMake problem while assembling .asm files in CLion - windows

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)

Related

How can I compile example in ESP-IDF

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()

How to create a makefile for Keystone library using cmake? [duplicate]

Work on Ubuntu 16
I used g++ main.cpp -lpq command for compiler my small project. Now I use Clion and wanna do same what I do with g++. But I can't add compiler flags in cmake file and get compile error.
cmake_minimum_required(VERSION 3.5.1)
project(day_g)
set(CMAKE_CXX_FLAGS "-lpq")
add_definitions(-lpq)
message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(day_g ${SOURCE_FILES})
Also I run only cmake file and get CMAKE_CXX_FLAGS with -lpq flag.
CMAKE_CXX_FLAGS is -lpq
-- Configuring done
-- Generating done
How properly add compiler flags to cmake file?
Flag -l is for linker, not for compiler. This flag is used for link with libraries. CMake has special command target_link_libraries for that purpose:
target_link_libraries(day_g pq)
-lq is not a compiler flag (CFLAGS) but a linker flag.
To pass a library in a CMake project you should use:
target_link_libraries(target_name libraries...)
Note that if you specify 'q' as library the project will link with libq.a or, if you are on windows q.dll.
... in your CMakeLists.txt the correct line to add is:
target_link_libraries(day_g pq)
Note also that when you add a CFLAG you should also "remember" the previous ones that may be added by libraries or by your platform, ie:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
To check the exact flags cmake is passing to compiler or linker you can always run, from the build directory, the following command:
make VERBOSE=1

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.

cmake: Create a hex-file with an AVR compiler

I hope someone is able to help me:
I try to use the cmake plugin in a jenkins server to create a hex file, but i don't know my fault.
I also try to run the example of this site: http://robot-develop.org/archives/2952 but if i use the "make" command, i get this error message:
make: *** No targets specifed and no makefile found. Stop
Here is my code:
CMakeLists.txt:
cmake_minimum_required (VERSION 2.6.0)
INCLUDE("C:/Users/name/Desktop/example/Code/test_crosscompile.cmake")
INCLUDE("C:/Users/name/Desktop/example/Code/macro.cmake")
project (Code)
MESSAGE(STATUS "\n -------------------------------->Creating Test-Projekt...")
IF( NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE Release ... FORCE )
ENDIF()
SET(MAIN_FILE
class.c)
# add the executable
add_executable(Code ${MAIN_FILE})
#makro
AVR_CREATE_HEX(class)
makro.cmake:
# create avr hex
MACRO(AVR_CREATE_HEX name)
ADD_CUSTOM_COMMAND(TARGET ${name} POST_BUILD COMMAND avr-objcopy ARGS -O ihex -R.eeprom ${name} "C:/Users/name/Desktop/example/Code/class.hex")
MESSAGE(STATUS "\n ----------JONAS---------------------->Macro")
ENDMACRO(AVR_CREATE_HEX)
test_crosscompile.cmake:
SET(CMAKE_SYSTEM_NAME "Windows")
SET(CMAKE_C_COMPILER avr-gcc)
SET(CMAKE_CXX_COMPILER avr-g++)
SET(CSTANDARD "-std=gnu99")
SET(CDEBUG "-gstabs")
SET(CWARN "-Wall -Wstrict-prototypes")
SET(CTUNING "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
SET(COPT "-Os")
SET(CMCU "-mmcu=atmega32")
SET(CDEFS "-DF_CPU=12000000UL")
SET(CFLAGS "${CMCU} ${CDEBUG} ${CDEFS} ${CINCS} ${COPT} ${CWARN} ${CSTANDARD} ${CEXTRA}")
SET(CXXFLAGS "${CMCU} ${CDEFS} ${CINCS} ${COPT}")
SET(CMAKE_C_FLAGS ${CFLAGS})
SET(CMAKE_CXX_FLAGS ${CXXFLAGS})
I use the cmake GUI, but i don't know how to use it.
I try as generator visual studio 10 (specify toolchain file for cross compiling), but it generates no makefile or hex file.
If i choose MinGW Makefiles as the generator, i get the error:
The C compiler "C:/WinAVR-20100110/bin/avr-gcc.exe" is not able to compile
a simple test program.
I hope somebody can help me, THANKS!
You have the CMAKE_SYSTEM_NAME set to windows, you need to set this to generic to enable Cross compiling eg:
SET(CMAKE_SYSTEM_NAME Generic)

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