I am trying to use the Z3 Solver on OSX using the OCaml binding.
When attempting to build and run my solution using
ocamlfind ocamlc -o testsat.byte -package Z3 -linkpkg testsat.ml I am getting an ocamlfind: Package Z3 not found.
I have also tried using ocamlbuild without the -package tag, however then I'm getting an Unbound Module Z3 error.
I am also having problems installing the z3Overlay library - https://github.com/termite-analyser/z3overlay when trying to install the z3 dev portion.
Does anyone know of any fixes, or a stable version that can be used on OSX? My assumptions are that I'm encountering these errors since the build is failing (as can be seen from the official documentation: https://github.com/Z3Prover/z3).
I am new to this, any help is greatly appreciated.
Library and package names are case sensitive, and the package name of the z3 bindings is z3 not Z3. You can always query for available packages using ocamlfind list.
ocamlfind list | grep -i Z3
z3 (version: 4.6.0.0)
So the following command will work as expected
ocamlfind ocamlc -o testsat.byte -package z3 -linkpkg testsat.ml
There is a small caveat, that Martin mentions in the comments, so you should get another error, that should look like this:
libz3.so: cannot open shared object file: No such file or directory
Indeed, the package installs libz3.soin a location that is not searched, thus you should tell the system linker where to search for the z3 shared object. In Mac OS X, this can be achieved by setting the DYLD_LIBRARY_PATH variable, e.g.,
export DYLD_LIBRARY_PATH=`opam config var z3:lib`
on GNU/Linux systems the same can be done via the LD_LIBRARY_PATH environment variable:
export LD_LIBRARY_PATH=`opam config var z3:lib`
Related
I'm working through chapter 3 of the tutorial of LLVM,
The given file myocamlbuild.ml is:
open Ocamlbuild_plugin;;
ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;
flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);;
But I find if I run
ocamlbuild -pkg llvm repl.byte
Error message is: the required module llvm_analysis is unavailable.
What did I do wrong here? Thanks.
You've followed some outdated and probably wrong instructions. If you will install llvm from opam, it will be correctly packaged, and in order to use the llvm_analysis library, you just need to use -pkg llvm.analysis option of the ocamlbuild tool.
So, erase myocamlbuild.ml file, and any other support files, that you've created (e.g., _tags), and compile it as follows
ocamlbuild -pkgs llvm,llvm.analysis repl.byte
or
ocamlbuild -pkgs llvm,llvm.analysis repl.native
Add other llvm subpackages after the comma (no whitespaces).
To get the list of all llvm subpackages use the following command:
ocamlfind list | grep llvm
See also my other answer to your previous questions for the detailed description on how to setup a new project, that uses llvm
I'm having trouble building the hmatrix library on OS X Lion. Looking at the .cabal file, it requires the gsl library, so I installed it with macports. The .a files are in /opt/local/lib and the .h files are in /opt/local/include/gsl
As suggested here I changed the built-type from Custom to Simple. (without that change I get a similar error).
When I use cabal configure I get the following output:
* Missing C library: gsl
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
So I tried cabal --extra-include-dirs=/opt/local/include --extra-lib-dirs=/opt/local/lib configure, but I still get the same error. I can compile and link a c program that includes gsl. What files is cabal looking for? If I have the right files, how do I tell it how to find them?
libgsl.a is a universal binary:
$ file /opt/local/lib/libgsl.a
/opt/local/lib/libgsl.a: Mach-O universal binary with 2 architectures
/opt/local/lib/libgsl.a (for architecture x86_64): current ar archive random library
/opt/local/lib/libgsl.a (for architecture i386): current ar archive random library
ghc looks like it's 64-bit:
$ ghc --info
[("Project name","The Glorious Glasgow Haskell Compilation System")
,("GCC extra via C opts"," -fwrapv")
,("C compiler command","/usr/bin/llvm-gcc")
,("C compiler flags"," -m64 -fno-stack-protector -m64")
,("ar command","/usr/bin/ar")
,("ar flags","clqs")
,("ar supports at file","NO")
,("touch command","touch")
,("dllwrap command","/bin/false")
,("windres command","/bin/false")
,("perl command","/usr/bin/perl")
,("target os","OSDarwin")
,("target arch","ArchX86_64")
,("target word size","8")
,("target has GNU nonexec stack","False")
,("target has subsections via symbols","True")
,("Project version","7.4.2")
,("Booter version","7.4.2")
,("Stage","2")
,("Build platform","x86_64-apple-darwin")
,("Host platform","x86_64-apple-darwin")
,("Target platform","x86_64-apple-darwin")
,("Have interpreter","YES")
,("Object splitting supported","NO")
,("Have native code generator","YES")
,("Support SMP","YES")
,("Unregisterised","NO")
,("Tables next to code","YES")
,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn")
,("Leading underscore","YES")
,("Debug on","False")
,("LibDir","/usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2")
,("Global Package DB","/usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2/package.conf.d")
,("Gcc Linker flags","[\"-m64\"]")
,("Ld Linker flags","[\"-arch\",\"x86_64\"]")
]
As an alternative to mac-ports you can use the nix package manager for mac. It does a pretty good job of taking care of the c dependancies for for the libraries available through it. In general I have been more happy with it then any other package manager on mac.
Unfortunately mac(darwin) unlike for linux does not have as many binaries available through nix so installing ghc often means waiting for it to compile.
The commands to install ghc and hmatrix after installation of nix are:
nix-env -iA nixpkgs-unstable.haskellPackages.ghc
nix-env -iA nixpkgs-unstable.haskellPackages.hmatrix
All of the needed dependencies will be taken care of for you.
I just tried it on my macbook pro and hmatrix seems to be working correctly in ghci after trying commands from the first few pages of the tutorial.
I'm not a mac person, but it really sounds like you haven't installed the "-dev" version. For a mac, I suspect you need to install gsl-devel in addition to gsl. If the problem persists, verify that you have libgsl0-dev on your library path.
I am learning more complex compilations in OCaml.
first I haven't been a C programmer and I really don't know what is make, etc. I am using Mac OS X terminal and i am also a Java programmer.
I find that in OCaml, there some things like ocamlc, ocamlbuild, ocamlfind, oasis, etc. I got very confused by them.
Question 1
Can anyone tell me which one I should use among ocamlc, ocamlbuild, ocamlfind, oasis?
Question 2
I tried this tutorial http://nicolaspouillard.fr/ocamlbuild/ocamlbuild-user-guide.html, it is good for ocamlbuild.
But if I want to use external libraries such as ocaml-batteries or camomile, how can I link those libraries using ocamlbuild?
Question 3
This is a more practical question about all the external libraries.
So for many ocaml libraries, I use opam install to install them.
why need to install a library? I mean, in Java, normally we just copy a lib to somewhere and then include the path of the lib into -classpath or -cp. then why we need to install a OCaml library?
after opam install a lib, such as camomile (for utf8), what happened and what will happen? Is this kind of install just download sourcefiles of a lib and copy it to somewhere?
how can find the library then? for example, if I opam install camomile, then how can I link or use them in my own code?
normally how to use a ocaml library? for example, for camomile (http://camomile.sourceforge.net/dochtml/index.html) they have three modules: CamomileLibrary, etc. So I should open the module in my code, right?
Tools:
ocamlc: OCaml to bytecode compiler
ocamlopt: OCaml to native code compiler
ocamlfind: wrapper around ocamlc and ocamlopt to compile/link with various OCaml packages, i.e. you use "ocamlfind ocamlopt -package camomile -c yourfile.ml' to compile with yourfile.ml,
and you use 'ocamlfind ocamlopt -package camomile yourfile.cmx -linkpkg -o yourfile' to create an executable
oasis: a build system generator like autoconf&automake for C/C++ but much simpler
With a recent ocamlbuild you can use 'ocamlbuild -use-ocamlfind -pkg -pkg ... ' as quick way of building your project with ocamlfind packages package1, package2.
A next step would be to use 'ocamlbuild -use-ocamlfind ' and put package() directives in a _tags file.
However I would recommend trying oasis, it simplifies creating a build system for your project.
If you want to see what happens "under-the-hood" when using oasis or ocamlbuild see the _build/_log file. It contains all the ocamlfind/ocamlc/ocamldep/ocamlopt invocations.
The opam question probably belongs into a separate question.
According to this post (https://github.com/mxcl/homebrew/pull/2953), the flag "--with-mpi" should enable boost_mpi build support for the related homebrew formula, so I am trying to install boost via homebrew like this:
brew install boost --with-mpi
However, the actual boost mpi library is not being build and can not be found.
There is currently some work being done around this, according to: https://github.com/mxcl/homebrew/pull/15689
In summary, I can currently build boost, but it seems the "--with-mpi" flag is being ignored. Could someone please check, if I should be able to build boost (with mpi support) on Mac OS X Mountain Lion (10.8)?
The (verbose) output generates these lines:
MPI auto-detection failed: unknown wrapper compiler mpic++
Please report this error to the Boost mailing list: http://www.boost.org
You will need to manually configure MPI support.
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
Not sure how exactly I can fix this and get the mpi stuff to be build - any ideas?
Just in case this helps anyone else along the line, here's how I fixed this. The main error is MPI auto-detection failed: unknown wrapper compiler mpic++, any typing mpic++ at the command line verified that it was not working properly for me. I used brew to install open-mpi, but the same error was showing in the verbose output for installing boost. A run of brew doctor showed that openmpi was not linked properly, so I fixed those errors and reran brew -v install boost --with-mpi --without-single and it finally built and installed all of the libraries without a problem
To anyone that comes across this, the package migrated to boost-python and boost-mpi separate from boost. Use brew install boost-mpi
Just get it worked on OSX 10.11.5. I've tried brew, but with no luck.
Suppose you already have gcc installed. Here are what I've done:
1. Find and disable (but do not remove) clang
clang alway cause headaches. There would be a lot of warnings when building Boost.
which clang, which should give you /usr/bin/clang
Rename it: sudo mv clang clang_mac_remove, also for clang++: sudo mv clang++ clang++_mac_remove. You can change the names back if you need them in future.
2. Install OpenMPI
If you already installed using brew, uninstall first. Becasue it would have used clang as the compiler wrapper by default. You need to change the wrapper to gcc.
Download the package.
Specify the wrapper compiler to gcc and g++:
./configure CC=gcc CXX=g++ F77=ifort FC=ifort --prefix=/usr/local
Below may take a long time.
make all
sudo make install
Reference: https://wiki.helsinki.fi/display/HUGG/Open+MPI+install+on+Mac+OS+X
3. Install Boost MPI
Download the package.
Run ./bootstrap.sh (can open it first and specify the toolset to gcc, otherwise, the default option is darwin for mac).
Add using mpi ; in project-config.jam file. Then ./b2 —with-mpi will only build the mpi library.
Then, all built libraries can be found in the folder ~/Downloads/boost_1_61_0/stage/lib.
Copy or move them to /usr/local/lib or any other commonly used library path.
Reference: http://www.boost.org/doc/libs/1_61_0/doc/html/mpi/getting_started.html
4. Compile with Boost MPI
LIBRARY DIR = -L/usr/local/lib
INCLUDE = -I/usr/local/include/
LINKER = -lboost_mpi -lboost_serialization
e.g.
mpic++ -std=c++11 -I/usr/local/include/ -c boost_test.cpp -L/usr/local/lib -lboost_mpi -lboost_serialization
Good luck!
I'm trying to follow the steps to compile some C code to import into Python from the example given here: http://csl.sublevel3.org/C-functions-from-Python/
I can compile it using the suggested invocation:
gcc -dynamiclib -I/usr/include/python2.3/ -lpython2.3 -o myModule.dylib myModule.c
But I'm using Python 3, I've muddled through and resolved a bunch of compiler errors, to end up with this:
gcc -dynamiclib -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/ -lpython3.2m -o myModule.dylib myModule.c
But now I'm stuck, this gives the following error:
ld: library not found for -lpython3.2m
From my limited knowledge I tried some things out. I've found that I have two locations where Python versions exist:
/System/Library/Frameworks/Python.framework/Versions
and also:
/Library/Frameworks/Python.framework/Versions
Python 3.2 is located in the second place, so I think that somehow I need to tell gcc where to search to resolve the -lpython3.2m? Or that -lpython3.2m is wrong, I've tried -lpython3.2 but I get the same type of error from ld.
Other facts that might help:
Mac OS 10.6.8
Python 3.2 installed from the DMG that you get from Python.org
If there is any other information that I can give you to help you to help me then please let me know
To tell gcc additional directories to search for libraries, you use the -L option, similar to the -I option you're already using. Something like -L/Library/Frameworks/Python.framework/Versions/3.2/lib, I would guess.