跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • go 的 cgo 怎么用啊?
未分類
12 1 月 2021

go 的 cgo 怎么用啊?

go 的 cgo 怎么用啊?

資深大佬 : lysS 0

这段代码直接报错:

package main  // #include <stdio.h> // #include <stdlib.h> /* void print(char *str) {     printf("%sn", str); } */ import "C"  import "unsafe"  func main() {  s := "Hello Cgo"  cs := C.CString(s)  C.print(cs)  C.free(unsafe.Pointer(cs)) }  

go 的 cgo 怎么用啊?

说一下我的需求:golang 编译的 dll 动态库输出字符串
如果是这段代码:

import "C"  func main() {  Hello_world() }  //export Hello_world func Hello_world() string {  return "hello dart!!" } 

编译的 dll,使用 py 调用的结果是一串数字830403984

from ctypes import CDLL, c_char_p  dll = CDLL("./hello_world.dll") r = dll.Hello_world() print(r) 

查了一下,需要把 go 的 string 转换为对应的 C 的类型,就有最开始那个问题; 给我整蒙了。。。。

大佬有話說 (0)

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具