Vivian
Vivian

Reputation: 217

Use dlib in Visual studio 2012

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/).

enter image description here

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;

Upvotes: 1

Views: 3553

Answers (2)

Andriy Gerasika
Andriy Gerasika

Reputation: 118

using namespace std;
using namespace dlib;
#define vector std::vector

use w/ caution

Upvotes: 0

Halil
Halil

Reputation: 2173

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.

Upvotes: 1

Related Questions