I've successfully created a ghc cross compiler, that allows me to compile haskell code for armv6h (raspberry pi in my case) from my x64 linux machine.
I've successfully run a hello world program on the raspberry.
No I want to build my real app, which has a lot of dependencies on other haskell modules.
When I compile for x64 I simply do
cabal install dependenciy1 depenency2 ...
I know I could make my own programm a cabal-project an automate this step. But that's not the point here.
When I try to use the cross-compiler
arm-unknown-linux-gnueabi-ghc --make myapp.hs
It tells me about modules it could not find. Of course, they are not installed!
I read https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling
and according to that I tried
cabal --with-ghc=arm-unknown-linux-gnueabi-ghc --with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg --with-ld=arm-unknown-linux-gnueabi-ld install random
random is the depenency I'm trying to install here. I get the following error:
Resolving dependencies...
Configuring random-1.0.1.3...
Failed to install random-1.0.1.3
Last 10 lines of the build log ( /home/daniel/.cabal/logs/random-1.0.1.3.log ):
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: cannot execute binary file
cabal: Error: some packages failed to install:
random-1.0.1.3 failed during the configure step. The exception was:
ExitFailure 126
When I do
file /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804
I get
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.10.2, not stripped
No wonder it can't execute it. It's compiled for arm.
Am I missing something here?
My goal is to pull in all dependencies, then create a statically linked app that I can deploy on my raspberry.
To understand this error, you need to know how cabal install works internally. In essence, it will perform the following steps:
Download and unpack the source code
Compile Setup.hs (this file is used for customization of the build system, for example, you can implement some hooks to run additional haskell code in the configure phase).
Run setup configure <configure flags> && setup build && setup install
The problem is now that cabal install uses the GHC given by --with-ghc also for step 2, but the executable produced by that step must run on the host system!
A workaround is to do the steps manually, which means you have full control. First, get the source:
$ cabal get random
Downloading random-1.0.1.3...
Unpacking to random-1.0.1.3/
$ cd random-1.0.1.3
Then, compile Setup.hs, using the host ghc:
$ ghc ./Setup.hs -o setup
And finally, configure, build and install. As suggested by #Yuras in a comment, we also add the -x option for running hsc2hs:
$ ./setup configure ----with-ghc=arm-unknown-linux-gnueabi-ghc --with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg --with-ld=arm-unknown-linux-gnueabi-ld --hsc2hs-options=-x
$ ./setup build && ./setup install
There is already a cabal issue about this: https://github.com/haskell/cabal/issues/2085
Related
I'm attempting to compile a Haskell project on Windows with profiling enabled, using the following command.
ghc --make -O -prof -fprof-auto game_dangerous.hs
I develop the project myself and the same source code compiled and linked fine without profiling. As expected (from previous experience) I ran into a number of errors of the form:
Could not find module `Data.Vector.Mutable'
Perhaps you haven't installed the profiling libraries for package `vector-0.12.0.2'?
I proceeded to iteratively reinstall packages based on the errors encountered using for example:
cabal install -p vector --reinstall
Cabal kept giving me warnings about possibly breaking packages with the reinstalls but I pressed on as (as far as I could see) every package that could be broken was going to get reinstalled itself as I moved through the tree of dependencies. Also, I've previously followed the same process on another machine and it worked fine. After reinstalling all the required packages my project now compiles but the linker fails with this error:
C://Program Files//Haskell Platform//8.6.3//mingw//bin/ld.exe: cannot find -lHSsemigroups-0.18.5-8pPnWqWrcWhEagTFf5Pnk2_p
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
However, the build does complete successfully without profiling enabled. Does anyone know what may have gone wrong and how to fix the issue? Thanks in advance.
Steven
I would try making a .cabal file for your program, where you explicitly specify the cabal packages your program depends on and use cabal v2-build to compile your program. It will warn you about missing dependencies of your program until you include them all in build-depends section of the .cabal file. You only need to include the dependencies of your program, not the dependencies of the dependencies. After that you can add cabal.project.local to enable profiling and maybe something else. It should be enough to run cabal v2-build to build your program and packages it depends on with profiling(and other options in the cabal.project.local) enabled.
You need to have profiling enabled in the packages used by your program to support profiling in it. Cabal v2 builds allows you to have multiple instances of the same package. Those instances are different because different flags and options have been used to build them.
It is possible to achieve the same result using a separate package database for your program. That is using ghc-pkg with --package-db option.
Another option is to use stack. It will solve the same issues, but differently at the cost of more space and some performance penalties in ghc(compared to ghc built from source which can be used with cabal).
for some time, the travis builds of my little haskell app are failing with a cryptic link error:
$ cabal configure --enable-tests && cabal build && cabal test
Resolving dependencies...
[1 of 1] Compiling Main ( Setup.hs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
/usr/lib/ghc/unix-2.5.1.0/libHSunix-2.5.1.0.a(execvpe.o): In function `pPrPr_disableITimers':
(.text+0x320): multiple definition of `pPrPr_disableITimers'
/home/travis/.cabal/lib/x86_64-linux-ghc-7.4.1/unix-2.7.1.0/libHSunix-2.7.1.0.a(ghcrts.o):ghcrts.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
The command "cabal configure --enable-tests && cabal build && cabal test" exited with 1.
Done. Your build exited with 1.
The builds work fine on my machine. Is there anything I can tune in my .travis.yml file to fix the issue there?
In my experience, this is usually caused by having multiple versions of a library in your dependency tree, which cabal configure allows while cabal install will not. I don't see evidence of that in your build log, but it might theoretically be happening. You can try changing cabal configure to cabal install and see what happens.
So, first I'm on the legacy travis system, I guess I need to go on the new one. But that one requires much more thorough config I think. Second on the legacy system, ghc 7.10 is not supported: stackoverflow.com/questions/29516932/… I had configured 7.10 but didn't realize that didn't work, and since travis didn't recognize the ghc version, it just put me the oldest, 7.4. So I reverted to 7.8 for now, and the error is now different and more understandable.
So the root cause for weird error was being fallback to the relatively ancient ghc 7.4 due to my misconfiguration.
I would like to install pandoc, but I have some restrictions due to the Corporate IT policies:
I cannot download any binaries.
Every executable has to be build from sources
Only Google Chrome have an access to internet (proxy restrictions)
So I downloaded Pandoc sources but it depends on haskell. Thus I downloaded ghc-7.8.4-src.tar.bz2
Unfortunately I discovered that I need GHC to build GHC. I downloaded ghc-7.4.1-i386-unknown-linux.tar.bz2 and I got this error:
$ ./configure
checking for path to top of build tree... ./configure: line 2113: utils/ghc-pwd/dist-install/build/tmp/ghc-pwd: cannot execute binary file: Exec format error
configure: error: cannot determine current directory
In "/usr/src/ghc-7.4.1/utils/ghc-pwd/dist-install/build/tmp/usr/src/ghc-7.4.1/utils/ghc-pwd/dist-install/build/tmp" I found a binary that should not be here. I cannot execute binaries.
I also discovered that I need cabal for which I need to install Haskell first.
It seems It's the snake that bites its own tail...
Is there a method that I can use to build Pandod, Haskell, Cabal and all the other dependencies?
Usually if I need a program, I just download the sources, execute ./configure, solve the dependencies issues and eventually run make install. In this case it seems I need my whole lifetime just to understand what I need to build Pandoc...
I would try using the newly (beta-)released stack tool [1]
Recipe to download GHC and build pandoc:
Obtain the stack executable [2]
Run:
$ stack setup
Add the recommended directory to your PATH (will be something like $HOME/.stack/progams/...arch.../ghc-7.8.4/bin)
Run:
$ stack install pandoc
Look for the pandoc executable in $HOME/.local/bin.
Links:
[1]: https://www.fpcomplete.com/blog/2015/06/announcing-first-public-beta-stack
[2]: https://github.com/commercialhaskell/stack/wiki/Downloads
I was trying to install wxHaskell into a machine running Windows XP64, with MinGW/MSYS and wxWidget 3.0 built from source using gcc. I did:
cabal install wx
and got an error:
...
Configuring wxc-0.90.0.4...
setup.exe: wx-config: does not exist
Failed to install wxc-0.90.0.4
cabal.exe: Error: some packages failed to install:
wx-0.90.0.1 depends on wxc-0.90.0.4 which failed to install.
wxc-0.90.0.4 failed during the configure step. The exception was:
ExitFailure 1
wxcore-0.90.0.3 depends on wxc-0.90.0.4 which failed to install.
I had successfully used wxWidgets to write an sample application in C++ (gcc). So I do have a working wxWidget installation. And I have wx-config at:
$ which wx-config
/usr/local/bin/wx-config
The problem is that wx-config is a unix shell script, and cabal (called from MSYS) somehow refuses to recognize it even if it's on the system path. If I run wx-config in MSYS, I get something like:
$ wx-config --cxxflags
-I/usr/local/lib/wx/include/msw-unicode-3.0 -I/usr/local/include/wx-3.0 -D_LARGE
FILE_SOURCE=unknown -DWXUSINGDLL -D__WXMSW__ -mthreads
I have asked a question https://stackoverflow.com/questions/21998763/how-to-convert-msys-shell-scripts-to-windows-exe-files to see if it's possible to convert the script to an exe, but no one responded with any solutions.
There is also a related question here, wxHaskell installation on windows , and another here wx 0.90.0.1 fails to install on Haskell Platform 2012.2.0.0 (WinXP). In fact, I couldn't found an answer that's confirmed to work. Also, the errors/settings here seem to be different, or the answers therein don't seem solve my problem. In particular, I downloaded an external wx-config.exe from https://sourceforge.net/projects/wxhaskell/files/wx-config-win/ per http://www.haskell.org/haskellwiki/WxHaskell/Windows. But running wx-config.exe can't recognize my wxWidget installation and always gives me an error about cannot find wxWidgets, like this:
$ ./wx-config.exe --prefix=/usr/local/
wx-config Error: wxWidgets hasn't been found installed at 'C:\MinGW\msys\1.0\loc
al'.
Please use the --prefix flag (as in wx-config --prefix=C:\wxWidgets)
or set the environment variable WXWIN (as in WXWIN=C:\wxWidgets)
to specify where is your installation of wxWidgets.
Any idea how to work around this issue?
Thanks,
-- Update --
#JP I tried:
C:\temp\wxdirect-0.90.0.1>runhaskell Setup configure --extra-lib-dirs=c:\MinGW\lib --extra-include-dirs=c:\MinGW\include --extra-include-dirs=c:\MinGW\msys\1.0\local\include
Configuring wxdirect-0.90.0.1...
and got
Setup: At least the following dependencies are missing:
containers >=0.2 && <0.5, strict -any
I tweaked wxdirect.cabal to bypass containers >=0.2 && <0.5, but can't get pass strict.
I've written a powershell script that automates the setup of MinGW and the downloading/building of wxWidgets in order to build wxHaskell for Windows 7.
https://github.com/cessationoftime/wxHaskell-Windows-Builder
I am trying to cabal install yesod on my Windows machine. I have a relatively fresh install of the Haskell Platform. The cabal install failed, reporting that I need the sqlite3 C library in order to install "persistent", a package which Yesod relies upon.
cabal: Missing dependency on a foreign library:
* Missing C library: sqlite3
So I went to http://www.sqlite.org/download.html and grabbed both the C source and the precompiled binary. I tried using both, to no avail:
cabal install persistent --extra-lib-dirs=C:\Path\To\C\Source\Files
cabal install persistent --extra-lib-dirs=C:\Path\To\Binary
In both cases, I got the same result: it didn't work. :( What can I do to give cabal the C library it needs? (sqlite3 in this case)
So, facepalm. I didn't need the source, I didn't need the exe. I needed the dll.
Under the "precompiled binaries for Windows" section of the website mentioned in my question, I downloaded and extracted the zip file with sqlite3.def and sqlite.dll. Then I used
cabal install persistent --extra-lib-dirs=C:\Path\To\DllAndDef
The installation appears to have completed successfully. Afterwards, I did a cabal install yesod, which also appears to have completed successfully.
I suppose if I had put the dll somewhere magical, then I wouldn't have had to use the --extra-lib-dirs= option.