c - 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]
我该如何解决?
解决方案
推荐阅读
- c++ - boost::asio 数据拥有`ConstBufferSequence`
- python - 这将是什么代码?你必须用python解决
- windows - 如何记录CMD输出?
- android - Android Studio Portable 设置中的 Flutter Doctor 问题“未找到 Android Studio”
- python-3.x - BayesSearchCV 在 SGDClassifier 参数调整期间不起作用
- java - 我如何访问paintcomponent graphics g 变量以从其他方法中绘制东西?
- javascript - 如何更有效地将这些任务分配到批次中?
- css - 前端 - 当我们减小缩放大小时,为什么某些网站会改变它们的外观
- typescript - Vue - 在工作区和独立中转到定义
- android - 解决了依赖配置“:app:myappDebugApiElements”后无法创建变体“android-manifest-metadata”