Wednesday, July 29, 2015

Running ClojureCLR 1.7 on Mac OS X

ClojureCLR 1.7.0 came out few days ago. Trying it out on Mac OS X took some steps that I document in this post.

Step 1: Download latest Mono from the URL below
http://www.mono-project.com/download/#download-mac

Step 2: Download ClojureCLR 1.7.0 using NuGet client
$ nuget install Clojure -Version 1.7.0
This command will create a directory 'Clojure.1.7.0' containing ClojureCLR 1.7 files.

Step 3: Put lib and tools files together
$ cd Clojure.1.7.0
$ mkdir all
$ cp -r lib/net40 all
$ cp -r tools/net40/* all/net40
$ cp -r lib/net35 all/
$ cp -r tools/net35/* all/net35/

Step 4: Verify that files are combined by running the 'tree' command
$ tree
.
├── Clojure.1.7.0.nupkg
├── all
│   ├── net35
│   │   ├── Clojure.Compile.exe
│   │   ├── Clojure.Main.exe
│   │   ├── Clojure.dll
│   │   ├── Microsoft.Dynamic.dll
│   │   ├── Microsoft.Scripting.Core.dll
│   │   └── Microsoft.Scripting.dll
│   └── net40
│       ├── Clojure.Compile.exe
│       ├── Clojure.Main.exe
│       ├── Clojure.dll
│       ├── Microsoft.Dynamic.dll
│       └── Microsoft.Scripting.dll
├── lib
│   ├── net35
│   │   ├── Clojure.dll
│   │   ├── Microsoft.Dynamic.dll
│   │   ├── Microsoft.Scripting.Core.dll
│   │   └── Microsoft.Scripting.dll
│   └── net40
│       ├── Clojure.dll
│       ├── Microsoft.Dynamic.dll
│       └── Microsoft.Scripting.dll
└── tools
    ├── net35
    │   ├── Clojure.Compile.exe
    │   └── Clojure.Main.exe
    └── net40
        ├── Clojure.Compile.exe
        └── Clojure.Main.exe

9 directories, 23 files

Step 5: Create a script called mklinks.sh with the following content
#!/usr/bin/env bash
ln -s Clojure.dll clojure.clr.io.clj.dll
ln -s Clojure.dll clojure.core.clj.dll
ln -s Clojure.dll clojure.core_clr.clj.dll
ln -s Clojure.dll clojure.core_deftype.clj.dll
ln -s Clojure.dll clojure.core_print.clj.dll
ln -s Clojure.dll clojure.core.protocols.clj.dll
ln -s Clojure.dll clojure.core_proxy.clj.dll
ln -s Clojure.dll clojure.genclass.clj.dll
ln -s Clojure.dll clojure.gvec.clj.dll
ln -s Clojure.dll clojure.instant.clj.dll
ln -s Clojure.dll clojure.main.clj.dll
ln -s Clojure.dll clojure.pprint.cl_format.clj.dll
ln -s Clojure.dll clojure.pprint.clj.dll
ln -s Clojure.dll clojure.pprint.column_writer.clj.dll
ln -s Clojure.dll clojure.pprint.dispatch.clj.dll
ln -s Clojure.dll clojure.pprint.pprint_base.clj.dll
ln -s Clojure.dll clojure.pprint.pretty_writer.clj.dll
ln -s Clojure.dll clojure.pprint.print_table.clj.dll
ln -s Clojure.dll clojure.pprint.utilities.clj.dll
ln -s Clojure.dll clojure.repl.clj.dll
ln -s Clojure.dll clojure.set.clj.dll
ln -s Clojure.dll clojure.stacktrace.clj.dll
ln -s Clojure.dll clojure.string.clj.dll
ln -s Clojure.dll clojure.template.clj.dll
ln -s Clojure.dll clojure.test.clj.dll
ln -s Clojure.dll clojure.uuid.clj.dll
ln -s Clojure.dll clojure.walk.clj.dll
Step 6: Create symlinks to Clojure.dll
cd all/net40
bash ../../mklinks.sh
cd ../..
cd all/net35
bash ../../mklinks.sh
cd ../..
Step 7: Run ClojureCLR now

Run the Clojure.Main.exe file with Mono. If everything went fine you will get a REPL.
$ mono all/net40/Clojure.Main.exe
Clojure 1.7.0
user=>
That is all. If you like this post you may like to follow me on Twitter.

6 comments:

  1. Thanks for this, really helpful - should be in the official Clojure-CLR wiki really.

    ReplyDelete
  2. Thanks so much! This was really helpful for Clojure 1.7.0. Sadly, I get the following error:

    Even though I edited the script to be:

    ```
    System.TypeInitializationException: The type initializer for 'Clojure.CljMain' threw an exception. ---> System.TypeInitializationException: The type initializer for 'clojure.lang.RT' threw an exception. ---> clojure.lang.Compiler+AssemblyInitializationException: Cannot find initializer for Clojure, Version=1.8.0.0, Culture=neutral, PublicKeyToken=cf3caecd327a2fa9.clojure/core/server
    ```

    ```
    #!/usr/bin/env bash
    ln -s Clojure.dll clojure.clr.io.clj.dll
    ln -s Clojure.dll clojure.clr.shell.dll

    ln -s Clojure.dll clojure.core.protocols.clj.dll
    ln -s Clojure.dll clojure.core.reducers.clj.dll
    ln -s Clojure.dll clojure.core.server.clj.dll

    ln -s Clojure.dll clojure.pprint.cl_format.clj.dll
    ln -s Clojure.dll clojure.pprint.column_writer.clj.dll
    ln -s Clojure.dll clojure.pprint.dispatch.clj.dll
    ln -s Clojure.dll clojure.pprint.pprint_base.clj.dll
    ln -s Clojure.dll clojure.pprint.pretty_writer.clj.dll
    ln -s Clojure.dll clojure.pprint.print_table.clj.dll
    ln -s Clojure.dll clojure.pprint.utilities.clj.dll

    ln -s Clojure.dll clojure.reflect.clr.clj.dll

    ln -s Clojure.dll clojure.test.junit.clj.dll
    ln -s Clojure.dll clojure.test.tap.clj.dll

    ln -s Clojure.dll clojure.ants.clj.dll
    ln -s Clojure.dll clojure.core.clj.dll
    ln -s Clojure.dll clojure.core_clr.clj.dll
    ln -s Clojure.dll clojure.core_deftype.clj.dll
    ln -s Clojure.dll clojure.core_print.clj.dll
    ln -s Clojure.dll clojure.core_proxy.clj.dll
    ln -s Clojure.dll clojure.data.clj.dll
    ln -s Clojure.dll clojure.dm-test.clj.dll
    ln -s Clojure.dll clojure.edn.clj.dll
    ln -s Clojure.dll clojure.genclass.clj.dll
    ln -s Clojure.dll clojure.gvec.clj.dll
    ln -s Clojure.dll clojure.instant.clj.dll
    ln -s Clojure.dll clojure.main.clj.dll
    ln -s Clojure.dll clojure.pprint.clj.dll
    ln -s Clojure.dll clojure.reflect.clj.dll
    ln -s Clojure.dll clojure.repl.clj.dll
    ln -s Clojure.dll clojure.set.clj.dll
    ln -s Clojure.dll clojure.stacktrace.clj.dll
    ln -s Clojure.dll clojure.string.clj.dll
    ln -s Clojure.dll clojure.template.clj.dll
    ln -s Clojure.dll clojure.test.clj.dll
    ln -s Clojure.dll clojure.uuid.clj.dll
    ln -s Clojure.dll clojure.walk.clj.dll
    ln -s Clojure.dll clojure.zip.clj.dll
    ```

    ReplyDelete
    Replies
    1. I'm sorry I noticed your comment so late. I think you were trying Clojure 1.8.0 - I will probably update the post for a newer version of Clojure.

      Delete
  3. Sorry, forgot to ask, what suggestions do you have for this error? Thanks so much!

    ReplyDelete
  4. I got a different error when I was trying

    pair@fox ~/p/h/Clojure.1.9.0-alpha13
    > echo '(println "Hello CLR")' | time mono all/net40/Clojure.Main.exe -

    Unhandled Exception:
    System.TypeInitializationException: The type initializer for 'Clojure.CljMain' threw an exception. ---> System.TypeInitializationException: The type initializer for 'clojure.lang.RT' threw an exception. ---> System.IO.FileNotFoundException: Could not locate clojure.spec.cljc.dll or clojure/spec.cljc on load path.
    ...

    So I did the following extra links and then it worked and I could get a REPL too:

    ln -s Clojure.dll clojure.spec.cljc.dll
    ln -s Clojure.dll clojure.spec.gen.cljc.dll
    ln -s Clojure.dll clojure.core.specs.cljc.dll
    ln -s Clojure.dll clojure.core.server.cljc.dll
    ln -s Clojure.dll clojure.edn.cljc.dll

    ReplyDelete
    Replies
    1. Thanks, I will probably update the post for a newer version of Clojure.

      Delete

Disqus for Char Sequence