![]() | Compiler and Linker Flags |
Prev | Compiling Regina Into a C++ Project | Next |
When you compile your own C++ code that uses Regina's calculation engine, you will need to pass some extra flags to the compiler. There are two ways to do this: a simple way using a Makefile, and a more complex but more flexible way that extracts Regina's compiler and linker flags and passes them through to gcc.
You can use the regina-helper tool to create a Makefile. This Makefile is suitable for compiling small programs that are entirely contained in a single C++ source file.
example$
regina-helper makefile
Preparing Makefile...example$
Makefilels
example$
If you have a C++ source file named mycode.cc
(for example), you can put it in the same directory as the Makefile
and compile it by typing make mycode
.
The Makefile will ensure that the compiler receives all of the
necessary flags for building your program against Regina.
Regina also ships with a utility
regina-engine-config,
which will give you the necessary flags explicitly.
To find the compiler and linker flags,
run regina-engine-config --cflags
and
regina-engine-config --libs
respectively.
example$
regina-engine-config --cflags
-I/usr/include/regina-normal -I/usr/include -I/usr/include/libxml2example$
regina-engine-config --libs
-L/usr/lib -lregina-engine /usr/lib/libxml2.so /usr/lib/libgmp.so /usr/lib/libgmpxx.so /usr/lib/libz.so -lpthreadexample$
If your code is a single C++ source file, you can compile and link a final executable in a single step:
example$
g++ mycode.cc `regina-engine-config --cflags --libs`
example$
If your code is spread across multiple source files, you should set up your build system so that it fetches the compiler and linker flags from regina-engine-config.
Note that compiler and linker flags will differ from system to system. You should always use regina-engine-config to find out what they are, and not just copy the flags that appear in the examples above.
Tip
The compiler and linker flags that regina-engine-config outputs are tailored to the GNU C++ compiler (g++) and Clang. If you use a different compiler, you might need to adjust your flags accordingly.
Prev | Contents | Next |
Compiling Regina Into a C++ Project | Up | API Documentation |