V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
chengiri
V2EX  ›  程序员

有偿 求 go 调用 c++

  •  
  •   chengiri · 61 天前 · 2342 次点击
    这是一个创建于 61 天前的主题,其中的信息可能已经有所发展或是发生改变。

    不太会用 cgo ,能帮我正常调用的 bro ,请喝杯奶茶

    package main
    
    /*
    #cgo CFLAGS: -I./include -x c++
    #cgo LDFLAGS: -L./lib -lCameraSDK
    #include <camera/camera.h>
    #include <stdlib.h>
    #include <camera/device_discovery.h>
    #include <camera/photography_settings.h>
    */
    import "C"
    
    func main() {
    
    }
    
    

    device_discovery.h

    #pragma once
    #include <camera/ins_types.h>
    #include <vector>
    
    
    namespace ins_camera {
        /**
         * \class DeviceDiscovery
         * \brief a convenient class for discovery Insta360 camera devices. 
         */
        class CAMERASDK_API DeviceDiscovery {
        public:
            /**
             * \brief get a list of available devices. This method may establish a connection with
             *        detected cameras to get some basic information such as serial_number.
             * \return a list of DeviceDescriptor describing detected cameras. 
             *  Remember to call FreeDeviceDescriptors(std::vector<DeviceDescriptor> descs)
             *  on the returned list to avoid memory leak.
             */
            std::vector<DeviceDescriptor> GetAvailableDevices();
            /**
             * \brief free memory allocated for DeviceDescriptor
             */
            void FreeDeviceDescriptors(std::vector<DeviceDescriptor> descs);
        private:
            std::vector<DeviceDescriptor> GetAvailableUSBDevices();
            std::vector<DeviceDescriptor> GetAvailableWifiDevices();
        };
    }
    
    
    12 条回复    2024-02-27 16:39:40 +08:00
    anoyi
        1
    anoyi  
       61 天前
    ChatGPT 搞不定这个?
    mightybruce
        2
    mightybruce  
       61 天前   ❤️ 2
    你下面这个是 c++ 不是 C, 你要把 c++ 转成 C 的 接口, 才能调用

    只有 C 的 bindings 是通用的

    C 的代码,但要调用写好的 C++代码时,需要将 c++的类型配置为.lib 的静态库或是.dll 的动态库,然后通过 extern “c”调用
    Linux 则是.so 的共享库
    xxq2334
        4
    xxq2334  
       61 天前 via Android
    @mightybruce 这个大佬说的对
    0o0O0o0O0o
        5
    0o0O0o0O0o  
       61 天前
    正要发 chai2010 写的 CGO 部分,发现他本人已经发了
    totoro52
        6
    totoro52  
       61 天前
    我之前鼓动了好久的 CGO ,鼓动了两三天, 最后放弃,跟 2L 一样,直接编译成 so 库,动态加载就行,交互也超级容易,无语死, 至于 1L 说的 GPT 搞不定, 它是真的搞不定
    Jirajine
        7
    Jirajine  
       61 天前
    cpp 不是 c ,没法直接用 cgo 。你需要自己封装 c ffi ,或者 swig 能生成 bindings https://www.swig.org/Doc4.0/Go.html
    liberize
        8
    liberize  
       60 天前 via Android
    写一些 C 接口包装一下 C++接口,注意用 extern "C" { } 把这些 C 接口包起来
    dog82
        9
    dog82  
       60 天前
    曲线救国,把 c++封装成 restful
    hu8245
        10
    hu8245  
       60 天前
    你需要对 c++ 导出为 C 符号有点了解。你都 import "C" 了,cpp 的符号肯定不行啊。https://zhuanlan.zhihu.com/p/123269132
    uiluck
        11
    uiluck  
       60 天前
    利用 rpc 、http 呗
    tangtang369
        12
    tangtang369  
       60 天前
    直接 socket 封装个通信接口就行 就是部署的时候多了一个软件 但是功能实现起来更快
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1410 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:23 · PVG 01:23 · LAX 10:23 · JFK 13:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.