简体   繁体   English

cmake 为 riscv64-unknown-elf-g++ 编译时如何出错

[英]how cmake Error in compiling for riscv64-unknown-elf-g++

The error looks like the below when I cmake.. from the terminal:当我从终端 cmake.. 时,错误如下所示:

(base) k:~ cd /Users/yuli/Documents/version3/cpp/
(base) k:~ ls
CMakeLists.txt      src
riscv-gnu-toolchain test
(base) k:~ mkdir build
(base) k:~ cd build
(base) k:~ cmake ..
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.
CMake Error at CMakeLists.txt:10 (if):
  if given arguments:

    "/Library/Developer/CommandLineTools/usr/bin/c++" "MATCHES" ".*riscv64-unknown-elf-g++"

  Regular expression ".*riscv64-unknown-elf-g++" cannot compile


-- Configuring incomplete, errors occurred!
See also "/Users/yuli/Documents/version3/cpp/build/CMakeFiles/CMakeOutput.log".

I tried "STREQUAL" instead of MATCHES but didn't work.我尝试了“STREQUAL”而不是 MATCHES,但没有奏效。 any idea what might be wrong in here?知道这里可能有什么问题吗?

CMakeLists.txt as follows: CMakeLists.txt 如下:

cmake_minimum_required(VERSION 3.13)
project(ofdmchain)

set(CMAKE_CXX_FLAGS "-std=c++14")

add_definitions(-DCOMPILES_ON_PC -Wall -Wextra)

configure_file(${CMAKE_SOURCE_DIR}/src/config.hpp.in ${CMAKE_BINARY_DIR}/config.hpp)

if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g++")
  message(STATUS "Compiling RISCV")
  SET(RISCV 1)
else()
  message(STATUS "Compiling X86")
  SET(RISCV 0)
endif()

add_library(ofdm
  src/transmitter.cpp
  src/configuration.cpp

  src/ofdm.hpp
  src/datatypes.hpp
  )
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/../reference_matlab)
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/src/)

if (NOT ${RISCV})
  add_executable(unit_tests
    test/catch_main.cpp
    test/test_sanity.cpp
    test/test_utilities.cpp
    test/test_transmitter.cpp
    )
  target_include_directories(unit_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
  target_include_directories(unit_tests PUBLIC ${CMAKE_SOURCE_DIR}/src)
  target_link_libraries(unit_tests ofdm)
endif()

I have also tried adding ++ where g++ exits as well as - where - exists.我还尝试在 g++ 退出的地方以及存在的地方添加 ++。 And also have tired "STREQUAL" instead of "MATCHES" it didn't work either.并且也厌倦了“STREQUAL”而不是“MATCHES”,它也不起作用。 It could be the problem of c++ in the PATH?可能是PATH中c++的问题?

CMake "internal error" CMake“内部错误”

RegularExpression::compile(): Nested *?+.

is about the last two + characters: in regular expressions such characters has special meaning.关于最后两个+字符:在正则表达式中,这样的字符具有特殊含义。

Ways for make + character (and other special characters) to be treated literally :从字面上处理 make +字符(和其他特殊字符)的方法:

  1. Escape the character with \ .\转义字符。 Note, that escape character by itself should be escaped in CMake string, so you need to write it twice :注意,转义字符本身应该在 CMake 字符串中转义,所以你需要写两次

     if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g\\+\\+")
  2. Put the character into square brackets ( [] ).将字符放入方括号( [] ) 中。 Inside [] all special characters loose their special meaning:[]内,所有特殊字符都失去了它们的特殊含义:

     if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g[+][+]")

Note also, that in certain if conditions one doesn't need to explicitly dereference the variable: CMake does that by itself.另请注意,在某些if下,不需要显式取消引用变量:CMake 会自行执行此操作。

So, it is possible to write所以,可以写

if(CMAKE_CXX_COMPILER MATCHES ".*riscv64-unknown-elf-g[+][+]")

See more in the documentation for if command.if命令的文档中查看更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM