我目前正在开发一个需要 C++20 (g++ v11) 功能和 CMake 的项目。项目树类似于以下项目:
- Top level
- src
- IO
- IO.cpp
- CMakeLists.txt
- main.cpp
- CMakeLists.txt
Run Code Online (Sandbox Code Playgroud)
CMake 编译 IO 模块没有任何问题,但它通过以下方式生成 gcm.cache 文件夹:
- build
- Some other CMake files and folders
- bin
- lib
- src
- IO
- gcm.cache
- IO.gcm
Run Code Online (Sandbox Code Playgroud)
因此,g++ 找不到 gcm.cache 文件夹并给出以下错误:
IO: error: failed to read compiled module: No such file or directory
IO: note: compiled module file is 'gcm.cache/IO.gcm'
IO: note: imports must be built before being imported
IO: fatal error: returning to the gate for a mechanical issue
Run Code Online (Sandbox Code Playgroud)
如果有人告诉我有一种方法可以使用 CMake 指定 gcm.cache 位置或强制 CMake 递归搜索 gcm 文件或告诉它创建顶级 gcm.cache 并将所有内容存储在其中,我将不胜感激。由于 C++20 文档很糟糕,我在任何地方都找不到任何答案。提前致谢...
我遇到过完全相同的问题,并且在没有实际找到解决方案的情况下找到了解决方法。完整代码可以在这里找到。
\n简而言之,我创建了一个符号链接,以便子项目都使用位于项目根目录中的 gcm.cache/ 目录。像这样创建一个符号链接:
\nln -fs ../gcm.cache gcm.cache\nRun Code Online (Sandbox Code Playgroud)\n这是项目的目录树:
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 engine\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 core\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 types.cpp\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 engine.cpp\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 gcm.cache -> ../gcm.cache\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Makefile\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 memory\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 gcm.cache\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 init.sh\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Makefile\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 testgame\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 gamelib.cpp\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 gcm.cache -> ../gcm.cache\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Makefile\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test.cpp\nRun Code Online (Sandbox Code Playgroud)\n因此,当 gcc 构建engine并testgame项目时,它实际上使用根目录中的 gcm.cache/ 。在出现更好的东西之前,这是我的首选方法。