How do I include Boost.Interprocess and Boost.DateTime properly? - c++

This is a really basic question because I am a C++ newbie. I want to use the Boost.Interprocess library, but am having trouble building it. I'm trying to follow these instructions, but it's not working for me. Here is what I have:
#define BOOST_DATE_TIME_NO_LIB
#include <boost/interprocess/shared_memory_object.hpp>
#include <iostream>
using namespace std;
int main() {
cout << "Hello, beautiful world!\n";
}
But I get this error:
boost_1_55_0\boost\date_time\gregorian_calendar.hpp(63) : fatal error C1083: Cannot open include file: 'boost/date_time/gregorian_calendar.ipp': No such file or directory
I know Boost is able to load properly, because I can get an example that uses #include <boost/lambda/lambda.hpp> to work just fine. It's just when I try to include the Boost.Interprocess library that I am having trouble. The cause is clearly because it's having trouble including the Boost.DateTime library properly, but according to the documentation (linked above) I should be able to get by without separately compiling Boost.DateTime if I define BOOST_DATE_TIME_NO_LIB, right?
What am I missing here?

You need to add it to the preprocessor
In VS go to - Project >> properties >> C/C++ >> Preprocessor in the 'Preprocessor Definitions' paste BOOST_DATE_TIME_NO_LIB.

You can download boost libraries here: https://www.boost.org/users/download/
After that, you can include them in your projects. Also, you can check this video on how to add boost libraries in eclipse IDE on Ubuntu: https://www.youtube.com/watch?v=gN8zrnWxFeI

Related

FATAL ERRORS with compilation after installing Aspose.Cells library for C++

Can someone please help me with my issue with Aspose.Cells library for C++?
I was writing my first C++ programme using Aspose.Cells library. Everything seemed smooth except that the following error was produced after I built the file:
Error before I launch is:
"Error exist in a required project.Continue launch?"
Error after running the code is:
"**fatal error: boost/config/compiler/gcc.hpp: No such file or directory**".**
If I commented out the line #<include Aspose.Cells.h>, the file can run with no errors.
I tried to solve the error by installing Boost library for C++ from zip file "boost_1_73_0", as I think Aspose depends on Boost to run. However, I couldn't link to Boost successfully as there doesn't seem to be a "include" folder and "lib" folder for me to add into project properties.
My questions are:
Will installing Boost solve my problem?
If yes, how can I install Boost library successful?
The following is my code in C++. Thanks a Lot in advance!
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "!!!I am little red!!!" << endl;
return 0;
}
Regards
Hillary
UPDATE: I have successfully installed and linked Boot library now but I have got three warning message upon building: "Ignoring #pragma warning [-wunknown-pragmas]" , are these warning messages serious?
I also ran into another fatal error: unicode/uloc.h:No such file or directory. How can I correctly link up to unilib-master/Unicode library?
Yes, installing Boost helps.
If Aspose only requires header-only libraries from Boost, then you don't have to do much. The "include" path you're looking for is just the folder where you extracted the zip. The actual library headers are under boost/ in that folder, which are then found by the compiler.
If you need the shared libraries, you will need to build them. Follow the steps here Getting Started On Windows

Using Boost library in XCode

not particularly good with this kind of stuff I have managed to install the Boost C++ library and this basic program works with the g++ compiler and linking to the right .dylib files.
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost;
int main()
{
filesystem::path path1("/Users/username/Documents/testfile.txt");
filesystem::remove(path1);
std::cout << "It worked" << std::endl;
return 0;
}
Now I would like to do the same, just using Xcode to build and run the program, but it doesn't work. I have done everything in this tutorial:
http://buddypanda.com/?p=10
i.e. include header and library search paths, as well as linked the .dylib files of filesystem and system under the 'Build Phases' tab.
The Build succeeds but then the program crashed with an error of EXC_BAD_ACCESS.
I can maybe provide more specifics on what goes wrong if you tell me where to look.
Thanks!
EDIT1: I am using g++-4.9 and Boost-1.58 and Xcode 6.4

Compile C++ with static lib

this will probably a dumb question for you guy's but I have no experience in C++ what so ever. I'm using an open source project osrm (which is awesome). Still to request a route, you have make an http request. To reduce the running time, I would like to build a wrapper around the code and call it using the command line. So I googled a bit and found that osrm already creates a static lib (.a file) when compiling the project. I also found a piece of code that points me in the right directions for building a wrapper. So to begin I build a simple hello world program (see below) that includes some files from that static lib. To compile I followed this tutorial.
My directory structure looks like this:
./helloWorld.cpp
./libs/libOSRM.a
And the command to compile is this:
gcc –static helloworld.cpp –L ./libs –l libOSRM.a
The code it selve:
#include "Router.h"
#include "boost/filesystem/path.hpp"
#include "ServerPaths.h"
#include "ProgramOptions.h"
#include <InternalDataFacade.h>
#include <viaroute.hpp>
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
the exact error I got:
fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.h"
Add the -IPathToTheHeaderFiles to the compiler options. So it will find the files to be included. Replace PathToTheHeaderFiles with the path where your file ServPaths.h resides.
Edit: Add as many -I as you need for further header files.
Additionally it would be worth to read a book about C++ or/and the GCC manual1
1 Section 3.11 will help.

Boost build error with websocketpp and MySQL on Windows

I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.

C++ search directories and files

Can someone tell me if there is a library built in C++ that I can use to get a list of files and directories? I've looked around and I see people using dirent.h but I need to download it(i think).
Thanks
P.S. I've looked at the fstream, but thats only for reading and outputting files as far as i know.
FORGOT TO MENTION. I DO NOT WANT TO DOWNLOAD ANYTHING, I JUST WANT TO SEE IF THERE IS A LIBRARY THAT IS BUILT WITHIN C++ THAT I CAN USE STRAIGHT OFF THE BAT. THIS IS FOR WINDOWS ASWELL
How about Boost::Filesystem? Supports directory iteration and is portable.
You can use Boost Filesystem library.
http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/index.htm
Some nice samples are also provided at the link.
EDIT:
Without downloading a 3rd party library, there is no portable way to do it. For windows you can use CFileFind class from MFC.
Using namespace std::filesystem is available in visual studio 2017 you have in #include
#include <iostream>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <chrono>
#include <thread>
#include <functional>
namespace fs = std::filesystem;
void Files_in_Directory();
fs::path path_Copy_Directory = "E:\Folder";
fs::path path_Paste_Directory = "E:\Folder1";
int main()
{
Files_in_Directory()
return 0;
}
void Files_in_Directory()
{
for (const auto & entry : fs::directory_iterator(path_Copy_Directory))
{
std::cout << entry.path() << std::endl;
}
}
Since others already mentioned boost::filesystem there are also other alternatives. Almost every C++ framework has some way to list directories and files. Like wxWidgets or poco and there are many more.
Regarding dirent.h. It is a standard C Posix library so on Posix compatible systems it should be available. For Windows you can also get it here and it includes instructions on how to use it.
After your edit:
On Windows you can use things like FindFirstFile (example here) and then you don't have to download anything. But it only works on Windows. It is not build in C++.