Call the .net dlls into the golang

282 views
Skip to first unread message

Pavan Kumar A R

unread,
May 22, 2024, 8:31:04 AM5/22/24
to golang-nuts

Hello ,

I build the.net dlls in the target framework, which is.net-framework 2.0, and inside the.net dlls are some functions. I want to call this function in Golang. How can I call the.net function in Golang? Please help out here.

Carla Pfaff

unread,
May 22, 2024, 9:48:24 AM5/22/24
to golang-nuts
You can't call .NET functions directly from Go. Go programs and .NET have two completely different runtimes. You would need some form of inter-process communication (IPC).

Pavan Kumar A R

unread,
May 22, 2024, 12:04:19 PM5/22/24
to Carla Pfaff, golang-nuts

Okay,  it's possible to call the C program to Golang. Because I also have the C platform dlls and the C platform dlls  we using in the cross platform mono and in the mono internally call the.net dlls function , can I use the C program dlls in Golang?  

Carla Pfaff

unread,
May 22, 2024, 4:41:13 PM5/22/24
to golang-nuts
Yes, you can call C functions from Go, it's called Cgo: https://go.dev/blog/cgo

peterGo

unread,
May 22, 2024, 5:23:12 PM5/22/24
to golang-nuts
cgo command   
Cgo enables the creation of Go packages that call C code.   

Pavan Kumar A R

unread,
May 23, 2024, 8:47:10 AM5/23/24
to golang-nuts
Hello ,

I am try to call the c program in the golang , but i am getting the issue .  please see the error message :
package main

go list failed to return CompiledGoFiles. This may indicate failure to perform cgo processing; try building at the command line. See https://golang.org/issue/38990.go list

//#cgo LDFLAGS: -L. -llibCWrapper-win64 -Wl,-rpath,.
//#include "ealApiLib.h"

import "C"
import "fmt"

func main() {

    result := C.Connect("192.168.1.1")

    fmt.Println("connection success" + result)

}

Brian Candler

unread,
May 23, 2024, 9:21:34 AM5/23/24
to golang-nuts
"try building at the command line"

That's your clue. You'll most likely get a meaningful error message on stderr, which your IDE is hiding.

Reply all
Reply to author
Forward
0 new messages