V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2WT
V2EX  ›  问与答

Cgo 如何传递 函数指针给 注册回调函数的函数?

  •  
  •   V2WT · Sep 4, 2019 · 1804 views
    This topic created in 2432 days ago, the information mentioned may be changed or developed.

    如题,我有一个 C 的 .so, 里面有一个函数是注册回调的。 类似于

    #ifndef __TEST_H__
    #define __TEST_H__
    #ifdef __cplusplus
    extern "C"{
    #endif
    
    #define API __attribute__((visibility("default")))
    
    typedef struct info{
        int a;
    }tInfo;
    
    typedef int(*cb) (tInfo* n);
    
    
    API int setcallback(cb s);
    
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif
    
    

    现在我想在 Go 里面通过 Cgo 调用setcallback,我要怎么做呢? 看了半天资料 还是看不懂。。

    2 replies    2019-09-05 08:56:09 +08:00
    V2WT
        1
    V2WT  
    OP
       Sep 4, 2019
    zizhoutong
        2
    zizhoutong  
       Sep 5, 2019
    吓我一跳,你这头像我以为前女友呢 : )
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2503 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 02:43 · PVG 10:43 · LAX 19:43 · JFK 22:43
    ♥ Do have faith in what you're doing.