Use dlib in Visual studio 2012 - c++

I want to use optimization algorithm lbfgs in my project but I do not want to code it myself. So I found Dlib is a good option.
http://dlib.net/compile.html is a good library. I downloaded it. I use windows 7 and visual studio 2012. If I create a new win 32 console project and set property->configuration properties->VC++ Directories->Include Directories to the path of Dlib(dlib-18.10/).
And it works fine which mean I can run examples.
But when I add it to my project. I occur errors.(error : "vector" is ambiguous)
I guess it maybe because the way I include it.
On the document of Dlib, it says,
Again, note that you should not add the dlib folder itself to your compiler's include path. Doing so will cause the build to fail because of name collisions (such as dlib/string.h and string.h from the standard library). Instead you should add the folder that contains the dlib folder to your include search path and then use include statements of the form #include <dlib/queue.h>. This will ensure that everything builds correctly.
But I am not clear what it means above. I googled the Visual Studio search path (Tools / Options / Projects and Solutions / VC++ Directories).. But in my project this is non-editable.
I only use optimization.h in dlib. If I delete 'using namespace dlib;', then ' typedef matrix column_vector;'then the error is matrix is not a template. If I keep 'using namespace dlib;' I have error "vector" is ambiguous`.
#include <dlib/optimization.h>
#include <iostream>
using namespace std;
using namespace dlib;
// ----------------------------------------------------------------------------------------
// In dlib, the general purpose solvers optimize functions that take a column
// vector as input and return a double. So here we make a typedef for a
// variable length column vector of doubles. This is the type we will use to
// represent the input to our objective functions which we will be minimizing.
typedef matrix<double,0,1> column_vector;

As the documentation says, include directory should be root directory of the zip you downloaded. Then you include as #include <dlib/vector.h>. However, since vector is defined under namespace of std as well, you should be specifically denote which namespace's STL you will use.
If you want to use std::vector,
#include <vector.h>
then use it as
std::vector<int> stdVar;
Similarly, for dlib,
#include <dlib/geometry/vector
then use it as
dlib::vector<int> dLibVar;
You could also delete using namespace std if you don't use it as frequent as dlib. Then every STL you reference will be dlib. If you want std, just type std::vector.

using namespace std;
using namespace dlib;
#define vector std::vector
use w/ caution

Related

C++ an VS error: <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft and will be REMOVED

I coded in C++ on Visual Studio (Windows 10) and got this error:
#error The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft \
and will be REMOVED. It is superseded by the C++17 <filesystem> header providing std::filesystem. \
You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.
With this headers:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <filesystem>//If I will disable it nothing happens.
#include <experimental/filesystem> //If I will disable it happens another error.
namespace fs = std::experimental::filesystem;
using namespace std;
I've tried: #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING in the main cpp file. It didnt help.
So then I paste this code from here:
#ifdef __cpp_lib_filesystem
#include <filesystem>
using fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem
#include <experimental/filesystem>
using fs = std::experimental::filesystem;
#else
#error "no filesystem support ='("
#endif
Didn't helped too.
What is the easiest way to get out that error?
Add _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to Preprocessor definitions.
Project -> Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.
This solved the issue for me.
According to the link
C++17’s is supported. This is a completely new
implementation, incompatible with the previous std::experimental
version, necessitated by symlink support, bug fixes, and changes in
standard-required behavior. Currently, including provides
the new std::filesystem and the previous
std::experimental::filesystem, and including
provides only the old experimental implementation. The experimental
implementation will be REMOVED in the next ABI-breaking release of the
libraries.
MS abandoned 'experimental' in filesystem.
You could try to use #include <filesystem>instead of #include <experimental/filesystem> and the std::experimental::filesystem is slated for removal, this means you should use std::filesystem.
I had the same problem and then, when I removed the experimental filesystem and added:
#include <filesystem>
namespace fs = std::filesystem;
I would get the error:
namespace “std” has no member “filesystem”
The solution was to go to project properties and do as instructed in the link.
VS2017: E0135 namespace "std" has no member "filesystem"
Adding the define where necessary worked for me:
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 1;
ie.
#ifdef __cpp_lib_filesystem
#include <filesystem>
namespace fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING 1;
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#error "no filesystem support ='("
#endif
I've been researching this same problem for weeks, and I'm using visual studio 2019 on an Unreal Engine 4 project. It's difficult to enable c++17 headers in visual studio and make them work. A lot of people online suggests using the boost library instead, but this is my attempt in using filesystem because I don't want to deal with trying to download / import external libraries, and so here's what I know...
** Before you start coding in visual studio, you should build / compile your project and see if Visual Studios needs anything set up; for me, I had to download / setup a free license with Incredibuild (there are tutorials online if someone needs to get this setup). Incredibuild is helpful and necessary to build projects in Visual Studio (at least if you're using Unreal Engine 4), but sometimes I get 1 or 2 "errors" in visual studio, but will compile in Unreal Engine 4 because those errors aren't actually errors (people say online that Incredibuild is weird, and wanted to mention that)**
1) How to enable c++17 Headers
When trying to #include which is a c++ version 17 header, it's necessary to enable c++17: Look inside the visual studio "solution explorer" to view the project files, and right-click the project itself and open "properties". Go to the "C/C++ language" tab and switch the version to c++17 (this is easy to find this online). Unless you're doing an Unreal Engine project because there is not a "C/C++ language" tab, so instead find the "NMake" tab and in the text-box to the right of "Addition Options" type in:
/std:c++17 OR /std:c++latest (Microsoft has a list I found online of others, but these are fine)
and visual studios will recognize as a header.
2) How NOT to get c++17 namespaces to work (things I've tried)
After the headers start working you can try to finally make a namespace variable:
namespace fs = std::filesystem; => ERROR: 'std does not have a namespace or class filesystem'
OR if you also #include you can try:
namespace fs = std::experimental::filesystem; OR namespace fs = std::experimental::filesystem::v1; => ERROR: 'we want you to define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING'
how does one fix these errors?
Online, I found that adding these lines of code to your ProjectName.Build.cs file (which can be found and edited after clicking on the file in "solution explorer") instead of the original declaration for PCHUsage:
PCHUsage = PCHUsageMode.NoSharedPCHs; PrivatePCHHeaderFile = "Folder.h"; CppStandard = CppStandardVersion.Cpp17;
this did get rid of the Errors when using std::filesystem BUT caused wayyyy more problems, and seemed harmful. After looking through other websites / possible solutions, it seems people online don't know how to actually use the filesystem library in visual studio, I've been looking for working code for weeks.
if you want to try and use the std::experimental::filesystem or std::experimental::filesystem::v1, I tried #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING, but no dice.
I'm in the same boat as you man, and it looks like you didn't get much help from the previous comments. If we can't find a solution / video tutorial online, I have a plan B. Maybe we could try and write a c++17 project using some different software, or maybe we could write a program using a different software that could be launched instead of enabling c++17 into Visual Studio; for example, if you wanted to list the files in a directory, make an executable file in your preferred other software, and launch that executable / feed it arguments from your visual studio project. That's the best I got man. I hope that sparks some creativity or whatever, but I think it's a lot more helpful than what I've seen online. Good luck to you! and I need that luck too

CodeLite autocomplete cannot find c++ headers

CodeLite 7.0, Windows 7, MinGW installed, autocomplete cannot find anything c++ related. I have a workspace and a project in it (just started with CodeLite).
When I try to include a c++ header (e.g. string or vector) or use those classes in my code i get no autocomplete. Compiling and running works fine, just the autocomplete does not.
Under CodeLite->Settings->Code Completion->CTags there is a list of MinGW's include folders for c++ (I checked, all headers are in those folders).
Am I missing something?
What happens when you go to :
CodeLite -> Workspace -> Retag Workspace (full) , does it change anything?
And just to make sure: you do have a workspace and project, right?
Eran
I may be way off base here, but found a similar (same?) issue.
This does NOT work:
#include <vector>
using std::vector;
vec (No autocomplete)
However, both other ways work as expected:
#include <vector>
std::vec (Yes autocomplete)
OR:
#include <vector>
using namespace std;
vec (Yes autocomplete)

Eclipse CDT project with armadillo - CDT does not recognize 'arma' namespace

I'm running on a CentOS 6.5 x64 OS and have used yum to install armadillo. I'm developing in Eclipse CDT
I've included the armadillo header in the project properties >> C/C++ Build >> Settings >> GCC C++ Compiler >> Includes >> Include files. The entry is: "/usr/include/armadillo"
The header file I am working on recognizes armadillo and the include statement isn't flagged for any errors or warnings.
Below is the code:
#include <armadillo>
using namespace std;
using namespace arma; // arma is not recognized as a symbol
const double DEGREES_PER_RADIAN = 180.0 / datum::pi; // datum is not recognized
I've checked the file /usr/include/armadillo and it does include the namespace arma section.
//! \namespace arma namespace for Armadillo classes and functions
namespace arma
{
// preliminaries
...
I've also checked the permissions and the /usr/include/armadillo file is readable to all users.
The problem is when I add the "using namespace arma", CDT marks it as an error and says that "Symbol 'arma' could not be resolved".
At this point, I don't have any other ideas to figure out why the namespace isn't recognized. Any insights or pointers to figure this out would be much appreciated.
This question's answer provided the answer to my issue:
Clean Eclipse Index, it is out of sync with code
Josh Kelley's answer from the linked issue:
Right-click on your project, go under the Index submenu, and choose either "Rebuild," "Update with modified files," or "Freshen all files."
I don't know the difference between those three options, but one of "Update with modified files" or "Freshen all files" usually fixes it for me.
Also, I'm sure you've already done this, but make sure that you're running the latest version of the Eclipse CDT. Current versions seem to have much more reliable indexing than previous versions.
After running Index >> Rebuild and Index >> Freshen All Files, the errors were gone.

How to create a VTK project in Windows Form Project (VisualC++ 2012 )

I'm trying to embed scene created with Visualization ToolKit (VTK)library into VisualC++ 2012 created windows form so I can design my Windows native GUI interface.
I'd like to underline that, all examples with console app are configured with (Cmake), compiled with VC++2012 and works flawlessly, as instructed by the official VTK wiki page.
The issue is, if I try to call those VTK functions and class initializations inside of Win Form application I get the Error LNK1107: invalid or corrupt file: cannot read at 0x2E0 D:\.....\VTK_61_BUILD_VS2012\bin\Debug\vtkViewsCore-6.1.dll even if I add everything normally as expected, include headers and external library dependencies.
This makes me think that I'm originating from wrong Visual C++ 2012 project template or something obvious that I'm completely missing, otherwise compiler would arise many not found files or syntax error.
This is the first lines where I'm trying to invoke the VTK library, even the intellisense suggest the vtk..... named proc,functions and structures, but application fails to compile.
#pragma once
#include <vtkSmartPointer.h>
#include <vtkTriangle.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkRenderWindow.h>
namespace CLR_Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
...
...
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
What is the problem here ?
The following link (in particular the answer of Mr. bnsteel) helped me very much, when I had the same problem ==>
http://vtk.1045678.n5.nabble.com/VTK-and-Winforms-integration-td5721086.html
You can use Swig as it is suggested under the link. But it is not necessary. Using the similar way (passing the windows form panel handle) you can create a C++/CLI wrapper as jalal sadeghi proposed. You will pass the panel handle through the wrapper to your C++ library that does all the "VTK work". This way you don't have to create individual wrappers for all VTK classes, all the "VTK work" and dependencies on VTK stay hidden in your C++ layer.
Something like this ==>
C++ side
setImageRenderWindowParentID(void *theID){
... (init your vtk render window)
renWin->SetParentId(theID);
}
C++/CLI side
void setRenderWindowParentID(IntPtr parentID, .. also pass the panel size .. ){
void* p = parentID.ToPointer();
myCPPVTK->setRenderWindowParentID(p, .. also pass the panel size ..);
}
C# side
VTKWrapper.setRenderWindowParentID(m_panel.Handle, .. also pass the panel size ..);

getting error for ambiguous symbol and need help to remove it

i am getting this error which i unable to remove in visual studio 2010. i am using one third party library which uses its own definition for "string" Also visual studio's xstring file is there in the folder where it gets installed. now when i am trying to compile code i am getting following error
1>...\xyz.cpp(24): error C2872: 'string' : ambiguous symbol
1> could be 'third party library path\string.h(31)
1> or 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\xstring(2063) : std::string'
compiler is not able to understand which string definition it should use. How can i remove this error in visual studi 2010. I want the code to use third party string definition.
i tried to set third party path in include directory but still i am seeing this error.
Please help me. Thanks in advance
This is an example of a namespace clash. You probably have in your code:
#include <3rdPartyString.h> // declaration of 3rd party string type
#include <string> // declaration of std::string
using namespace 3rdPartyNamespace;
using namespace std;
...
string myStr; // which string type?
Compiler now doesn't know which string you want to use - one from 3rd party library or STL one. You can resolve this ambiguity by prepending namespace name to the type:
3rdPartyNamespace::string myStr; // if you want to use string from 3rd party library
or
std::string myStr; // if you want to use STL string
Never place using namespace namespace_name; in headers but try to avoid it in source files as well. The best practice is to prepend type name as this does doesn't pollute your current namespace with the other one thus avoiding namespace clashes.
Namespaces were invented to prevent these ambiguities. Make sure you never use using namespace std (that specific using namespace is bad practice anyway, and "std::" isn't that long to type) and it should be fine, just use std::string if you want the standard string.
// Without "using namespace std;"
string foo; // string from third party library used.
std::string bar; // string from standard library used.
The two definitions of string are clashing with each other so the compiler doesn't know what to use so you need a way to differentiate the two and that's where namespaces come in.
You can use the namespace that your third party string uses when referring to that string as the errors you are showing implies you have using namespace std in your code.
I ran into this issue recently by adding a Class Library project to a very large solution that included an in-house String library, the using namespace System; in the pre-generated header was causing the ambiguity.
There is System.String. If not intended to use, make sure to indicate otherwise. Example System::String, or Custom::String