Error building cgo: cannot parse $WORK/b046/_cgo_.o as ELF, Mach-O, PE or XCOFF #6
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Info
Macbook Pro M3Pro (2024)
Sonoma 14.4.1
Node: v21.7.3
Go: 1.22.2
I have added the example files, but when I try to build the go to create "example.node", I get this error:
github.com/akshayganeshen/napi-go: invalid flag in #cgo LDFLAGS: -Wl,-no_pie
I am new to go so I'm not quite sure how to fix this, any help would be greatly appreciated!
I've uploaded what I have to this repo:
https://github.com/annie-elequin/napi-go-test
Slight progress. Here's what I did...
I then got a different error even though I hadn't changed anything.
New error:
Figured that out - it was because napi-go expects node to be at
/usr/local/include/node
and mine is under.nvm
.So I did this:
sudo ln -s /Users/<username>/.nvm/versions/node/v21.7.3/include/node /usr/local/include/node
(I also added node-gyp with these commands, and my simple binding.gyp file that does nothing is in the above linked repo)
yarn add -D node-gyp
binding.gyp
filenode-gyp configure
(requires the binding.gyp file)node-gyp build
SO NOW
I run this:
go build -buildmode=c-shared -o "example.node" .
and we have this error:
cgo: cannot parse $WORK/b046/_cgo_.o as ELF, Mach-O, PE or XCOFF
and I think I might post on stack overflow? I see some other issues of this online but I haven't been able to figure out the solution
@annie-elequin are you on mac arm ?
We had a similar issue and we fixed it by editing the various node_api_...flags to adjust the
-arch x86_64
Note: We also used go1.18 to make it work though, not sure if it works on 1.19+
@ACenterA

yes that did it!
here are the changes to our flags that we made that worked: