2 years ago
#9318
Proof-By-Sledgehammer
How to build stack projects with external libraries on M1
I have a project that depends on the Hapstone package, which in turn depends on the Capstone library.
I build capstone like this:
cd /Users/ds3/Opt/
git clone https://github.com/capstone-engine/capstone
mkdir build && cd build
cmake ..
cmake --build .
This successfully builds an arm64 library libcapstone.dylib
.
Now I want to build hapstone like this:
cd /Users/ds3/Opt/
git clone https://github.com/ibabushkin/hapstone
stack build --extra-include-dirs=/Users/ds3/Opt/capstone/include --extra-lib-dirs=/Users/ds3/Opt/capstone/build
Which builds mostly successful, but generates the error
ld: warning: ignoring file /Users/ds3/Opt/capstone/build/libcapstone.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
My current theory is: this is because stack installs an x86-64 version of GHC, which is run through Rosetta. As such, GHC generates x86-64 libraries and binaries, which are run through Rosetta too. This works as long as it is not linked to an arm64 library.
But in the case of an external C library like capstone, the library is already built for arm64, which seems to cause problems for the linker.
So, has anyone experience with linking external libraries using stack on an M1 Macbook?
haskell
linker
ghc
apple-m1
haskell-stack
0 Answers
Your Answer