I'm trying to compile the following code on a MacOS machine
// #cgo darwin LDFLAGS: -L${SRCDIR}/build/darwin -lprocessing_lib
// #cgo linux LDFLAGS: -L${SRCDIR}/build/linux -lprocessing_lib
// #include "Processing-bridge.h"
// #include <stdlib.h>
import "C"
import "unsafe"
type ProcessorWrapper struct {
ptr unsafe.Pointer
}
func init() {
pr.ptr = C.NewProcessor()
}
func GetDefault() (id int, name string) {
var default = C.GetDefault(pr.ptr)
id = int(default.materialId)
name = C.GoString(default.name)
return
}
I have the libprocessing_lib.so file in the correct location defined in the LDFLAGS. However the compiler still throws an error saying
dyld: Library not loaded: build/lib_processing_lib.so
Referenced from: /Users/ag/workspace/src/github.com/apremalal/pq-processor/./pq-processor
Reason: image not found
Once I copy build/lib_processing_lib.so to the root of the project it works.
It seems that the library directory provided by the LDFLAGS is somehow getting overridden.
I've noticed that setting DYLD_LIBRARY_PATH variable before compilation also override this value.(I ran above scenarios without setting this parameter)
Interestingly though the same code works in Linux environment by picking up the correct path.
Is there anything special that I need to do in MacOS to get the desirable LDFLAGS behavior?
Set the dynamic library load path.For mac setting DYLD_LIBRARY_PATH
for linux LD_LIBRARY_PATH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With