I\'m not new in C++ although I\'m new in Linux. I\'m using CMake to precompile a cross-platform game engine with some third-party components, but I have a lot of doubts abou
Okay, so this is one of the basic questions and while I myself might not come across very clear on this, here goes:
That's the basics.
If you have some specific libaries, you can add them to your own project-specific lib/
and include/
directories and add them to the include path and the library path respectively.
Adding these dirs to these paths can be done in many ways, depending upon how you are building the project. I'm sure there is something called LD_PATH involved in all this... But I don't really know the specifics involved with CMake.
A little googling can help you do the above with CMake.
Hope that helps,
jrh
If you are installing the libraries with a package manager, they will probably all end up in the right place. If not you can get the compiler to search for the by providing the an additional search path using the -L <path>
flag. You should be able to pass this extra flag to CMake.
Incidentally the -I <path>
can be used to add an extra directory to search for include files.
Where to put libraries
The best solution is to use your Linux distribution's packaging system (apt-get
, yum
, or similar) to install libraries from distro-provided packages wherever possible.
If the distro's packaged libraries aren't of a recent enough version, or if you need some nonstandard build options, or if you need a library that your distro doesn't provide, then you can build and install it yourself. You have two main options for where to put the library:
/usr/local
(libraries under /usr/local/lib
, headers under /usr/local/include
). This installs the libraries systemwide and is probably the simplest solution, since you should then be able to build against them without taking any extra steps. Do NOT install libraries directly under /usr
, since that will interfere with your distro's packaging system.LD_LIBRARY_PATH
or ld.so.conf
- see the link for more details).How libraries work
See David A. Wheeler's excellent Programming Library HOWTO. I'd recommend reading that then posting any specific questions as new topics.
How to distribute your program
Traditionally, Unix / Linux programs do not include copies of their dependencies. It's instead up to the end user or developer to install those dependencies themselves. This can require a "large README," as you said, but it has a few advantages:
If you're distributing your program to end users, you may want to consider offering a package (.dpkg
or .rpm
) that they could simply download and install without having to use source. Ideally, from the end user's perspective, the package would be added to distros' repositories (if it's open source or at least freely available) so that users can download it using their package managers (apt-get
or yum
). This can all get complicated, because of the large number of Linux distros out there, but a Debian/Ubuntu compatible .dpkg
and a Red Hat/CentOS/Fedora-compatible .rpm
should cover a good percentage of end users. Building packages isn't too hard, and there are good howtos online.
for the first part of your question regarding Windows: there's no real standard place for libraries/headers on Windows, so the easy solution is: create your own. Simply provide a single lib/ and include/ on your system and have all your projects use it (by setting the path in a cmake file that you include everywhere). Put all third party libs in there, for example:
your projects:
d:/projects/projectA
d:/projects/projectB
third party stuff:
d:/api/lib/lua.lib
d:/api/include/lua/....
(you can even use symlinks aka 'directory junctions' if you have different version)
and the corresponding cmake file:
include_directories( d:/api/include )
link_directories( d:/api/lib )