dtyyrt4545 2016-10-26 15:44
浏览 54

C和Golang集成问题

I have a C shared library named libtest.so which in turn use another shared library lihelp.so. The code for libtest.so use dlopen() to load the libhelp.so

I have integrated libtest.so with my GO script gotest.go

When I run gotest.go after building and installing, I am seeing libtest.so is getting loaded successfully and function in libtest is executed successfully. But the dlopen() call in libtest.so to load libhelp.so is failining with error "undefined symbol: dlopen"

But if I write a C application which use libtest.so all execution are fine withour any error.

Here is the code snippet of my Go file

/*
 #cgo CFLAGS: -I./include
 #cgo LDFLAGS: -L. -ltest -ldl
*/

Here is the Makefile entry for building libtest.so

CC = gcc # C compiler
CFLAGS = -c -fPIC -I./include # C flags
LDFLAGS = -shared -L/lib -ldl # linking flags

Can any one suggest what can be the problem?


Output of ldd of my go binary

ldd app
    linux-gate.so.1 =>  (0xb77c3000)
    libtest.so => ./libtest.so (0xb77bc000)
    libgo.so.5 => /usr/lib/i386-linux-gnu/libgo.so.5 (0xb6ed0000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb6eb2000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6d03000)
    /lib/ld-linux.so.2 (0xb77c4000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb6ce7000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6ca1000)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 vue3加ant-design-vue无法渲染出页面
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序