Library file placement in C++ - c++

I am trying to use the dynamic bitset provided by boost libraries. Downloaded the file boost_1_55_0.tar.bz2 and extracted it into a folder named boost. In this folder I have put my source code file with the #include directive #include <boost/dynamic_bitset.hpp>, when I compile the source code, the compiler returns "No such file or directory". Where to place the source code?

I managed to compile the program by putting the source code file in the the same directory that boost is in, and compiling using the command formula:
g++ -I /your/source/root /your/source/root/A/code.cpp
As mentioned in the How to make g++ search for header files in a specific directory?

Related

Can't link a static binary to #include it

Good day,
I have a file that I'm trying to compile and within it has an #include to a statically linked binary.
#!/bin/bash
g++ -Wall -std=c++17 Message.cpp ../textmagic-rest-cpp/lib/libtextmagic.a
I am getting the following error: fatal error: libtextmagic.h: No such file or directory
The relative path that I provided is correct under the assumption that the current working directory is the directory in which the script is called/ran. I might be linking the binary incorrectly and I've searched around the internet but the other posts/resources did not help me.
Note that the script is run in the same directory as Message.cpp.
g++ has the -I and -L flags that do that for you. Your flag will look like this: -I/ThePathToYourHeaders and -L/ThePathToYourLib. I don't know if g++ supports relative paths there but absolut paths are guaranteed to work there.
Also you probably need to add a linker flag. For your project it will be -ltextmagic. It is just the name of the .a file you want to link with, without the lib in front of the filename.
The #include directive needs to "read" the header file you give it as argument, and that is not included in the static library.
You can either include using a relative path to the source file or pass the location of the header file to the compiler using the -I argument.

C++ Shogun library: Cannot locate shogun/lib/config.h file

I am reading through the shogun C++ library code and while reading in the src folder, I notice that many files include the header file shogun/lib/config.h, but I cannot find this header file in the source code.
For example, if you look at the header file SGMatrix.h you can clearly see that it has the following include statement:
#include <shogun/lib/config.h>
yet you can't find config.h anywhere in shogun/lib. Where can I find this header file?
The config.h is being created during configuration, i.e. running cmake, and the actual content is based on your system's properties. the template of for the file can be found in src/shogun/lib/config.h.in

Cant compile rocksdb, dependencies not found

I am trying to compile a program that uses rocksdb.
According to the example in the official webpage, the only header i should add to my code is db.h.
Now, the file i am compiling is in folder A.
db.h however is in A/rocksdb-master/include/rocksdb/.
So, i add this line to my file:
#include "rocksdb-master/include/rocksdb"
It finds the file, but the problem is that inside db.h, i have this line:
#include "rocksdb/metadata.h"
And when i compile i get this error:
fatal error: rocksdb/metadata.h: No such file or directory
#include "rocksdb/metadata.h"
I mean, it's obvious. db.h is in the same folder as metadata.h, so it's fine that the compiler cant find any rocksdb folder. But i doubt that people who wrote this library don't know that.
Is there any other way to add the path's to compile it?
Why is it that the path from db.h are not relative to where it is located?
You should normally use just the following header in your project:
#include "rocksdb/db.h"
When compiling your own project, you should then add the RocksDB include path to the list of include directories. For example, if the RocksDB source code is in directory ../rocksdb-master, the include path will be ../rocksdb-master/include.
How to add the include path to the compiler flags is indeed compiler-specific. With g++ or clang, it's done by passing -I../rocksdb-master/include to the compiler when compiling your own program. Note that you many need to link against the RocksDB library as well.
And finally, you may need to include some more RocksDB headers if you use some of its advanced concepts, e.g. transactions.

Fatal error: FlexLexer.h: No such file or directory

I created a simple Flex file to read and return tokens from a file. I generated the scanner file using the command flex -c++ scanner.l. When trying to compile the generated lex.yy.cc file I am getting the error as:
Fatal error: FlexLexer.h: No such file or directory
The include folder of flex contains the FlexLexer.h file. I also tried by copying the file to the same folder where lex.yy.cc resides. Still the error exists.
I am using Windows7.
How can I solve this problem. Thank You
The generated scanner uses the line:
#include <FlexLexer.h>
which means that the FlexLexer.h file will be searched for in system include directories. If you correctly install flex, the installation should put the FlexLexer.h file in some system include directory. If you just download the flex source and compile it without installing it, that won't work. And it might not work in the Windows environment either; I've never tried.
If you have no other alternative, and you're using gcc, you can tell gcc to use the include directory in the flex source tree as a system include directory using the command-line option -isystem /path/to/flex/include. There's almost certainly a VS2010 equivalent but I have no idea what it is.

where to place the header and lib files

I have program which I need for a graphic interface. In the installation it says I should copy the "some_header.h" in my favorite include directory and the "libsomething.so" in my favorite lib directory. I know copied them to /usr/include/program-name and to /usr/lib/program-name respectively. When I know try to compile a c++ program using this graphic program, I get the error 'fatal error: some_header.h: No such file or directory, #include "some_header.h"'
What do I have to do, so the file is found?
compile your application with:
g++ -I/usr/include/program-name -L/usr/lib/program-name -lsomething .......
and this should sort out the directories.
-I is for include directories
-L is for library directories
-l is to use the given library
Another solution for the header file is to put it in the directory where your source is and then #include "some_header.h" is supposed to work out of the box.
Update
Of course, you always can put your files in standard system directories, such as: /usr/lib and /usr/include