Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify arch in GHC?

I'm writing a multiplatform ncurses text adventure game. The required C library, ncursesw, is configured for x86, but my OS is Mac OS X 10.6.6 x86_64.

ghc --make -o rogue rogue.hs
[1 of 2] Compiling Dungeon          ( Dungeon.hs, Dungeon.o )
[2 of 2] Compiling Main             ( rogue.hs, rogue.o )
Linking rogue ...
ld: warning: in /usr/local/lib/libncursesw.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

I figure it's much easier to force compilation for x86 than convince Homebrew, MinGW, and Aptitude repositories to include an x86_64 ncursesw library.

Is there a command line option I can pass to ghc to specify the architecture, similar to -march for GCC?

like image 680
mcandre Avatar asked Apr 04 '11 07:04

mcandre


People also ask

Is it possible to use static linking with arch GHC?

Since version 8.0.2-1, the Arch ghc package and all haskell-* packages in community provide only dynamically linked libraries. Therefore, to link successfully one must configure GHC, Cabal and Stack for dynamic linking, as the default is to use static linking.

How to use stack-static with system GHC?

Install stack-static AUR package. Similarly to cabal-static method, make sure that the only other Haskell packages you have installed from the official repositories are ghc, ghc-libs and ghc-static. Then setup Stack to use system GHC as explained in #Configuring Stack for dynamic linking :

Why --GHC- options=-dynamic is required on the command line?

Therefore, it is necessary to specify --ghc-options=-dynamic flag on the command line otherwise you might experience build errors in setup.hs like Could not find module ‘Prelude’ There are files missing in the ‘base-...’ package. You can also build and install a Haskell package from source.


1 Answers

It looks like your ghc is configured for 32-bit (i386), while the ncurses library is 64-bit (x86-64). I believe that the most recent Haskell Platform (2011.2.x.x) uses a 64-bit ghc, whereas earlier versions provided a 32-bit ghc.

If you're using an earlier HP, upgrading to the latest version is probably sufficient for solving this problem.

Unfortunately ghc is not a native cross-compiler, and you can't set the architecture, or word size, via a flag. You need a separate ghc for each architecture you want to use, and you'll also need to make sure that all the libraries you link to match it.

(BTW, x86 isn't sufficient to distinguish an architecture, as it can refer to either 32bit or 64bit. Conventionally it refers to the 32bit version, but not always. At least on OSX 10.6 with XCode 3, gcc rejects it as an invalid value for -march)

like image 186
John L Avatar answered Nov 04 '22 00:11

John L