include <Eigen/Dense> succeed, include <Eigen> failed - c++

My question is similar to this 5 years old question.
I can successfully compile it if I use the following code:
#include <Eigen/Dense>
#include <iostream>
//#include <boost/serialization/array_wrapper.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
int main(){
std::cout<<"asfserea"<<std::endl;
boost::gregorian::date d(boost::gregorian::day_clock::local_day());
std::cout << d.year() << d.month() <<d.day() << std::endl;
return 0;
}
But I got errors after I changed annotation from #include <Eigen/Dense> to #include <Eigen>, from #include <boost/date_time...> to #include <boost/serialization...>:

File you are looking for is <Eigen/Eigen>. If you want to include <Eigen>, you should add correct folder to your include path.
For array_wrapper.hpp, you need newer version of Boost. At least version 1.67.0 has this file.

When you #include <Eigen>, your compiler looks at the directories that you have told it about, for a file named Eigen. It only finds a folder named Eigen, and within that folder there are files Eigen and Dense. It does not look inside that folder.
If you change your compilers parameters to include the Eigen folder (rather than it's parent), you can #include <Eigen> and #include <Dense>. Alternatively, you can keep your include directories as they are, and prepend Eigen/ to all the Eigen includes

Related

Why does changing the order of including psapi.h gives compilation erros?(Indentifier BOOL is undefined)

I am using Visual Studio Community 2017 to code c++. When I run the following code everything works fine.
#include "pch.h"
#include<Windows.h>
#include<Psapi.h>
#include <iostream>
#include <conio.h>
int main()
{
std::cout << "Really!! How do you do it?";
_getch();
}
But if I change the order of #includes by including psapi.h before Windows.h, compiler goes badass and throws 198 errors at me, which surprisingly(maybe only to me) includes Identifier "BOOL" is undefined.
Why is this happening?
Since Psapi.h's include tree is trivial, I'm going to exemplify. Everything relies on VStudio 2015 (Community) (v14.0.25431.01 Update 3) and Windows Kits 8.1 (? funny, because v10 is there too) files (with default env vars and preprocessor definitions):
BOOL is defined in minwindef.h (#157: typedef int BOOL;)
Psapi.h only includes one file (#27: #include <winapifamily.h>)
winapifamily.h doesn't include any other file
So, when reaching Psapi.h (#87: BOOL WINAPI EnumProcesses (...), the compiler doesn't know anything about BOOL, so it complains.
Windows.h includes minwindef.h (indirectly, via windef.h), and that's why it works when you include it before Psapi.h.
Personally, I think it's a bug in Psapi.h, since it's not self contained, but there might be a good reason (that I'm not aware of) for that. Anyway, if this is indeed a bug, it wouldn't be MS's 1st one :)
#include <Windows.h>
#include <WinSock2.h>
// main present just for rigorosity's sake
int main() {
return 0;
}
to answer the question, I know this is DATED but the issues persist today. You need the following:
#include "stdafx.h"
#include <stdbool.h>
#include <Windows.h>
#include <stdlib.h>
#include <psapi.h>
After stdlib.h was included, the errors were gone.

Cant use boost in xCode

When I am trying to use the boost library in xCode, i keep getting an error.
I have linked the header and link library like the tutorials say, but i am still getting an error
> #include <iostream>
> #include <string> // std::string
> #include <sstream> // std::stringstream
> #include <initializer_list>
> #include <vector>
> #include <boost/type_index.hpp>
> using std::cout;
> using std::endl;
at the boost index, my compiler says "'boost/type_index.hpp' file not found" when I try building..
How do i fix this?
In your Xcode project build settings, you must ensure you find/choose it in the the header search paths. (eg /usr/local/boost_1_60_0/include/)

Using declaration "not found" in mongodb c++ driver

I'm using the mongo-cxx-driver-r3.1.1 based on mongo-c-driver-1.6.2.
Using the latest examples provided on github, I managed to find how to connect the database and how to save documents.
I'm struggling to fetch results using a filter following the informations provided in the mongocxx/query.cpp example.
There's a lot of call to a make_document method but I have no class/method/template in the bsoncxx namespace with that name (same problem with make_array).
Heres's the includes, the using directives and using declarations :
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/exception/exception.hpp>
#include <mongocxx/options/find.hpp>
using namespace mongocxx;
using namespace bsoncxx;
using bsoncxx::builder::basic::document;
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::sub_document;
using bsoncxx::builder::basic::sub_array;
using bsoncxx::builder::basic::array;
using bsoncxx::types::value;
using mongocxx::result::insert_one;
The using declarations "not found" :
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;
Am I missing something obvious ?
Are there more recent examples ?
Your code looks right, as you included all necessary header files needed for make_document and make_array.
You said in your comment, that the document.hpp doesn't contain the make_document and the array.hpp doesn't contain the make_array template.
This is right for the release mongo-cxx-driver-r3.1.1.
In the current master branch the header files exists as you can see if you follow the source links for them: document.hpp and array.hpp. The examples you use are probably for the new master branch as they are also from a current branch from git.

g++, Xerces 3.1, "memcpy was not declared in this scope"

In my makefile on this project, I am specifying 3 location for the compiler to find #includes.
INCLUDES=-I. -I/home/kelly/xerces/xerces-c-3.1.1/src -I/home/kelly/Utilities_New
When I compile the following sample code with the command line found in the comment:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <xercesc/util/XMLString.hpp>
using namespace std;
/*
g++ -I. -I/home/kelly/xerces/xerces-c-3.1.1/src -I/home/kelly/Utilities_New test.cpp
*/
int main(int argc, char* argv[])
{
cout << "this works" << endl;
}
In file included from /home/kelly/Utilities_New/string.h:5:0,
from /home/kelly/xerces/xerces-c-3.1.1/src/xercesc/framework/XMLBuffer.hpp:28,
from /home/kelly/xerces/xerces-c-3.1.1/src/xercesc/util/XMLString.hpp:26,
from test.cpp:7:
/home/kelly/Utilities_New/defs.h:26:21: fatal error: windows.h: No such file or directory
compilation terminated.
Clearly the compiler has decided that when it processes the Xerces #includes and finds string.h in the Utilities_New directory, it has found what it needs and stops there.
This other string.h was written by another programmer and I am attempting to use his library.
I thought that the standard locations were searched first. I'm a little lost here. I may be missing something super obvious to you all.
Also, wasn't there some rule about #include files that had <> vs. "" around them and where the compiler was supposed to look?
The standard locations are searched last.
#include "blah" is identical to #include <blah> unless blah is found in the same directory as the file that tries to include it. (And unless you use the rare and gcc-specific -iquote option).
For more information see here.

"No such file" Include issue with Boost dynamic_bitset

I'm trying to use Boost's Dynamic_bitset class for a project, and I (believe I) have taken whichever subset of files I needed from the complete library. Now I'm doing an
#include "boost/dynamic_bitset.hpp" inside my manager.cpp file, and when compiling I get this:
In file included from manager.cpp:4:0:
boost/dynamic_bitset.hpp:15:51: fatal error: boost/dynamic_bitset/dynamic_bitset.hpp: No such file or directory
The file ierarchy inside the project folder goes like this:
proj/extras.h
proj/Makefile~
proj/manager.cpp
proj/boost
proj/boost/limits.hpp
proj/boost/dynamic_bitset.hpp
proj/boost/mpl
proj/boost/mpl/if.hpp
proj/boost/mpl/has_xxx.hpp
proj/boost/iterator.hpp
proj/boost/static_assert.hpp
proj/boost/dynamic_bitset
proj/boost/dynamic_bitset/dynamic_bitset.hpp
proj/boost/dynamic_bitset/config.hpp
proj/boost/config
proj/boost/config/select_platform_config.hpp
proj/boost/config/select_compiler_config.hpp
proj/boost/config/user.hpp
proj/boost/config/suffix.hpp
proj/boost/config/select_stdlib_config.hpp
proj/boost/dynamic_bitset_fwd.hpp
proj/boost/config.hpp
proj/boost/type_traits
proj/boost/type_traits/is_same.hpp
proj/boost/type_traits/is_pointer.hpp
proj/boost/type_traits/remove_pointer.hpp
proj/boost/type_traits/remove_const.hpp
proj/boost/type_traits/is_base_and_derived.hpp
proj/boost/type_traits/detail
proj/boost/type_traits/detail/bool_trait_def.hpp
proj/boost/type_traits/detail/yes_no_type.hpp
proj/boost/pending
proj/boost/pending/integer_log2.hpp
proj/boost/detail
proj/boost/detail/limits.hpp
proj/boost/detail/dynamic_bitset.hpp
proj/boost/detail/workaround.hpp
proj/boost/lowest_bit.hpp
proj/Makefile
proj/generator.cpp~
proj/generator.cpp
This same project compiles fine on my university's linux systems(g++ 4.2.4 there but I doubt it matters), but fails to do so (with the above error) on my Ubuntu laptop. Why isn't it finding the file since it evidently exists?
All my includes are as such:
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include "boost/dynamic_bitset.hpp"
#include <cmath>
#include <list>
#include <unistd.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <errno.h>
#include <wait.h>
#include <time.h>
#include "extras.h"
compilation is done simply with
g++ -o manager manager.c
or
g++ -Iboost -o manager manager.c
if I want to explicitely include the (local..) folder
-I .
At least if you are compiling in the same directory that contains boost.
You wrote -Iboost and #include "boost/…". So it looks in ./boost if there is a boost subdirectory.