Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executable fails to build with --enable-executable-dynamic #10

Closed
langston-barrett opened this issue Jan 30, 2020 · 1 comment
Closed

Comments

@langston-barrett
Copy link
Contributor

Building a simple executable against limp-cbc with cabal v2-build --enable-executable-dynamic fails.

{-# LANGUAGE DataKinds #-}
module Main where

import qualified Numeric.Limp.Program as I
import qualified Numeric.Limp.Solvers.Cbc as I (solve)
import qualified Numeric.Limp.Rep as I

simpleTest :: IO ()
simpleTest = do
  let obj :: I.Linear String String I.IntDouble 'I.KR
      obj = I.r "y" (I.R 4.5)
  let constraints = I.r1 "y" I.:<= I.conZ (I.Z 10)
  let bounds = [ I.lowerUpperR (I.R 0) "y" (I.R 5) ]
  let prog = I.maximise obj constraints bounds
  case I.solve prog of
    Left err -> error $ show err
    Right ass -> putStrLn $ show ass

main :: IO ()
main = simpleTest
executable exetest
  main-is: Main.hs
  build-depends: base, limp, limp-cbc
cabal v2-build --enable-executable-dynamic exe:exetest
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - limp-cbc-0.3.2.2 (exe:exetest) (first run)
Preprocessing executable 'exetest' for limp-cbc-0.3.2.2..
Building executable 'exetest' for limp-cbc-0.3.2.2..
[1 of 1] Compiling Main             ( Main.hs, /home/siddharthist/code/limp-cbc/dist-newstyle/build/x86_64-linux/ghc-8.6.5/limp-cbc-0.3.2.2/x/exetest/build/exetest/exetest-tmp/Main.dyn_o )
Linking /home/siddharthist/code/limp-cbc/dist-newstyle/build/x86_64-linux/ghc-8.6.5/limp-cbc-0.3.2.2/x/exetest/build/exetest/exetest ...
/nix/store/q354712mnkw3ky8b5crj7ir7dyv29ylj-binutils-2.31.1/bin/ld: /home/siddharthist/code/limp-cbc/dist-newstyle/build/x86_64-linux/ghc-8.6.5/limp-cbc-0.3.2.2/build/libHSlimp-cbc-0.3.2.2-inplace-ghc8.6.5.so: undefined reference to `CbcClpUnitTest(CbcModel const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double const*)'
/nix/store/q354712mnkw3ky8b5crj7ir7dyv29ylj-binutils-2.31.1/bin/ld: /home/siddharthist/code/limp-cbc/dist-newstyle/build/x86_64-linux/ghc-8.6.5/limp-cbc-0.3.2.2/build/libHSlimp-cbc-0.3.2.2-inplace-ghc8.6.5.so: undefined reference to `CbcOrClpParam::setDoubleParameterWithMessage(CbcModel&, double, int&)'
/nix/store/q354712mnkw3ky8b5crj7ir7dyv29ylj-binutils-2.31.1/bin/ld: /home/siddharthist/code/limp-cbc/dist-newstyle/build/x86_64-linux/ghc-8.6.5/limp-cbc-0.3.2.2/build/libHSlimp-cbc-0.3.2.2-inplace-ghc8.6.5.so: undefined reference to `ClpSimplex::loadNonLinear(void*, int&, ClpConstraint**&)'
/nix/store/q354712mnkw3ky8b5crj7ir7dyv29ylj-binutils-2.31.1/bin/ld: /home/siddharthist/code/limp-cbc/dist-newstyle/build/x86_64-linux/ghc-8.6.5/limp-cbc-0.3.2.2/build/libHSlimp-cbc-0.3.2.2-inplace-ghc8.6.5.so: undefined reference to `CbcOrClpParam::setIntParameterWithMessage(CbcModel&, int, int&)'
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
@langston-barrett
Copy link
Contributor Author

I was able to fix this by adding the following line to the cabal file:

  pkgconfig-depends: cbc

and installing cbc and bzip2:

with import <nixpkgs> { };
mkShell {
  shellHook = ''
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${zlib}/lib:${cbc}/lib:${bzip2}/lib
  '';
  buildInputs = [
    zlib
    haskell.compiler.ghc865
    haskellPackages.cabal-install
    haskellPackages.ghcid
    pkgconfig
    libzip
    cbc
    bzip2
  ];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant