-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
on Linux search relative to $ORIGIN (see https://stackoverflow.com/a/72577483/1009546 ) on macOS it should search relative to @executable_path, but Go doesn't support it: golang/go#40559
on Linux search relative to $ORIGIN (see https://stackoverflow.com/a/72577483/1009546 ) on macOS it should search relative to @executable_path, but Go doesn't support it: golang/go#40559
I've just hit this issue and the Since |
Some people do use the GNU tools on Darwin, and those tools do read files when they see an If the specific string |
For |
The only other argument that I’m aware of that can receive a value starting with |
More info about these 3 special values at the very bottom of this man page: https://www.unix.com/man-page/osx/1/dyld/. |
I did some extra research and it looks like the GNU ld doesn't support Darwin as a target. The only way to use it on macOS is by targeting another platform to produce an ELF file. You cannot use it to produce a Mach-O file. See Homebrew/homebrew-core#17794. Since |
Change https://go.dev/cl/638075 mentions this issue: |
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: