$darkmode
A high-performance general-purpose compute library
/home/abuild/rpmbuild/BUILD/arrayfire-full-v3.9.0/docs/pages/using_on_osx.md
Go to the documentation of this file.
1 Using ArrayFire on OSX {#using_on_osx}
2 ======================================
3 
4 Once you have [installed](\ref installing) ArrayFire on your system, the next
5 thing to do is set up your build system. On OSX, you may create ArrayFire
6 project using almost any editor, compiler, or build system. The only requirement
7 is that you can include the ArrayFire header directory, and link with the
8 ArrayFire library you intend to use.
9 
10 ## The big picture {#big-picture-osx}
11 
12 By default, the ArrayFire OSX installer will place several files in your
13 computer's `/opt/arrayfire` directory. The installer will populate this
14 directory with files in the following sub-directories:
15 
16  include/arrayfire.h - Primary ArrayFire include file
17  include/af/*.h - Additional include files
18  lib/libaf* - CPU, CUDA, and OpenCL libraries (.a, .so)
19  lib/libforge* - Visualization library
20  lib/libcu* - CUDA backend dependencies
21  share/ArrayFire/cmake/* - CMake config scripts
22  share/ArrayFire/examples/* - ArrayFire examples
23 
24 Because ArrayFire follows standard installation practices, you can use basically
25 any build system to create and compile projects that use ArrayFire. Among the
26 many possible build systems on Linux we suggest using ArrayFire with either
27 CMake or Makefiles with CMake being our preferred build system.
28 
29 ## Build Instructions:
30 * [CMake](#CMake)
31 * [Makefiles](#Makefiles)
32 
33 ## CMake {#CMake}
34 
35 The CMake build system can be used to create ArrayFire projects. As [discussed
36 above](#big-picture-osx), ArrayFire ships with a series of CMake scripts to make
37 finding and using our library easy.
38 
39 First create a file called `CMakeLists.txt` in your project directory:
40 
41  cd your-project-directory
42  touch CMakeLists.txt
43 
44 and populate it with the following code:
45 
46  find_package(ArrayFire)
47  add_executable(<my_executable> [list your source files here])
48 
49  # To use Unified backend, do the following.
50  # Unified backend lets you choose the backend at runtime
51  target_link_libraries(<my_executable> ArrayFire::af)
52 
53 where `my_executable` is the name of the executable you wish to create. See the
54 [CMake documentation](https://cmake.org/documentation/) for more information on
55 how to use CMake. To link with a specific backend directly, replace the
56 `ArrayFire::af` with the following for their respective backends.
57 
58 * `ArrayFire::afcpu` for CPU backend.
59 * `ArrayFire::afcuda` for CUDA backend.
60 * `ArrayFire::afopencl` for OpenCL backend.
61 
62 Next we need to instruct CMake to create build instructions and then compile. We
63 suggest using CMake's out-of-source build functionality to keep your build and
64 source files cleanly separated. To do this open the CMake GUI.
65 
66  cd your-project-directory
67  mkdir build
68  cd build
69  cmake ..
70  make
71 
72 *NOTE:* If you have installed ArrayFire to a non-standard location, CMake can
73 still help you out. When you execute CMake specify the path to ArrayFire
74 installation root as `ArrayFire_DIR` variable.
75 
76 For example, if ArrayFire were installed locally to `/home/user/ArrayFire` then
77 you would modify the `cmake` command above to contain the following definition:
78 
79  cmake -DArrayFire_DIR=/home/user/ArrayFire ..
80 
81 You can also specify this information in the `ccmake` command-line interface.
82 
83 ## Makefiles {#Makefiles}
84 
85 Building ArrayFire projects with Makefiles is fairly similar to CMake except you
86 must specify all paths and libraries manually.
87 
88 As with any make project, you need to specify the include path to the directory
89 containing `arrayfire.h` file. This should be `-I /opt/arrayfire/include` if you
90 followed our installation instructions.
91 
92 Similarly, you will need to specify the path to the ArrayFire library using the
93 `-L` option (e.g. `-L/opt/arrayfire/lib`) followed by the specific ArrayFire
94 library you wish to use using the `-l` option (for example `-lafcpu`,
95 `-lafopencl`, `-lafcuda`, or `-laf` for the CPU, OpenCL, CUDA, and unified
96 backends respectively.
97 
98 Here is a minimal example Makefile which uses ArrayFire's CPU backend:
99 
100  LIBS=-lafcpu
101  LIB_PATHS=-L/opt/arrayfire/lib
102  INCLUDES=-I/opt/arrayfire/include
103  CC=g++ $(COMPILER_OPTIONS)
104  COMPILER_OPTIONS=-std=c++11 -g
105 
106  all: main.cpp Makefile
107  $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)