Reputation: 324
Beginner trying to understand the whole compliling+linking business. Why can't I build my C++ program using the CGAL library as usual and need to use CMake to build it?
Additional question: can I build using CMake inside an IDE? (For example Code::Blocks?)
@Mike : Well this is what I got from reading CGAL documentation. Did I misunderstand something?
Upvotes: 0
Views: 745
Reputation: 61590
You've been misled somewhat by the CGAL documentation you refer to.
The CGAL developers have chosen CMake as the build system for the CGAL source package. It is a popular build system (pre-eminent for cross-platform portability). They also illustrate the building of their example programs with CMake; naturally enough since the examples are part of the source package. They also recommend that you use CMake to build programs of your own that depend on CGAL.
It's fair enough for them to recommend CMake and not suprising that they do.
However: When you want to write a program that depends on any library - libfoo
- you proceed on the assumption that libfoo
is already installed ready for
use in your project. Which means:
The libfoo
header files - foo.h
, whatever - that define the library's
programming interfaces are on your system somewhere so that your compiler
can find and read them when you write, e.g. #include <foo.h>
in your code.
The libfoo
binaries - libfoo.a
, libfoo.so
, foo.lib
, foo.dll
,
libfoo.dylib
, as the case may be for your OS - that contain the
library's implementation are also somewhere on your system so
that your linker can find them and link them with the object code of your
program to make a complete executable. (And, in the case of dynamic
libraries, someplace where the runtime loader can find them).
So, as far as building your program is concerned, it doesn't matter at all
how the libfoo
header files and binaries got to be where they are on your
system, whether put there by CMake or by fairies. It only matters that they're
there. Then, you can build your program with CMake, if you want, or any
other way that you like.
Of course it may be the case when you decide to write your program that
libfoo
is not already installed on your system. In that case, you
install it. Then proceed with your program on the assumption that it is
installed
You need the CGAL library and header files to be installed. That would
normally be achieved, (Linux/OS X), by installing the libcgal
development package
provided by your OS using its package manager, or (Windows) by downloading
and running the installer. Then you don't need to know or care how CGAL
is built.
If you can't get a development package for some reason or are technically interested in installing the library "from first principles", then you need to build and install it from a source package. As the build system for the source package is CMake, you'll need to learn how to build and install it with CMake, and do so.
Once CGAL is installed, to use in your own projects you only need to take care of the routine requirements of using a library:-
Whether you do that with CMake, Scons, Autotools, a makefile, project settings in your IDE or simply running your compiler and linker at the command prompt with the right options is entirely your own choice. (Although the last is the most efficiently instructive, when you are a beginner trying to understand the whole compiling and linking business).
The CGAL example programs can be built with Code::Blocks as ordinary simple projects with library dependencies, as long as you've installed CGAL beforehand some way.
Upvotes: 2
Reputation: 40897
You can pass the code blocks generator on the command line when you invoke cmake. It'll create the files you need to use and build with your ide.
Upvotes: 0