开发者

Specify arch in GHC?

开发者 https://www.devze.com 2023-02-22 09:02 出处:网络
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.

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 -mar开发者_如何学JAVAch for GCC?


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)


Use cabal, and set up arch-specific flags for which library to include in the .cabal file.

E.g.

> if flag(use_altivec)
>         cc-options:
>             -DHAVE_ALTIVEC

To force GHC to cross-compile (as you're wanting to do), you'll need to install an x86 version of GHC (32 bit).

0

精彩评论

暂无评论...
验证码 换一张
取 消