How to use go library

I want to create a go library and use it with go application using LD_PRELOAD. Suppose my library code is in a folder golib.

create library
go install -buildmode=shared golib
It will create

create application
go build gosampleapp.go
It will create gosampleapp. To use the library run following command

export LD_PRELOAD=path of; ./gosampleapp

It will give the error “undefined symbol: main.main”

But if I compile the library and application using linkshared option then there is no error and gosampleapp runs successfully.

Can someone suggest how to solve this problem without using linkshared option.

What about using LD_LIBRARY_PATH?

LD_LIBRARY_PATH` will help to find the library. If I have given full path of library in LD_PRELOAD then LD_LIBRARY_PATH is not required i guess.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.