cmd/go: go tool rejects #cgo LDFLAGS: -Wl,-rpath,@executable_path/../Frameworks #40559
Comments
What does Any fix for this will have to be very careful. For the GNU tools, among others, starting a parameter with |
@exexutable_path is like the MacOS version of $ORIGIN on Linux i.e. it is the path that the binary is in at runtime to be able to dynamically link to a library using a relative path. |
Here's some more info: https://wincent.com/wiki/@executable_path,_@load_path_and_@rpath |
It looks like
That would still be an issue here. Perhaps we could support specifically |
Yes, that sounds like the ideal solution! |
If someone can point me to where I need to look I'm happy to have a bash at a PR. |
security.go contains regular expressions for allowed flags.
cgo_bad_directives.txt tests this filtering, so that would need to be expanded. See README.txt in that directory for information on the test format. |
Actually I'm evaluating go for a project on mac and i've a poc that needs to load an external Any suggestions would be great, I really would like to use go for the project, but we need to load external C libraries that are not installed in any of the OS search paths. Update:
package native
/*
#cgo LDFLAGS: -L../path/to/libs -Wl,-rpath,./libs -lgreeter
#include "path/to/libs/include/greeter.h"
#include <stdlib.h>
*/
import "C"
// Rest of code omitted for brevity
# You can check the correct name for change with otool -L mybinary
install_name_tool -change @rpath/libgreeter.dylib @executable_path/libs/x64/libgreeter.dylib mybinary I'm not sure if this would break anything else, but so far everything is working as expected. I still hope that the go tooling will allow the |
@snmed I'm glad you found a way. You can also set set the |
@ianlancetaylor Thanks for your advice, that worked very well with |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to build a MacOS bundle using dynamically linked libraries. As per convention these are stored in
MyApp.app/Contents/Frameworks
which requiresLC_RPATH
to point there.I added the following flag:
What did you expect to see?
go build
builds binary withLC_RPATH
set to@executable_path/../Frameworks
What did you see instead?
I got an
invalid flag
error upon runninggo build
.I also tried replacing
@executable_path
for$ORIGIN
as I would in Linux but then I got animage not found
error when running the resulting binary (I assume this isn't supported on MacOS).The text was updated successfully, but these errors were encountered: