简体   繁体   English

无法运行 c++ 演员框架你好世界代码

[英]unable to run c++ actor framework hello world code

i am trying to run the hello world example of the c++ actor framework.我正在尝试运行 c++ actor 框架的 hello world 示例。 when trying to build in vscode with the cmaketools extension, i get the output that the package CAF is not found.当尝试使用 cmaketools 扩展在 vscode 中构建时,我得到 output,即找不到 package CAF。 when i comment out the caf related lines in all cmakelists.txt files, cmake builds the test.cpp and i can run the test.exe.当我注释掉所有 cmakelists.txt 文件中与 caf 相关的行时,cmake 构建了 test.cpp,我可以运行 test.exe。 ihave installed caf and catch2 via vcpkg as shown in the console output picture.我已经通过 vcpkg 安装了 caf 和 catch2,如控制台 output 图片所示。 at catch2, i am using the findpackage and target_link_libraries as shown in the picture in the CMakeLists.txt.在 catch2,我使用的是 findpackage 和 target_link_libraries,如 CMakeLists.txt 中的图片所示。 but caf does not provide any info how to findpackage and target_link_libraries.但 caf 不提供任何信息如何找到包和 target_link_libraries。 on caf's git there is the find_package(CAF REQUIRED), but it doesnt work.在 caf 的 git 上有 find_package(需要 CAF),但它不起作用。 i tried to find out what other packages exist caf provides but didnt find any.我试图找出 caf 提供的其他软件包,但没有找到。

控制台输出通过 vcpkg 安装 caf 和 catch2

./CMakeLists.txt: ./CMakeLists.txt:

cmake_minimum_required(VERSION 3.18.1)

set(CMAKE_TOOLCHAIN_FILE "c:/Users/daniel/Documents/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake") #relative path does not work    
set(CMAKE_CXX_STANDARD 14)

project(mgoe)    

find_package(Catch2 CONFIG REQUIRED)
find_package(CAF REQUIRED)
    
add_subdirectory(programs)

./programs/CMakeLists.txt: ./programs/CMakeLists.txt:

add_executable(caf_helloworld caf_helloworld.cpp)
add_executable(test test.cpp)

target_link_libraries(
   caf_helloworld

   libcaf_io
   libcaf_core
)


target_link_libraries(
   test 
   Catch2::Catch2
)

./programs/caf_helloword.cpp: ./programs/caf_helloword.cpp:

#include <iostream>

#include "caf/all.hpp"

using std::endl;
using std::string;

using namespace caf;

behavior mirror(event_based_actor* self) {
  // return the (initial) actor behavior
  return {
    // a handler for messages containing a single string
    // that replies with a string
    [=](const string& what) -> string {
      // prints "Hello World!" via aout (thread-safe cout wrapper)
      aout(self) << what << endl;
      // reply "!dlroW olleH"
      return string(what.rbegin(), what.rend());
    }
  };
}

void hello_world(event_based_actor* self, const actor& buddy) {
  // send "Hello World!" to our buddy ...
  self->request(buddy, std::chrono::seconds(10), "Hello World!").then(
    // ... wait up to 10s for a response ...
    [=](const string& what) {
      // ... and print it
      aout(self) << what << endl;
    }
  );
}

void caf_main(actor_system& system) {
  // create a new actor that calls 'mirror()'
  auto mirror_actor = system.spawn(mirror);
  // create another actor that calls 'hello_world(mirror_actor)';
  system.spawn(hello_world, mirror_actor);
  // system will wait until both actors are destroyed before leaving main
}

// creates a main function for us that calls our caf_main
CAF_MAIN()

./programs/test.cpp: ./programs/test.cpp:

#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
#include "catch2/catch.hpp"

cmake tools building output: cmake 工具楼 output:

[main] Ordner wird erstellt: mgoe 
[build] Build wird gestartet.
[proc] Befehl wird ausgeführt: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/daniel/Documents/projects/mgoe/build --config Release --target ALL_BUILD -- /maxcpucount:6
[build] CMake is re-running because C:/Users/daniel/Documents/projects/mgoe/build/CMakeFiles/generate.stamp is out-of-date.
[build]   the file 'C:/Users/daniel/Documents/projects/mgoe/CMakeLists.txt'
[build]   is newer than 'C:/Users/daniel/Documents/projects/mgoe/build/CMakeFiles/generate.stamp.depend'
[build]   result='-1'
[build] -- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
[build] CMake Error at C:/Users/daniel/Documents/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:493 (_find_package):
[build]   By not providing "FindCAF.cmake" in CMAKE_MODULE_PATH this project has
[build]   asked CMake to find a package configuration file provided by "CAF", but
[build]   CMake did not find one.
[build] 
[build]   Could not find a package configuration file provided by "CAF" with any of
[build]   the following names:
[build] 
[build]     CAFConfig.cmake
[build]     caf-config.cmake
[build] 
[build]   Add the installation prefix of "CAF" to CMAKE_PREFIX_PATH or set "CAF_DIR"
[build] -- Configuring incomplete, errors occurred!
[build] See also "C:/Users/daniel/Documents/projects/mgoe/build/CMakeFiles/CMakeOutput.log".
[build]   to a directory containing one of the above files.  If "CAF" provides a
[build]   separate development package or SDK, be sure it has been installed.
[build] Call Stack (most recent call first):
[build]   CMakeLists.txt:12 (find_package)
[build] 
[build] 
[build] CMake Configure step failed.  Build files cannot be regenerated correctly.
[cmakefileapi-parser] Unerwartete Codemodellversion (2.1) von cmake-file-api. Erwartet: (2.0). Möglicherweise ist die IntelliSense-Konfiguration falsch.
[cmakefileapi-parser] Unerwartete Codemodellversion (2.1) von cmake-file-api. Erwartet: (2.0). Möglicherweise ist die IntelliSense-Konfiguration falsch.
[build] Der Build wurde mit dem Exitcode 4294967295 abgeschlossen.

CAF is not exporting/installing CMake targets as such it is not available via find_package . CAF 不导出/安装 CMake 目标,因此它无法通过find_package I looked into the buildtree and saw a FindCAF.cmake in the cmake subdir.我查看了构建树并在cmake子目录中看到了FindCAF.cmake
Open up an issue in vcpkg that this file should be installed into the appropriate location or ask upstream to install it (Why it is supplied but not installed is beyond me).在 vcpkg 中打开一个问题,该文件应该安装到适当的位置,或者要求上游安装它(为什么提供但不安装我不明白)。 As a quick workaround you should simply be able to copy the file to your CMAKE_MODULE_PATH作为一种快速解决方法,您应该只需将文件复制到您的CMAKE_MODULE_PATH

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

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