There are currently 4 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
114 3
Linux系统Makefile方式编译Ray C++程序
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 5/20/26 17:41
【openssl_test.cpp】
#include <iostream>
#include <string>
#include <openssl/ssl.h>
#include <ray/api.h>

std::string openssl_test()
{
    char str[50];
    const SSL_METHOD *method;
    SSL_CTX *ctx;
    
    SSL_library_init();
    method = SSLv23_method();
    if (method != NULL)
    {
        snprintf(str, sizeof(str), "method=%p", method);
        ctx = SSL_CTX_new(method);
        if (ctx != NULL)
            SSL_CTX_free(ctx);
    }
    return str;
}
RAY_REMOTE(openssl_test);

int main()
{
    ray::Init();
    
    ray::ObjectRef res = ray::Task(openssl_test).Remote();
    std::shared_ptr<std::string> value = res.Get();
    std::cout << "value=" << *value << std::endl;
    
    ray::Shutdown();
    return 0;
}

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 5/20/26 17:41

【Makefile】

RAY_CPP_DIR=/home/oct1158/.local/lib/python3.10/site-packages/ray/cpp

openssl_test: openssl_test.cpp libopenssl_test.so
    $(CXX) openssl_test.cpp -o $@ -D_GLIBCXX_USE_CXX11_ABI=0 -lssl -lcrypto -I$(RAY_CPP_DIR)/include -L$(RAY_CPP_DIR)/lib -lray_api -Wl,-rpath,$(RAY_CPP_DIR)/lib
    
libopenssl_test.so: openssl_test.cpp
    $(CXX) openssl_test.cpp -o $@ -shared -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -lssl -lcrypto -I$(RAY_CPP_DIR)/include -L$(RAY_CPP_DIR)/lib -lray_api

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 5/20/26 17:42
【程序运行结果】
oct1158@oct1158-ubuntu:~/Documents/Code/C/ray/openssl_test$ ls
Makefile  openssl_test.cpp
oct1158@oct1158-ubuntu:~/Documents/Code/C/ray/openssl_test$ make
g++ openssl_test.cpp -o libopenssl_test.so -shared -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -lssl -lcrypto -I/home/oct1158/.local/lib/python3.10/site-packages/ray/cpp/include -L/home/oct1158/.local/lib/python3.10/site-packages/ray/cpp/lib -lray_api
g++ openssl_test.cpp -o openssl_test -D_GLIBCXX_USE_CXX11_ABI=0 -lssl -lcrypto -I/home/oct1158/.local/lib/python3.10/site-packages/ray/cpp/include -L/home/oct1158/.local/lib/python3.10/site-packages/ray/cpp/lib -lray_api -Wl,-rpath,/home/oct1158/.local/lib/python3.10/site-packages/ray/cpp/lib
oct1158@oct1158-ubuntu:~/Documents/Code/C/ray/openssl_test$ ./openssl_test
[2026-05-20 17:41:55,376 I 16738 16738] config_internal.cc:218: No code search path found yet. The program location path "/home/oct1158/Documents/Code/C/ray/openssl_test" will be added for searching dynamic libraries by default. And you can add some search paths by '--ray_code_search_path'
[2026-05-20 17:41:55,377 I 16738 16738] process_helper.cc:51: ray start --head --port 6379 --redis-username default --redis-password 5241590000000000 --node-ip-address '192.168.71.129'
Usage stats collection is enabled. To disable this, add `--disable-usage-stats` to the command that starts the cluster, or run the following command: `ray disable-usage-stats` before starting the cluster. See https://docs.ray.io/en/master/cluster/usage-stats.html for more details.

Local node IP: 192.168.71.129

--------------------
Ray runtime started.
--------------------

Next steps
  To add another node to this Ray cluster, run
    ray start --address='192.168.71.129:6379'

  To connect to this Ray cluster:
    import ray
    ray.init(_node_ip_address='192.168.71.129')

  To submit a Ray job using the Ray Jobs CLI:
    RAY_API_SERVER_ADDRESS='http://127.0.0.1:8265' ray job submit --working-dir . -- python my_script.py

  See https://docs.ray.io/en/latest/cluster/running-applications/job-submission/index.html
  for more information on submitting Ray jobs to the Ray cluster.

  To terminate the Ray runtime, run
    ray stop

  To view the status of the cluster, use
    ray status

  To monitor and debug Ray, view the dashboard at
    127.0.0.1:8265

  If connection to the dashboard fails, check your firewall settings and network configuration.
[2026-05-20 17:42:18,888 I 16738 16738] gcs_client.cc:96: GcsClient has no Cluster ID set, and won't fetch from GCS.
[2026-05-20 17:42:18,902 I 16738 16738] gcs_client.cc:96: GcsClient has no Cluster ID set, and won't fetch from GCS.
value=method=0x71c55f30f2c0
Stopped only 6 out of 7 Ray processes within the grace period 16 seconds. Set `-v` to see more details. Remaining processes [psutil.Process(pid=16777, name='python3', status='terminated')] will be forcefully terminated.
You can also use `--force` to forcefully terminate processes or set higher `--grace-period` to wait longer time for proper termination.
oct1158@oct1158-ubuntu:~/Documents/Code/C/ray/openssl_test$

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 4 Posted at: 5/20/26 18:46

【另一种写法】

#include <iostream>
#include <string>
#include <openssl/ssl.h>
#include <ray/api.h>

class Test
{
private:
    char str[50];
    SSL_CTX *ctx;
public:
    Test();
    ~Test();
    std::string get_str();
};

Test::Test()
{
    const SSL_METHOD *method;
    
    SSL_library_init();
    method = SSLv23_method();
    if (method != NULL)
    {
        snprintf(str, sizeof(str), "method=%p", method);
        ctx = SSL_CTX_new(method);
    }
}

Test::~Test()
{
    if (ctx != NULL)
        SSL_CTX_free(ctx);
}

std::string Test::get_str()
{
    return str;
}

Test *CreateTest()
{
    return new Test();
}
RAY_REMOTE(CreateTest, &Test::get_str);

int main()
{
    ray::Init();
    
    ray::ActorHandle<Test> actor = ray::Actor(CreateTest).Remote();
    ray::ObjectRef res = actor.Task(&Test::get_str).Remote();
    std::shared_ptr<std::string> value = res.Get();
    std::cout << "value=" << *value << std::endl;
    
    ray::Shutdown();
    return 0;
}

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 114 Replies: 3
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 5/20/26 18:46
Announcements