Trying to compile simple example program with boost::program_options. The suggested include directive for the lib is
#include <boost/program_options.hpp>
I noticed the hard path to boost/program_options.hpp (relative to root folder) is:
boost/libs/program_options/include/boost/program_options.hpp.
And the symlinked path from the root folder boost/program_options/ points to hard path:
boost/libs/program_options/include/boost/program_options/
which is one level below the program_options.hpp file.
I assume I should set my header search path in Xcode to
boost/libs/program_options/include/
and not at boost root?
If I do the former, I get no errors in editor, and auto-completion works, but when I go to compile I get error:
fatal error: 'boost/config.hpp' file not found
#include <boost/config.hpp>
Any advice on how to include this? Have used 1/2-dozen other boost libs without problem.
UPDATE
Sorry, I missed that this lib was NOT header-only.
On building with the program_options lib, it's working fine.
Related
I have the boost library in my downloads folders. When I tried to include a particular file. It is throwing errors. Below is the code and the steps I did.
\main.cpp
#include "type_index.hpp"
int main(){
//some code
return 0;
}
I opened the command prompt and ran the following command
g++ -IC:\Users\Owner\Downloads\boost_1_70_0\boost -o main main.cpp
I got the following error in command prompt
In file included from main.cpp:2:0:
C:\Users\Owner\Downloads\boost_1_70_0\boost/type_index.hpp:17:28: fatal error: boost/config.hpp: No such file or directory
#include <boost/config.hpp>
^
compilation terminated.
How can I run the above file? Do I have to change the location of boost directory from downloads folder to some where within mingw directories?
Adding the picture of directory:
Assuming boost is correctly configured and built on your system, there will be a location where the hub of the boost include root is located. Ex: if you downloaded and built boost in c:\Stuff\boost_1_70_0, then within that folder will be the hub of the boost include set, c:\Stuff\boost_1_70_0\boost, and it contains all of the boost headers.
boost is referenced by amending the include path to provide access to the boost include hub; not to provide access to the top-most headers in the hub. Similar to openssl, boost prefaces all of their header includes in their own headers, with boost/. The consumers of boost should do the same, Therefore, the include path must include the folder where the boost/ hub can be found. It should not include the boost/ hub itself as part of the path.
Ex: This is correct
g++ -Ic:\Stuff\boost_1_70_0 -o main main.cpp
This, on the other hand is wrong:
g++ -Ic:\Stuff\boost_1_70_0\boost -o main main.cpp
With the former, when code includes:
#include <boost/asio.hpp>
the include path is searched, and the file is found. Further, within that header, when the compiler see this:
#include <boost/asio/associated_allocator.hpp>
it can still resolve correctly, because dropping that "thing" on the end of one of the folders in the include path works.
Now, consider the wrong case. What happens if you configure the include path to accidentally specify the boost/root hub itself? Well, now you can do this:
#include <asio.hpp>
But as soon as the preprocessor starts in on that header it will see:
#include <boost/asio/associated_allocator.hpp>
Um.. woops. The pre-processor will look for this and never find it
Summary
When using boost headers in your source, you always refer to them with the boost hub preamble:
#include <boost/headername.hpp>
and always include the folder where the boost/ hub is located in your build configuration as an amended include path; not full path including the boost/ hub.
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.
I've downloaded the latest version of FreeType and want to get the source code running in my program. I'm programming in Eclipse and I've copied all the Freetype files into my project. I've listed them under ProjectName/Source/FreeType2/..
I've added compiler include directories for the new folders, so my GCC C++ compiler knows where to look for them. However, if I build my project, an error occurs on the last line of the following code:
#include <ft2build.h>
#include FT_WINFONTS_H
#include FT_INTERNAL_DEBUG_H
I did some research and the macro file FT_INTERNAL_DEBUG_H is defined as <internal/ftdebug.h>. The file is present in my system and the macro file FT_WINFONTS_H compiles like a charm! I think it's got something to do with my directory stucture somehow. How should I change my directory structure in order to get things compiled succesfully? My current structure is like this:
ProjectName
Source
FreeType2
devel
docs
include
config
internal
objs
src
I know I used two "source" folders, but this shouldn't be the problem, right?
The error message I get is Invalid preprocessor directive: #include FT_INTERNAL_DEBUG_H
Thank you for your time ;)
My understanding is that when I build a C++ project in xcode and I have an include line in one of my C files in angle-bracket form then the C++ compiler that works with xcode looks in /System/Library/Frameworks/ to find the file. I think that because of this answer: when I use the line #include <OpenGL/gl.h> in my xcode project, where does it look for the gl.h file?
I have an SDL.h file at /System/Library/Frameworks/SDL.framework/headers/SDL.h (I downloaded the folder SDL.framework and copied it to that location with the command sudo cp -r /Volumes/SDL/SDL.framework System/Library/Frameworks)
But my include statement in one of the files in my xcode project still gives this error:
#include <SDL/SDL.h> //throws file not found
Did I properly install the SDL framework? Why doesn't xcode see it?
Under your projects Build Settings, do a search for "search". Add a header search path to the SDL directory /System/Library/Frameworks/SDL.framework/headers
Should be able to just do this after:
#include <SDL.h>
Hope that works for you.
You can also check out this link:
http://meandmark.com/blog/2012/01/using-sdl-with-xcode-4/
It's for Xcode 4, but it looks like all the pieces are there.
I'm trying to build a project of mine that includes fuzzylite C++ libraries within a Carbon C++ application. However the compiler throws out an error for each fuzzylite's library I include in my source code. I've tried to include the Header Search Path and the Library Search Path on my target application build info but it doesn't work.
I've included the header file using double quote markers just like the following example:
#include "fuzzylite/test.h"
How can I include such library in my project and get it to work properly?
Easy, you need clean the path: #include "fuzzylite/test.h" for ALL #include, like this: #include "test.h"
From version 3.1, you should use #include fl/Headers.h.
If you are running into problems, I strongly encourage you to report the problem in the forums at http://www.fuzzylite.com, where I and others will be very happy to help you.