Undefined reference to `ray::Init()'

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;

}

Ray’s C++ API is not supported on Windows (including Cygwin), which is the root cause of your build and runtime errors. The official documentation and codebase state that the C++ API is experimental and only supported on Linux. Attempting to use it on Windows (even via Cygwin) will result in linker errors and segmentation faults, as you observed (source, source).

If you need to use Ray’s C++ API, you must use a Linux environment (native or via WSL2). There is no workaround for Windows at this time. Would you like more detail on setting up Ray C++ on Linux?

Sources:

Hint: Mention @RunLLM in the post for followups.

Is there any plan to support Windows in the future?