oct1158@DESKTOP-UCV8LC8 /cygdrive/d/Code/C++/Ray/first
$ ls
Makefile test.cpp test_internal.cpp
oct1158@DESKTOP-UCV8LC8 /cygdrive/d/Code/C++/Ray/first
$ make
cp C:/Users/qwert2180/AppData/Local/Programs/Python/Python310/Lib/site-packages/ray/cpp/lib/libray_api.so libray_api.so
cp C:/Users/qwert2180/AppData/Local/Programs/Python/Python310/Lib/site-packages/ray/cpp/lib/libray_api.so ray_api.dll
g++ test_internal.cpp -o test_internal -D_GLIBCXX_USE_CXX11_ABI=0 -IC:/Users/qwert2180/AppData/Local/Programs/Python/Python310/Lib/site-packages/ray/cpp/include -L. -lray_api
g++ test.cpp -o test -D_GLIBCXX_USE_CXX11_ABI=0 -IC:/Users/qwert2180/AppData/Local/Programs/Python/Python310/Lib/site-packages/ray/cpp/include -L. -lray_api
/usr/lib/gcc/x86_64-pc-cygwin/13/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccrLaO7V.o:test.cpp:(.text+0x233): undefined reference to ray::Init()' /usr/lib/gcc/x86_64-pc-cygwin/13/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccrLaO7V.o:test.cpp:(.text+0x323): undefined reference to ray::Shutdown()’
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: test] Error 1
oct1158@DESKTOP-UCV8LC8 /cygdrive/d/Code/C++/Ray/first
$ ls
Makefile ray_api.dll test_internal.cpp
libray_api.so test.cpp test_internal.exe
oct1158@DESKTOP-UCV8LC8 /cygdrive/d/Code/C++/Ray/first
$ ./test_internal
Segmentation fault
oct1158@DESKTOP-UCV8LC8 /cygdrive/d/Code/C++/Ray/first
$
【Environment】
Windows 11 + Python 3.10.11 + cygwin
【Makefile】
RAY_CPP_DIR=C:/Users/qwert2180/AppData/Local/Programs/Python/Python310/Lib/site-packages/ray/cpp
all: test_internal test
test_internal: test_internal.cpp ray_api.dll
$(CXX) test_internal.cpp -o test_internal -D_GLIBCXX_USE_CXX11_ABI=0 -I$(RAY_CPP_DIR)/include -L. -lray_api
test: test.cpp ray_api.dll
$(CXX) test.cpp -o test -D_GLIBCXX_USE_CXX11_ABI=0 -I$(RAY_CPP_DIR)/include -L. -lray_api
ray_api.dll:
cp $(RAY_CPP_DIR)/lib/libray_api.so libray_api.so
cp $(RAY_CPP_DIR)/lib/libray_api.so ray_api.dll
clean:
$(RM) test_internal test libray_api.so ray_api.dll
【test_internal.cpp】
#include <ray/api.h>
extern “C”
{
namespace ray
{
namespace internal
{
msgpack::sbuffer TaskExecutionHandler(const std::string &func_name, const ArgsBufferList &args_buffer, msgpack::sbuffer *actor_ptr);
ray::internal::FunctionManager &GetFunctionManager();
std::pair<const RemoteFunctionMap_t &, const RemoteMemberFunctionMap_t &> GetRemoteFunctions();
void InitRayRuntime(std::shared_ptr runtime);
}
}
}
int main()
{
ray::internal::GetFunctionManager();
ray::internal::GetRemoteFunctions();
return 0;
}
【test.cpp】
#include <ray/api.h>
#include
int MyFunction()
{
return 1;
}
RAY_REMOTE(MyFunction);
int SlowFunction()
{
std::this_thread::sleep_for(std::chrono::seconds(10));
return 1;
}
RAY_REMOTE(SlowFunction);
int main()
{
ray::Init();
ray::ObjectRef res = ray::Task(MyFunction).Remote();
std::shared_ptr<int> value = res.Get();
std::cout << "value=" << *value << std::endl;
for (int i = 0; i < 4; i++)
ray::Task(SlowFunction).Remote();
ray::Shutdown();
return 0;
}