I just write a very simple demo to test load the shared library with cgo(golang).the code as follow:
xxx.h
#pragma once
void myprint(const char *str);
xxx.c
#include "xxx.h"
#include <stdio.h>
void myprint(const char *str) {
printf("%s
",str);
}
build shared library:
gcc -fPIC -shared xxx.c -o libxxx.so
ok,everything is ok from here.
now ,use the cgo load the libxxx.so,and use the myprint function:
package main
/*
#include <stdio.h>
#cgo linux CFLAGS: -I../../include
#cgo linux LDFLAGS: -L../../lib/linux -lxxx
#include "xxx.h"
*/
import "C"
funct main() {
C.myprint(C.CString("xxx"))
}
then, build the go demo:
go build test.go
as my title show:
error: undefined reference to 'myprint'
i ensure the path of lib/head file is right, Who can help me find the reason? thx.