-1

I want to call some c++ functions(which are specific for my c++ library ) in Go. But I am not sure, does Go support that?

I've already tried that calling dll functions from go

But it does not work for .so file

Do I have to write a c wrapper for my c++ code?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Mehmet Özcan
  • 85
  • 1
  • 5

1 Answers1

0

Because you're using .so which is Executable and Linkable Format (ELF) while your example uses .dll which is Portable Executable Format (PE). I'm not familiar with GoLang but it appears that syscall is used for lower level OS API, which is clear seeing that it uses LoadLibrary and GetProcAddress, both part of Windows API. You would do roughly the same thing but using Linux API rather than Windows API.

Pickle Rick
  • 808
  • 3
  • 6
  • I know, thats why I said "it does not work for .so file". I could not find anything about linux side except SWIG and writing wrapper – Mehmet Özcan Nov 22 '19 at 06:06
  • Oh, I'm sorry. I thought you were asking why the example you linked wasn't working for you, not that you specifically wanted to know how to load libraries from Linux. – Pickle Rick Nov 22 '19 at 06:08
  • No problem Pickle, even so thanks for your comment – Mehmet Özcan Nov 22 '19 at 06:10
  • 2
    Unfortunately I'm not familiar at all with either Linux or GoLang, but from a cursory look it seems that you're looking for [dlopen](http://man7.org/linux/man-pages/man3/dlopen.3.html) to replace ``LoadLibrary`` and [dlsym](http://man7.org/linux/man-pages/man3/dlsym.3.html) to replace ``GetProcAddress``. From there you would invoke the imported method via ``syscall.Syscall(...)`` the same way as the example. – Pickle Rick Nov 22 '19 at 06:13