C++: How to tell eclipse which version of library to use - c++

I am using ubuntu 12.04 and it has a version of boost (1.46.1)
installed to /usr/lib and include files in /usr/include.
I have compiled my own version (1.51.1) locally and have been using it fine up until now.
I am working on a new project which is using many includes in /usr/include and libs in /usr/lib so in my include path I have /usr/include and /home/aly/libs/boost/stage/include,
similarly in lib search paths I have /usr/lib and /home/aly/libs/boost/stage/lib. However when I add boost libraries to link it seems to be grabbing them from /usr/lib and it causing my code not to work.
If I remove /home/aly/libs/boost/stage/lib and /home/aly/libs/boost/stage/include
it works fine but now can't use the 1.51 features.
Is there an easy way around this problem?

Related

How to force CMake to ignore sytem db.h header file in favour of installed version on Mac?

I'm trying to port my CMake library to mac. I'm linking berkerly DB so I've installed it using brew and I'm able to find the appropriate paths (library, include etc) in cmake. They are
Berkerly
BERKELY_STATIC_LIBRARY /usr/local/lib/libdb.a
BERKELY_lIBRARY /usr/local/lib/libdb.dylib
BERKELY_INCLUDE_DIR /usr/local/include
However, my library doesn't compile because the dependency I am compiling includes db.h
#include <db.h>
which also exists at
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/db.h
and is being used in preference to the one at /usr/local/include. Is it be possible to force CMake to use the db.h from /usr/local/include instead of the other one?

How to Prioritize Boost Include for a Specific Version on macOS

The GitHub project, https://github.com/bluzelle/swarmDB , that I am working on provides an option that installs Boost 1.70.0 in the build folder and links from there.
Unfortunately, on macOS only, if the developer has installed a previous version of boost, 1.68.0 say, manually or via brew, the include and lib files are placed in
/usr/local
which causes the compiler to ignore the boost in the build folder, as it sees the older version of boost first. Since we are using new functionality in boost 1.70.0 this results in difficult to diagnose linker errors (well, not now, we know what the problem is).
The fix is to request developers remove the older version of boost, a better fix would be to ignore the older boost include folders and libraries.
How do we get the macOS c++ compilers to ignore the older boost versions include folder and libraries in favour of those installed in the build folder?

Set up Quantlib in Code Blocks on Fedora 25

I used to use Quantlib in Visual Studio on Windows, but recently transferred to Fedora Linux. I watched this video of setting up Quantlib in Eclipse On Ubuntu (https://www.youtube.com/watch?v=4NNc9mZ8Nro), but I noticed that in Fedora I could download and install the compiled rpm files for Quantlib and Boost. I would like to know how I can set up Quantlib in Code Blocks on Fedora 25 using these compiled rpm files.
I haven't used Code::Blocks, but the steps should be the same as for any other library; include in your sources the headers for the features you want to use, link the library with your compiled source, and make headers and libraries available to the compiler.
Starting from the end: the RPMs might have already installed QuantLib header files and libraries where the compiler can find them, so you probably won't have to worry about it. If that's not the case, find out where the RPMs installed QuantLib: headers and libraries might be in /usr/include/ and /usr/lib/, or /usr/local/include and /usr/local/lib. Add the include directory (which must contain the ql folder) to the include search paths for Code::Blocks, and the library directory (which must contain libQuantLib.*) to the library search paths.
The page at http://wiki.codeblocks.org/index.php/BoostWindowsQuickRef shows how to do it for Boost (look under the section "Add Boost search directories to your project"); you can do the same for QuantLib.
Once the search directories are set up, you have to include in your sources the QuantLib headers you need; for instance;
#include <ql/time/date.hpp>
if you want to use the Date class. Finally, add QuantLib to the list of libraries to link to your project. Again, this is done in the same way described for Boost on the page I linked above; look at the section "Include Boost headers and link with Boost libraries".

Install GMP library on Mac OS X 10.9 and Xcode

My question is as simple as the title. I have a Macbook Pro with OS X Mavericks (10.9.4) and Xcode (5.1.1). I need to install the GMP arbitrary precision libraries so that I can just get to write GMP-enabled programs from within Xcode.
I downloaded the package from the official website
I extracted it to my desktop
./configure --prefix=/usr/local --enable-cxx
make
make check
sudo make install
But when I go to Xcode and just #include <gmpxx.h> it doesn't find it. Also adding -lgmp to my linker flags causes an error.
I also tried using homebrew with brew install gmp but that didn't work either (same symptohms)
What is the correct way to solve this problem?
You need to ensure that you have an include path -I/usr/local/include, before you can include <gmpxx.h> (or <gmp.h> for that matter).
Also, adding -lgmp is insufficient, since that's only the C interface. You want to link with -lgmpxx (the C++ library), and possible specify the path to that library with -L/usr/local/lib.
You can run otool -L /usr/local/lib/libgmpxx.dylib, to ensure that libgmp.dylib is already linked to it. Which it should be.
Set the Header Search Path and Library Search Path in the Xcode Project Settings to /usr/local/include and /usr/local/lib respectively as, by default, these paths are not searched by Xcode.

Installing multiple copies of library on Unix

So suppose I have installed the SFML 1.6 C++ library from the Ubuntu repositories. Then I have header files in /usr/include/SFML, library files in /usr/lib etc.
Now I have also downloaded a recent source tarball and built and installed SFML 2.0 into /usr/local.
So by default, if I #include , it gets the SFML 2.0 copy from /usr/local/include. Similarly, it links to libraries from /usr/local/lib.
My question is, how can I tell the compiler/linker to get the files from /usr/include and /usr/lib? I tried
g++ -I/usr/include
but it didn't work. Is this possible at all? Or should I just keep the 'home built' copy in a non system location?
Check the ldconfig command. I guess running it in the destination folder of the newer version of the library should do the trick.