run C exe that linked with 2 GO dynamic link shared object .
text
“*Go code linked into, and called from, a non-Go program
In this mode Go code acts as a library that may be called by a non-Go program. A single Go library will be an archive, a .a file on Unix, that will act as a unit, providing a C style API. If some of the execution modes below are implemented, then it will also be possible to implement this as a shared library, a .so file on Unix.
This mode supports people who must work with large existing programs, especially in C/C++ but possibly in other languages as well. It permits them to extend those existing programs with new packages written in Go.
In the Go 1.5 release this mode is implemented, using a .a file, for most Unix systems*.”
it is already supported.
when I run sample program, that load 2 GO sharead object, that code behave unexpcted and crash
- go
/*
#include <stdio.h>
*/
import "C"
import (
"reflect"
"unsafe"
)
func main() {
}
//export CallAddCheckA
func CallAddCheckA( {
fmt.PrintLn("hello A")
}
- go
package main
/*
#include <stdio.h>
*/
import "C"
import (
"reflect"
"unsafe"
)
func main() {
}
//export CallAddCheckB
func CallAddCheckB( {
fmt.PrintLn("hello B")
}
- c
#include "../mainA.h"
#include "../mainB.h"
#include <sys/types.h>
#include "stdio.h"
#include <unistd.h>
#include <sys/syscall.h>
#include <pthread.h>
#include <stdlib.h>
int main()
{
CallAddCheckA();
CallAddCheckB();
}
when I call CallAddCheckB() from new thread, all works good
Yuval Abadi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.