收藏
回答

workdwxsdk.so与pulsar.so.2.4.1不兼容问题

package main

import (
   "bytes"
   "fmt"
   "github.com/spf13/viper"
   "gitlab.xiaoduoai.com/marketing/base/queue"
   "os"
   "unsafe"
)
/*
#cgo CFLAGS: -I./
#cgo LDFLAGS: -L/home/zz/share/tmp/test/lib -lWeWorkFinanceSdk_C_old
#include <stdlib.h>
#include "WeWorkFinanceSdk_C.h"
*/
import "C" // 注意这个地方与上面注释的地方不能有空行,并且不能使用括号如import ("C" "fmt")

func main() {
   sdk := C.NewSdk()
   var (
      corpID string = "ww0273164e290049d5"
      secret string ="F2uftgCGNaYInskdrpo8LeAeX0N0iyPxpiMCRjyOk38"
      //jpg文件
      sdkfileid string = "CtQBMzA2ODAyMDEwMjA0NjEzMDVmMDIwMTAwMDIwNDgzMmZiZGMzMDIwMzBmNTliMTAyMDQ1YzliNTQ3NzAyMDQ1ZmEwMDQ2YjA0MjQ2MzM0MzczMzYyMzYzMjM1MmQzMTM3NjYzMjJkMzQzNTM3NjIyZDM4MzgzNjM0MmQzODYyMzY2NDY1Mzg2MjM0NjM2MjMyMzgwMjAxMDAwMjAyMmY3MDA0MTAwMzZiMDVjNGJiNTAyOWJjMjM2ZDI4ZjM1MDU4ZmIzNTAyMDEwMTAyMDEwMDA0MDASOE5EZGZNVFk0T0RnMU16RXdNelk0TWpZeU1GODROell5TVRneU5EaGZNVFl3TkRNeU1qUXhNZz09GiAzMTMwNjQ2NDMwNjQzMjM2MzUzOTMwMzE2NTM5NjM2MQ=="
   )

   //mp4视频
   sdkfileid = "CtYBMzA2OTAyMDEwMjA0NjIzMDYwMDIwMTAwMDIwNDgzMmZiZGMzMDIwMzBmNTliMzAyMDQxZjM2MGE2ZjAyMDQ1ZmEwMDYwOTA0MjQ2MzY2MzI2MjMyNjM2NTY2MmQzNjYzMzUzMDJkMzQzNTY0MzUyZDM5MzAzMzM5MmQzNTMxMzYzOTYzNjQzMTY0MzgzNTM5NjYwMjAxMDAwMjAzM2ZjZGQwM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DRhMDIzMGE2ZjAyMDQ1ZmEwY2EzMDA0MjQ2MTM0MzMzODM0NjQzMzM2MmQzNDM3NjMzMzJkMzQ2MjMxNjMyZDYxMzE2MzY2MmQzNTMwMzAzNzM0MzE2MjM1MzczOTM2MzYwMjAxMDAwMjAzMTU1YzEwMDQxMDA5ZDhiZmUwZmI2OGI2ZmEzYTIzZTQ2ODBlYmE2Mzc4MDIwMTAyMDIwMTAwMDQwMBI0TkRkZk1UWTRPRGcxTXpFd016WTRNall5TUY4ME5EZzVPVE0wTlY4eE5qQTBNemN6TURReBogOGRmZjAwM2E1MzU2NDgyM2E3OGVhYTc0YTIzMDk3ZTc="
   CorpID := C.CString(corpID)
   Secret := C.CString(secret)
   Sdkfileid := C.CString(sdkfileid)
   defer C.free(unsafe.Pointer(CorpID))
   Media_data := &C.MediaData_t{}
   C.Init(sdk, CorpID, Secret)
   fmt.Printf("GetMediaData")
   f, err := os.OpenFile("tupian", os.O_RDWR|os.O_CREATE, 0755)
   if err != nil {
      fmt.Printf("err:%v", err)
      return
   }
   outindexbuf := ""
   for {
      res := C.GetMediaData(sdk, C.CString(outindexbuf), Sdkfileid, nil, nil, 10, Media_data)
      data := C.GoStringN(Media_data.data, Media_data.data_len)
      nn, err := f.Write([]byte(data))
      fmt.Printf("nn:%v err:%v", nn, err)
      fmt.Printf("res:%v, Media_data:%v", res, *Media_data)
      outindexbuf = C.GoStringN(Media_data.outindexbuf, Media_data.out_len)
      fmt.Printf("outindexbuf:%v", outindexbuf)
      if Media_data.is_finish > C.int(0) {
         break
      }
   }
   
   viper.SetConfigType("json")
   conf := `
    {
      "producer":{
         "init_phone":{
            "url":"pulsar://pulsar-cluster01-slb:6650",
            "topic":"persistent://public/default/init_phone",
            "type":"pulsar"
         }
        }
   }
    `

   buf := new(bytes.Buffer)
   buf.Write([]byte(conf))
   _ = viper.ReadConfig(buf)

   pulsarClient, err := queue.NewProducer("producer.init_phone")
   fmt.Printf("%v, %v", pulsarClient, err)
}

单独调用sdk没问题,单独调用pulsar也没问题,但是两个写到一起就会出现类型转换错误,pulsar是用的libpulsar.so.2.4.1

怀疑与sdk依赖的boost库存在版本冲突,不知道这种情况怎么解决。开始用C++直接写,也存在此类问题

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签