I seem to be able to install a package using stack, but then it's not available in ghci. I didn't set up a project directory; I'm just loading files from the directory I start ghci in. (I'll get to packages, this is for my early learning experiments.)
With stack Version 2.5.1, Git revision d6ab861544918185236cf826cb2028abb266d6d5 x86_64 hpack-0.33.0, I am able to install package pretty-tree:
~$ stack install pretty-tree
split > using precompiled package
boxes > using precompiled package
pretty-tree> configure
pretty-tree> Configuring pretty-tree-0.1.0.0...
pretty-tree> build
pretty-tree> Preprocessing library for pretty-tree-0.1.0.0..
pretty-tree> Building library for pretty-tree-0.1.0.0..
pretty-tree> [1 of 1] Compiling Data.Tree.Pretty
pretty-tree> copy/register
pretty-tree> Installing library in /Users/marshall/.stack/snapshots/x86_64-osx/7f23217891aaded25d36ce049bc36fa5daea730080286c2d93877f934c894bb2/8.8.4/lib/x86_64-osx-ghc-8.8.4/pretty-tree-0.1.0.0-KTaQApPwVahHd2AQwQQQSA
pretty-tree> Registering library for pretty-tree-0.1.0.0..
Completed 3 action(s).
But I can't load the module that pretty-tree provides:
$ stack ghci
...
Prelude> import Data.Tree.Pretty
<no location info>: error:
Could not find module ‘Data.Tree.Pretty’
It is not a module in the current program, or in any known package
I have a similar problem when I put the import statement into a file that normally would load:
myfile.hs:9:1: error:
Could not find module ‘Data.Tree.Pretty’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
9 | import Data.Tree.Pretty
| ^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
I can see a .conf file for the package:
~/.stack/snapshots/x86_64-osx$ ll 7f23217891aaded25d36ce049bc36fa5daea730080286c2d93877f934c894bb2/8.8.4/pkgdb
total 48
-rw------- 1 marshall staff 1817 Dec 3 12:28 boxes-0.1.5-Q9SvFlNJmuH845NHEKHN9.conf
-rw------- 1 marshall staff 10015 Dec 3 12:28 package.cache
-rw------- 1 marshall staff 0 Dec 3 12:28 package.cache.lock
-rw------- 1 marshall staff 1894 Dec 3 12:28 pretty-tree-0.1.0.0-KTaQApPwVahHd2AQwQQQSA.conf
-rw------- 1 marshall staff 2763 Dec 3 12:28 split-0.2.3.4-KyPtAwfJzED2zEIheQpqQL.conf
and there are other packages I've installed with stack that I can import (but they are in different snapshot directories).
I don't know much about stack or cabal. Up to this point, installing new packages with stack just worked, and I didn't have to think about it. I've looked at the half a dozen similar SO questions that I can find. Some of them report similar problems but don't use stack. The ones that do involve stack haven't helped. I've gone through the parts of the online stack documentation that seemed relevant, but haven't found anything.
What am I missing?
Related
I have a Haskell stack project, and I'm trying to import the module Cardano.CLI.Run exposed by cardano-cli.
cardano-cli is a folder within the repository cardano-node:
https://github.com/input-output-hk/cardano-node
So, I have added the following to my stack.yaml file (extra-deps):
# cardano-node, version 1.35.2
- git: https://github.com/input-output-hk/cardano-node.git
commit: 7612a245a6e2c51d0f1c3e0d65d7fe9363850043
subdirs:
- cardano-cli
- cardano-node
However, when I try to build the project, I get an error:
% stack build
Stack has not been tested with GHC versions above 9.0, and using 9.2.3, this may fail
Stack has not been tested with Cabal versions above 3.4, but version 3.6.3.0 was found, this may fail
summon-api-server> build (lib + exe)
Preprocessing library for summon-api-server-0.1.0.0..
Building library for summon-api-server-0.1.0.0..
[2 of 2] Compiling Lib
/Users/xyz/dr/xsf/my-project/src/Lib.hs:23:1: error:
Could not find module ‘Cardano.CLI.Run’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
23 | import Cardano.CLI.Run (runClientCommand)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What else do I gotta do?
I'm using MXE to build my own cross-compiler toolchain (this specific version). Only I don't use the default gcc 5.5 but gcc 6.3.0 instead.
I'm not specifically tied to that version - I just picked it because it was also used to generate the latest portaudio binaries
It appears that for some reason, some MSVCRT symbols have been included in and are exported by the portaudio DLL:
dumpbin /exports libportaudio64bit.dll
992 3DF 00032F30 mbrlen
993 3E0 00032D90 mbrtowc
994 3E1 00032E00 mbsrtowcs
1112 457 00033180 wcrtomb
1113 458 000331C0 wcsrtombs
I only found out because I was trying to cross-compile and build bzip2 1.0.8
This is pretty old and it doesn't have all the infrastructure in place to support cross-compiling. However it can be done by hand in a couple of very simple steps:
make CC=x86_64-w64-mingw32.shared-gcc AR=x86_64-w64-mingw32.shared-ar RANLIB=x86_64-w64-mingw32.shared-ranlib libbz2.a
x86_64-w64-mingw32.shared-gcc *.o -s -shared -o libbz2-1.dll
Alike the portaudio DLLs, the above exports the same symbols:
dumpbin /exports libbz2-1.dll
36 23 00012B60 mbrlen
37 24 000129F0 mbrtowc
38 25 00012A60 mbsrtowcs
39 26 00012DC0 wcrtomb
40 27 00012E00 wcsrtombs
Needless to say, this is causing issues at link time, due to multiple definitions of the same symbol (mingw-w64-v8.0.0/mingw-w64-crt/misc/mbrtowc.c:98: multiple definition of 'mbrtowc' - x86_64-w64-mingw32.shared/lib/../lib/libmsvcrt.a(lib64_libmsvcrt_os_a-mbrtowc.o): first defined here)
My question is not how to avoid this issue. That can be done by using a DEF file when building the DLLs, to control the exact list of exported functions.
My question is more fundamental: why would these symbols be exported in the first place ? Is this a bug somewhere ?
I tried running my program which uses Haskell QuickCheck via ghc MyProgramm.hs , but received the following error:
$ ghc Ex2.hs
[1 of 1] Compiling Ex2 ( Ex2.hs, Ex2.o )
Ex2.hs:21:1: error:
Could not find module ‘Test.QuickCheck’
There are files missing in the ‘QuickCheck-2.11.3’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
21 | import Test.QuickCheck (
| ^^^^^^^^^^^^^^^^^^^^^^^^...
I installed stack, ran stack update and stack install QuickCheck without issue but the error persisted. Then, I ran cabal install QuickCheck and got the following errors:
$ cabal install QuickCheck
Resolving dependencies...
Configuring QuickCheck-2.12.4...
Building QuickCheck-2.12.4...
Failed to install QuickCheck-2.12.4
Build log ( /home/username/.cabal/logs/ghc-8.4.3/QuickCheck-2.12.4-3d2YDDqfPBn4BfmTJbpJXK.log ):
cabal: Entering directory '/tmp/cabal-tmp-9133/QuickCheck-2.12.4'
Configuring QuickCheck-2.12.4...
Preprocessing library for QuickCheck-2.12.4..
Building library for QuickCheck-2.12.4..
[ 1 of 16] Compiling Test.QuickCheck.Exception ( Test/QuickCheck/Exception.hs, dist/build/Test/QuickCheck/Exception.o )
[ 2 of 16] Compiling Test.QuickCheck.Random ( Test/QuickCheck/Random.hs, dist/build/Test/QuickCheck/Random.o )
Test/QuickCheck/Random.hs:10:1: error:
Could not find module ‘System.Random’
There are files missing in the ‘random-1.1’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
10 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
Test/QuickCheck/Random.hs:11:1: error:
Could not find module ‘System.Random.TF’
There are files missing in the ‘tf-random-0.5’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
11 | import System.Random.TF
| ^^^^^^^^^^^^^^^^^^^^^^^
Test/QuickCheck/Random.hs:12:1: error:
Could not find module ‘System.Random.TF.Gen’
There are files missing in the ‘tf-random-0.5’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
12 | import System.Random.TF.Gen(splitn)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Leaving directory '/tmp/cabal-tmp-9133/QuickCheck-2.12.4'
cabal: Error: some packages failed to install:
QuickCheck-2.12.4-3d2YDDqfPBn4BfmTJbpJXK failed during the building phase. The
exception was:
ExitFailure 1
However, I already have the arch packages haskell-random, haskell-tf-random and haskell-mwc-random installed. Does anybody know how to fix this?
Edit: I also ran cabal install random --reinstall.
Problem
On Archlinux as of 2022-09-17, pacman -S ghc cabal-install will install
system packages that provide only dynamic files (.so, .dyn_hi) in
installed packages inside /usr/lib/ghc-*; static files (.a, .hi) are (for
the most part) missing. However, the default cabal configuration enables static file
building. Unfortunately, upstream cabal-install doesn't track whether or not
static files are available inside installed packages. It just assumes they
are, and when they are gone, it fails with errors such as you have found:
[1 of 1] Compiling Main ( Main.hs, ../setup.dist/work/depender/dist/build/depender/depender-tmp/Main.o )
Main.hs:3:1: error:
Could not find module `Dynamic'
There are files missing in the `dynamic-1.0' package,
try running 'ghc-pkg check'.
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
| import qualified Dynamic (number)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Workaround
A quick workaround just to get up and running quickly is to disable static file
building, which is by default enabled. (Note that trying to pass package-local
flags to disable static file with e.g. --enable-shared --enable-executable-dynamic --disable-library-vanilla (which is how most if
not all current Archlinux Haskell packages seem to build packages, e.g. with
https://github.com/archlinux/svntogit-community/blob/master/haskell-scientific/trunk/PKGBUILD)
building using cabal-install may be ignored due to another, related bug; but
~/.cabal/config is a safe bet.) You may do so by adding 3 lines to
~/.cabal/config in the appropriate location:
library-vanilla: False
shared: True
executable-dynamic: True
(Alternatively, consider using alternative tools like stack.)
More complete solution
For a more long-term solution, one option involves 2 pieces: 1) one or more
system packages that provide all types of build artifacts, static and dynamic,
for the base, foundational packages (from GHC and cabal-install), at least as an option besides dynamic-only packages (secondary Haskell packages are optional,
since cabal-install can rebuild these with needed build artifacts (static or
dynamic)), and 2) patching cabal-install (and ghc-pkg, which can handle .conf
files recording information about installed packages) to track whether static
files are available, and to be aware of these when resolving dependencies so
that cabal-install knows when to prefer rebuild a source package with needed
build artifact configuration over an already installed package that doesn't
provid required build artifacts.
There is a merge request (I submitted) that provides such a patchset, called
fix-dynamic-deps, at https://github.com/haskell/cabal/pull/8461. For users
running into exactly the problem that you described (myself included), I also
created an AUR package that provides both pieces based on GHC 9.4.2 with Cabal
3.9.0.0 that includes my patchset (there is a mirror at
https://github.com/bairyn/ghc-cabal-arts.) It provides ghc and
cabal-install but includes both of these pieces.
Further reading
Here are a few more resources I wrote on or are related to this bug:
https://wiki.archlinux.org/index.php?title=Haskell&diff=745459&oldid=738269#Troubleshooting
https://github.com/haskell/cabal/pull/8461
https://github.com/bairyn/ghc-cabal-arts
https://github.com/bairyn/cabal/tree/fix-dynamic-builds
Even though I have a main = do and couldn't get it working that way, I was able to run my QuickCheck test as follows:
To run a quickCheck, first load your program with:
$ ghci MyProg.hs
Then to run the quickCheck, find the test you want to run, then run it with:
$ quickCheck my_quick_check
I am writing an r package which provides a wrapper around the libSBML C library.
I am using the rcppgsl package as a reference, which looks for the location of header files and the library files for GNU Scientific Library GSL and uses that information to write the configure script and Makevars and Makevars.in. I am not building for Windows currently. On my machine (macOS), libsbml (SBML C library) is installed in usual locations, i.e.
header files are at - /usr/local/include/sbml
and library files at - /usr/local/lib. Indeed, if in my package Makevars file I use the following, I can build my package.
CXX=clang++
PKG_CPPFLAGS= -I/usr/local/include
PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) /usr/local/lib/libsbml-static.a
However, I want to learn how to use the configure script to find the library and use that information to build the package. The relevant portion of configure.ac from rcppgsl is
## Check for non-standard programs: gsl-config(1)
AC_PATH_PROG([GSL_CONFIG], [gsl-config])
## If gsl-config was found, let's use it
if test "${GSL_CONFIG}" != ""; then
# Use gsl-config for header and linker arguments
GSL_CFLAGS=`${GSL_CONFIG} --cflags`
GSL_LIBS=`${GSL_CONFIG} --libs`
else
AC_MSG_ERROR([gsl-config not found, is GSL installed?])
fi
I replaced GSL_CONFIG with LIB_SBML at relevant places, i.e., the entire configure.ac file I am using is pasted below (at the end).
However, I don't see configure, Makevars and Makevars.in being generated (which I see in rcppgsl). Any help here would be highly appreciated!
For the sake of completion, the output of
ls -l | grep sbml (in usr/local/include) is
drwxrwxr-x 58 root admin 1856 Aug 1 2016 sbml
and ls -l | grep sbml (in usr/local/lib) is
-rw-r--r-- 1 root wheel 7970584 Aug 2 2016 libsbml-static.a
-rwxr-xr-x 1 arcadmin staff 10453624 Nov 25 2014 libsbml.5.11.0.dylib
-rwxr-xr-x 1 root wheel 3813572 Aug 2 2016 libsbml.5.13.0.dylib
lrwxr-xr-x 1 root wheel 20 Aug 1 2016 libsbml.5.dylib -> libsbml.5.13.0.dylib
-rw-r--r-- 1 root wheel 13907656 Feb 26 2015 libsbml.a
lrwxr-xr-x 1 arcadmin staff 15 Mar 27 2015 libsbml.dylib -> libsbml.5.dylib
-rwxr-xr-x 1 root wheel 828 Feb 26 2015 libsbml.la
-rwxrwxr-x 1 root admin 13362732 Nov 25 2014 libsbmlj.jnilib
My configure.ac file --
## Process this file with autoconf to produce a configure script.
##
## Configure.ac for RcppSBML
##
## Copyright (C) 2010 Romain Francois and Dirk Eddelbuettel
## Copyright (C) 2014 - 2015 Dirk Eddelbuettel
##
## Licensed under GNU GPL 2 or later
# The version set here will propagate to other files from here
AC_INIT([Rcppsbml], 0.1.0)
# Checks for common programs using default macros
AC_PROG_CC
## Use gsl-config to find arguments for compiler and linker flags
##
## Check for non-standard programs: gsl-config(1)
AC_PATH_PROG([LIB_SBML], [libsbml])
## If gsl-config was found, let's use it
if test "${LIB_SBML}" != ""; then
# Use gsl-config for header and linker arguments
SBML_CFLAGS=`${LIB_SBML} --cflags`
SBML_LIBS=`${LIB_SBML} --libs`
else
AC_MSG_ERROR([libsbml not found, is SBML installed?])
fi
# Now substitute these variables in src/Makevars.in to create src/Makevars
AC_SUBST(LIB_SBML)
AC_SUBST(LIB_SBML)
AC_OUTPUT(src/Makevars)
Here a minimal setup:
Remove src/Makevars and create src/Makevars.in with content
PKG_CPPFLAGS= #SBML_INCLUDE#
PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) #SBML_LIBS#
I am not setting CXX since you cannot change that in src/Makevars, c.f. Package build ignores Makevars flags.
Create a minimal configure.ac file:
AC_INIT([Rcppsbml], 0.1.0)
AC_LANG(C++)
AC_REQUIRE_CPP
AC_PROG_CXX
# default values
AC_SUBST([SMBL_INCLUDE], "-I/usr/local/include")
AC_SUBST([SMBL_LIBS], "/usr/local/lib/libsbml-static.a")
# allow for override
AC_ARG_WITH([smbl],
AC_HELP_STRING([--with-smbl=PREFIX],
[path to where smbl is installed]),
[
SMBL_INCLUDE="-I${with_smbl}/include"
SMBL_LIBS="${with_smbl}/lib/libsbml-static.a"
],
[])
# create and report output
AC_CONFIG_FILES([src/Makevars])
AC_OUTPUT
echo
echo "Final src/Makevars"
cat src/Makevars
Call autoconf to create a configure file from your configure.ac template. You might want to check the script with ./configure and ./configure --with-smbl=/some/path.
Call
R CMD build ...
R CMD check [--install-args=--configure-args=--with-smbl=/some/path] ...
R CMD INSTALL [--configure-args=--with-smbl=/some/path]...
to build, check and install the package.
Possible extensions:
Allow for switching between static and dynamic linking.
Check that SMBL can be found in a usable state at the specified location.
I see three issues here:
The generation of configure from configure.ac is not automatic. You have to call autoconf.
Similarly, Makevars.in is not generated by the system. You have to provide it as template from which Makevars is generated by configure.
The GSL ships with gsl-config, other libraries make use of the general pkg-config. If your library does not support this, you can use the more traditional way to use default locations or those provided with --with-... arguments. For example in RcppArrayFire I use:
AC_SUBST([AF_INCLUDE], "")
AC_SUBST([AF_LIBS], "-laf")
AS_IF([test -e "${with_arrayfire}"],
[
AF_INCLUDE="-I${with_arrayfire}/include ${AF_INCLUDE}"
AF_LIBS="-L${with_arrayfire}/lib ${AF_LIBS} -Wl,-rpath,${with_arrayfire}/lib"
])
If a directory is supplied as --with-arrayfire=/relevant/path, then appropriate sub directories are searched for headers and dynamic libraries.
I run ./myprogram and it gives me a warning:
Warning: Your program was compiled with SimGrid version 3.13.90, and then linked against SimGrid 3.13.0. Proceeding anyway.
Tryldd myprogram and it gives following:
libsimgrid.so.3.13.90 => /usr/lib/libsimgrid.so.3.13.90 (0x00007f338ef47000)
Then I go to usr/lib and type ll *sim* in terminal:
lrwxrwxrwx 1 ken ken 21 июл 28 19:29 libsimgrid.so -> libsimgrid.so.3.13.90*
-rwxrwxr-x 1 ken ken 12307480 июл 28 19:29 libsimgrid.so.3.13.90*
In CMakeLists.txt I link library simgrid in such way:
target_link_libraries(CSim2Sim simgrid)
Why myprogram still links against SimGrid 3.13.0 (it doesn't exist in /usr/lib while SimGrid 3.13.90 does)?
UPDATE:
Command locate libsimgrid.so in ternimal gives:
/home/ken/Downloads/simgrid-master/lib/libsimgrid.so
/home/ken/Downloads/simgrid-master/lib/libsimgrid.so.3.13.90
/home/ken/SimGrid/lib/libsimgrid.so
/home/ken/SimGrid/lib/libsimgrid.so.3.13.90
/usr/lib/libsimgrid.so
/usr/lib/libsimgrid.so.3.13.90
The message seems buggy, it looks like your application was actually compiled with 3.13.0, and linked to libsimgrid 3.13.90. The order was inverted in the message, I will fix that.
It could be a problem with your includes when you compile your code, I think. Please check that you don't use old versions of msg.h/simgrid_config.h files when you compile your app (maybe there are still one in /usr/include ?).
To check, you can look for SIMGRID_VERSION_PATCH in simgrid_config.h. it should be 90 in a recent one, not 0.