-
Notifications
You must be signed in to change notification settings - Fork 19
Using cf4ocl in a new project
This guide presumes you have cf4ocl installed in your system.
Source files should first include the cf4ocl header:
#include <cf4ocl2.h>
The following assumes a working installation of the pkg-config
build tool, which is usually bundled with GLib
. If this is not the case,
or if you prefer not to use this tool, click here
for an alternative approach.
If pkg-config
can't find cf4ocl, make sure the cf4ocl2.pc
file is
in its search path. For example, if cf4ocl2 was installed in
/usr/local/
(which is not a default library search path in some OSes),
one would first set the PKG_CONFIG_PATH
environment variable with the
appropriate value:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
There are two ways of using cf4ocl in your project:
- Using the CMake build framework.
- Manually specifying compiler options in the command line.
The latter option gives a good idea of how to specify these dependencies with other build systems.
If client code uses CMake as its build system, then it's very simple
to integrate cf4ocl. Simply add the following lines to your
CMakeLists.txt
file:
# Find required libraries
find_package(PkgConfig REQUIRED)
pkg_check_modules(CF4OCL2 REQUIRED cf4ocl2>=2.0.0)
# Library include directories
include_directories(${CF4OCL2_INCLUDE_DIRS})
Then, for each target, specify cf4ocl as a link library:
add_executable(myprog myprog.c)
target_link_libraries(myprog ${CF4OCL2_LIBRARIES})
CMake can then create the project or build files for several targets such as Unix Makefiles, Visual Studio, Xcode, Eclipse, etc.
The cf4ocl-examples project follows this approach.
If you prefer to manually set build options, directly in the compiler/linker options, in a makefile or in your IDE, follow these guidelines.
Depending on how cf4ocl was installed, it may be necessary to specify
the location of the cf4ocl header (and the headers of the cf4ocl
dependencies) with the -I
flag. These can be obtained with pkg-config
:
pkg-config --cflags cf4ocl2
It is necessary to specify cf4ocl (and other libraries) with the
-l
(and possibly -L
) flags. Using pkgconfig
, this is again a
simple process:
pkg-config --libs cf4ocl2
For example, to compile and link a simple program which uses cf4ocl with gcc or clang, one could do:
$ gcc `pkg-config --cflags cf4ocl2` myprog.c -o myprog `pkg-config --libs cf4ocl2`
You can try this with the mysum
program described in the
tutorial.