0

当我从终端 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".

我尝试了“STREQUAL”而不是 MATCHES,但没有奏效。知道这里可能有什么问题吗?

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

我还尝试在 g++ 退出的地方以及 - where - 存在的地方添加 ++。并且也厌倦了“STREQUAL”而不是“MATCHES”,它也不起作用。可能是PATH中c++的问题?

4

1 回答 1

1

CMake“内部错误”

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

是关于最后两个+字符:在正则表达式中,这些字符具有特殊含义。

使+字符(和其他特殊字符)按字面处理的方法:

  1. 用转义字符\。注意,转义字符本身应该在 CMake 字符串中转义,所以你需要写两次

    if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g\\+\\+")
    
  2. 将字符放入方括号( []) 中。在[]所有特殊字符内部都失去了它们的特殊含义:

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

另请注意,在某些if情况下,不需要显式取消引用变量:CMake 自己会这样做。

所以,可以写

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

在命令文档中查看更多信息。if

于 2020-07-06T08:56:10.730 回答