Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Statically linking Nim code to Go

Tags:

go

nim-lang

I'm trying in Linux to statically link some code created in Nim into a Go application. I've followed the Nim Backend Integration docs and some articles for linking C in Go but haven't gotten it working.

Here's where I'm at so far...


Nim code target.nim:

proc testnim* {.exportc.} =
  echo "In Nim!"

I compile it with:

nim c --app:staticLib --noMain --header target.nim

Go code app.go:

package main

/*
#cgo CFLAGS: -I/my/path/to/target/nimcache
#cgo CFLAGS: -I/my/path/to/Nim/lib
#cgo LDFLAGS: /my/path/to/target/libtarget.a
#include "/my/path/to/target/nimcache/target.h"
*/
import "C"
import "fmt"

func main() {
  fmt.Println("In Go!")
  C.NimMain()
  C.testnim()
}

I tried building it both of these:

go build

go build --ldflags '-extldflags "-static"' app.go

Here's what I get:

# command-line-arguments
/my/path/to/target/libtarget.a(stdlib_system.o): In function `nimUnloadLibrary':
stdlib_system.c:(.text+0xe6f0): undefined reference to `dlclose'
/my/path/to/target/libtarget.a(stdlib_system.o): In function `nimLoadLibrary':
stdlib_system.c:(.text+0xe71b): undefined reference to `dlopen'
/my/path/to/target/libtarget.a(stdlib_system.o): In function `nimGetProcAddr':
stdlib_system.c:(.text+0xe750): undefined reference to `dlsym'
collect2: error: ld returned 1 exit status

So I'm missing something(s). I'm using Go 1.5 and Nim 0.11.3 (devel branch). Any advice or hints would be much appreciated.

like image 895
Lye Fish Avatar asked Sep 10 '15 21:09

Lye Fish


People also ask

What is the code for linking my NIN?

To link your NIN to an Mtn number, simply dial *785# using the mtn phone number you wish to link, enter your NIN and submit or; Dial *785#Your NIN# from the mtn phone number you wish to link.

How do I link my NIN to all lines?

Dial *785* NIN Number followed by the # key. If you do this correctly, the NIN number will be linked automatically to your mobile number. Alternatively, you can visit: https://mtnonline.com/nin/ You can also download the MyMTN app to submit your details.

Can two sims use one NIN?

So, if you have multiple SIM cards, the Federal Government said you can link all of them to one NIN. The government isn't against having multiple lines but stated that they must all be linked to NIN. On Channels Television Politics Today in 2021, he said: “We developed an app, when you go online, you will see it.


1 Answers

You're missing the libdl library. Add -ldl to your LDFLAGS

like image 87
JimB Avatar answered Nov 12 '22 23:11

JimB