首页 > 解决方案 > CGO:指向从“char *”分配给“char”的整数转换的不兼容指针

问题描述

所以我正在尝试创建一个 go 函数,为我在 cgo 中的 ac struct 添加一个值。

package main

/*
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

typedef struct {
    char *response;
} Resp;

typedef struct {
    char resp_out;
} Resp_Out;

void reponse_return(Resp r_in, Resp_Out r_out)
{
    r_out.resp_out = r_in.response;
}
*/
import "C"

//export getResponse
func getResponse() C.Resp {
    C.Resp{
        response: C.CString("Hello World),
    }
}

getResponse 函数将“Hello World”添加到 C 结构中。现在我在 c 中尝试做的是创建 ac 函数,其中 Resp.response c 结构值将值赋予 Resp_Out.resp_out 值。但是当我尝试将其编译为共享对象时,我不断收到此错误。

duplicate symbol '_reponse_return' in:
    $WORK/b001/_x001.o
    $WORK/b001/_x002.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
# command-line-arguments
In file included from _cgo_export.c:4:
cgotest2.go:18:17: warning: incompatible pointer to integer conversion assigning to 'char' from 'char *'; dereference with * [-Wint-conversion]
# command-line-arguments
./cgotest2.go:18:17: warning: incompatible pointer to integer conversion assigning to 'char' from 'char *'; dereference with * [-Wint-conversion]

我该如何解决?

标签: cpython-3.xcgo

解决方案


推荐阅读