cmake “目标包含生成器不支持的C++模块源代码”

sqyvllje  于 2022-11-11  发布在  其他
关注(0)|答案(1)|浏览(155)

我在使用C20模块和VSCode、CMake编译任何内容时遇到一些问题(3.25.0-rc 3)和G,在M1 macbook上使用(据我所知)UnixMakefile.事实上,我甚至无法通过CMake的生成阶段,因为每次我尝试的时候,我都会得到错误“目标包含生成器不支持的C++模块源代码”。我遗漏了什么简单的东西吗?我目前正在尝试使用Bill霍夫曼昨天上传的CppCon演讲中的设置。(https://youtu.be/5X803cXe02Y?t=2288
我CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)
project(TryingModules CXX)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046")

set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
  "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E -x c++ <SOURCE>"
  " -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
  " -fmodules-ts -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT> -fdep-format=trtbd"
  " -o <PREPROCESSED_SOURCE>")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "g++")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG "-fmodules-ts -fmodule-mapper=<MODULE_MAP_FILE> -fdep-format=trtbd -x c++")

set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "g++")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_FLAG
    "${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
set(CMAKE_CXX_FLAGS "-fmodules-ts")

add_library(TryingModules)
target_link_libraries(TryingModules)

target_sources(TryingModules PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES moduleTest.cpp)

add_executable(main main.cpp)
target_link_libraries(main TryingModules)

我的主页。cpp:


# include <iostream>

import moduleTest;

int main(int, char**) {
    SayHello();
}

和我模块Test.cpp:

export module moduleTest;

# include <iostream>

export void SayHello()
{
    std::cout << "Hello :)" << '\n';
}

完整输出:

[main] Configuring folder: TryingModules
[proc] Executing command: /Applications/CMake.app/Contents/bin/cmake --no-warn-unused-cli
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/opt/homebrew/bin/aarch64-apple-darwin21-gcc-12
-DCMAKE_CXX_COMPILER:FILEPATH=/usr/local/bin/g++ -S/Users/rooster/Documents/TryingModules -B/Users/rooster/Documents/TryingModules/build -G "Unix Makefiles"
[cmake] CMake Warning (dev) at CMakeLists.txt:26 (target_sources):
[cmake]   CMake's C++ module support is experimental.  It is meant only for
[cmake]   experimentation and feedback to CMake developers.
[cmake] This warning is for project developers.  Use -Wno-dev to suppress it.
[cmake]
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done [cmake] CMake Error in CMakeLists.txt:
[cmake]   The "TryingModules" target contains C++ module sources which are not
[cmake]   supported by the generator
[cmake]
[cmake]
[cmake] -- Generating done
[cmake] CMake Generate step failed.  Build files cannot be regenerated correctly.
[proc] The command: /Applications/CMake.app/Contents/bin/cmake
--no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/opt/homebrew/bin/aarch64-apple-darwin21-gcc-12
-DCMAKE_CXX_COMPILER:FILEPATH=/usr/local/bin/g++ -S/Users/rooster/Documents/TryingModules -B/Users/rooster/Documents/TryingModules/build -G "Unix Makefiles" exited with code: 1 and signal: null

我试过不同的文件扩展名组合(.cpp.cppm.ixx.cxx等)在主模块和模块上测试(相应地更新了CMakeLists.txt)并且我已经多次尝试重新生成这个项目了。所以我可能完全找错了对象--因为事情是围绕着我建立的。任何帮助都是感激的,如果我需要提供任何更多的信息或任何东西,请让我知道。

guykilcj

guykilcj1#

你需要使用忍者构建作为一个发电机。

cmake -GNinja .

关于includes,我相信您的moduleTest.cpp应该看起来像这样:

module;

# include <iostream>

export module moduleTest;

export void SayHello()
{
    std::cout << "Hello :)" << '\n';
}

相关问题