I downloaded the latest version of Boost libraries 1_60_0 and I tried to use it but I quickly ran into troubles.
boost::unordered_map<int, int> map;
This piece of code says "namespace boost has no member unordered_map". I checkd the file, it is there though. The same happened for basically everything I tried to acces from the boost namespace.
Header includes are as follows:
#include <D:/IP/boost_1_60_0/boost/graph/adjacency_list.hpp>
#include <D:/IP/boost_1_60_0/boost/graph/graph_traits.hpp>
#include <D:/IP/boost_1_60_0/boost/graph/connected_components.hpp>
#include <D:/IP/boost_1_60_0/boost/unordered_map.hpp>
#include <D:/IP/boost_1_60_0/boost/graph/floyd_warshall_shortest.hpp>
#include <D:/IP/boost_1_60_0/boost/numeric/ublas/matrix.hpp>
#include <D:/IP/boost_1_60_0/boost/numeric/ublas/io.hpp>
I'm guessing I should include something more, but no clue what. Any tips?
unordered_map.hpp includes other boost header files this way:
#include <boost/config.hpp>
Which means that the boost folder has to be set as an additional include directory for this to work.
I'm assuming you're compiling on MSVC, if so, right click your project : properties -> C/C++ -> General and add the folder D:/IP/boost_1_60_0/ as Additional Include Directory.
The docs also answers this question for you.
Related
I am very new to cmake, but I am using it on Visual Studio to develop a program that has to run on linux. I need to include the following in this manner:
#include <xscontroller/xscontrol_def.h>
#include <xscontroller/xsdevice_def.h>
#include <xscontroller/xsscanner.h>
#include <xstypes/xsoutputconfigurationarray.h>
#include <xstypes/xsdatapacket.h>
#include <xstypes/xstime.h>
#include <xscommon/xsens_mutex.h>
However, the files are only recognize by visual studio when I do the following:
#include "xscontroller/xscontrol_def.h"
#include "xscontroller/xsdevice_def.h"
#include "xscontroller/xsscanner.h"
#include "xstypes/xsoutputconfigurationarray.h"
#include "xstypes/xsdatapacket.h"
#include "xstypes/xstime.h"
#include "xscommon/xsens_mutex.h"
The structure of my project in VS is fairly simple:
ANT
-out
-xscommon
-xscontroller
-xstypes
-ANT.cpp
-CMakeLists.txt
.
.
.
The includes I need are in the three xs folder, and I believe they have to be referenced with <> both in visual studio and when the code is compiled onto linux, as the references within each header are done in <> form, which is what causes this error:
xscallbackplainc.h:68:10: fatal error: xstypes/pstdint.h: No such file or directory
#include <xstypes/pstdint.h>
^~~~~~~~~~~~~~~~~~~
at compilation.
Concisely, I really just need to know what command (whether it be in CMakeLists.txt or somewhere else) will allow this kind of referencing within the project and the compiled project over ssh on linux. I am aware of the difference between #include "" and #include <>, I am however new to cmake, and have looked everywhere and cannot find an answer.
The simplest way to achieve this is using include_directories command. Simply add the following to your ANT/CMakeLists.txt:
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Though I would highly recommend using target_include_directories() instead. The difference between the two is that target_include_directories() specifies include directories just for one target[1].
[1]. A target is anything specified via add_executable() or add_library():
cmake_minimum_required(VERSION 3.12)
project(ANT)
add_executable(ANT ANT.cpp) #other source files as necessary
#format of target_include_directories:
# target_include_directories(target_name PUBLIC|PRIVATE PATH_TO_DIR)
target_include_directories(ANT PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
I have posted the question about linking, hopefully it makes sense. Should be clear I don't know what I'm doing.
I'm developing in VS2010 and looking to add code to an already existing project.
This is a Win32/MFC by the way.
And I couldn't help but notice that in class MyClass (in this case MyClass was an extension of the CDialog Class) the following was included at the top of the cpp file:
#include "MyClass.h"
#include ".\myclass.h"
I noticed that the second include was typed in without capitalization, but I couldn't quite figure out why?
"MyClass.h"
will be searched on INCLUDE_DIR path, which is defined in your project settings.
" ./myclass.h" will be searched in the same directory than the current file.
Windows files names are not case-sensitive so if your working dir is in your include path, these lines are pointing to the same file.
This redundancy is probably a way for VS to ensure the file will be included at least once...
Edit: thanks Arne Vogel, I was tired and wrote false things.
Your compiler will look for your header files only il the file name is like #include <file.h>
But I guess that the redundancy is to be compliant with all file systems.
.\ says to look in the current directory. I'm guessing with the include guards in that header, that wouldn't be a problem.
#include "MyClass.h" is from environment path, while #include ".\myclass.h" from current path.
most of the time, "MyClass.h" in the inc directory under your project, but you MyClass.cpp in other path.
I am trying to run this code
http://dlib.net/dlib/statistics/cca.h.html
As you can notice, it contains many include, which I copy them.
But inside each include there are a lot of includes like this :
#include "../matrix.h"
It contains
#include "matrix/matrix.h"
#include "matrix/matrix_utilities.h"
#include "matrix/matrix_subexp.h"
#include "matrix/matrix_math_functions.h"
#include "matrix/matrix_assign.h"
#include "matrix/matrix_la.h"
#include "matrix/symmetric_matrix_cache.h"
#include "matrix/matrix_conv.h"
#include "matrix/matrix_read_from_istream.h"
#include "matrix/matrix_fft.h"
#include "matrix/matrix_generic_image.h"
Is there any method to just include the main class? For example give the directory or the link of the classes?
I bet the problem lies with your include directories.
I assume you downloaded the full zip file from http://dlib.net/ (latest version seems to be 18.18). Inside that .zip you have a bunch of folders: examples, tools, dlib. In dlib folder you have all the header files.
You should add the path to wherever you extracted the .zip contents to the "Additional Include Directories" property of your project:
Then just use dlib in your own code as showed in the examples, for instance 3d_point_cloud_ex.cpp:
#include <dlib/gui_widgets.h>
#include <dlib/image_transforms.h>
Initially there is no need to create extra header files, all seems to be provided with a nice folder structure. I encourage you to read dlib's documentation before start using it.
You might also want to check this answer to another question to help you build a handy project folder structure.
I have been trying to create an static library out of C++ code by following this tutorial. If I trying to build the project some error occurs.
#include <limits> "limits" file not found
for example.
I have been trying different build settings, e.g. C++ Standard Library with no luck.
Rename the implementation files from .cpp to .mm did not work also. Is there an workaround to solve this issues?
Try using #include <limits.h> instead of #include <limits>
I've created an Allegro 5 project in Xcode 4.6.3 as an empty project. I've added all the Allegro 5 libraries as described in the Allegro documentation. But now I need to use some C/C++ libraries and get the error, that Xcode doesn't find the libraries (e.g. 'fstream file not found').
#include <allegro5/allegro5.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
How can I add the standard libraries to Xcode projects so that it finds them? Unfortunatelly I can't find any solution. This is not an Objective-C Project. It's written in C++ and also works if I don't use any of these libraries.
Thanks!
Does the name of your source file end with an extension that indicates it's C++? If it ends in (for instance) .c or .m, the compiler will not consider it to be C++, therefore the C++ headers won't be found. Try changing the extension on the source file name to .cpp (or some other extension that implies C++, see C++ code file extension? .cc vs .cpp ) and see if the header is found.