| 1 | # Description |
| 2 | This example shows how to setup CMake to build C++ project which uses ECL library. |
| 3 | |
| 4 | In `src/lisp` is definition of `core-lisp` system that's being loaded into C++ |
| 5 | program. |
| 6 | |
| 7 | Functions defined in `src/lisp/core-lisp.lisp`: |
| 8 | ``` |
| 9 | (defun hello-world () (format t "Hello World!~%")) |
| 10 | ``` |
| 11 | are used in `src/cxx/main.cpp`: |
| 12 | ``` |
| 13 | extern "C" { |
| 14 | extern void init_lib_CORE_LISP(cl_object); |
| 15 | } |
| 16 | |
| 17 | int main(int argc, char** argv) { |
| 18 | cl_boot(argc, argv); |
| 19 | ecl_init_module(NULL, init_lib_CORE_LISP); |
| 20 | cl_eval(c_string_to_object("(hello-world)")); |
| 21 | cl_shutdown(); |
| 22 | return 0; |
| 23 | } |
| 24 | ``` |
| 25 | |
| 26 | ## CMakeLists.txt |
| 27 | For more information about setup read `CMakeLists.txt` comments. |
| 28 | |
| 29 | # Build |
| 30 | Run: |
| 31 | ``` |
| 32 | $ mkdir build |
| 33 | $ cd build |
| 34 | ``` |
| 35 | If ECL is built and installed with non-default prefix use: |
| 36 | |
| 37 | ``` |
| 38 | $ cmake -DCMAKE_PREFIX_PATH=/home/user/local_prefix/ .. |
| 39 | ``` |
| 40 | |
| 41 | Otherwise you don't have to set `CMAKE_PREFIX_PATH`: |
| 42 | ``` |
| 43 | $ cmake .. |
| 44 | ``` |
| 45 | |
| 46 | Finally run: |
| 47 | ``` |
| 48 | $ make |
| 49 | ``` |
| 50 | |
| 51 | It shall produce: `cmake_ecl` executable and `core-lisp.a` static library that |
| 52 | has been linked to executable. |
| 53 | |
| 54 | |
| 55 | # Run |
| 56 | ``` |
| 57 | $ ./cmake_ecl |
| 58 | Hello World! |
| 59 | ``` |
| 60 | |
| 61 | # Notes |
| 62 | 1. You don't have to remove `./build` directory if you want to change option |
| 63 | in `CMakeLists.txt`. Just run `make`. |
| 64 | |
| 65 | 2. If you see `undefined reference` errors look at `nm --demangle core-lisp.a` |
| 66 | output. You may have forgot setting `:init-name` in `CMakeLists.txt` |
| 67 | |
| 68 | 3. To reuse this example you must copy `cmake` directory to your project. It |
| 69 | contains `FindECL.cmake` |
| 70 | |
| 71 | 4. You don't have to have `ecl` executable in `$PATH` environment variable. |
| 72 | `FindECL.cmake` shall find it. |