【发布时间】:2014-11-20 07:50:21
【问题描述】:
我想在我的项目中使用优化算法 lbfgs,但我不想自己编写代码。所以我发现Dlib 是一个不错的选择。
http://dlib.net/compile.html 是一个很好的库。我下载了它。我使用的是 windows 7 和 visual studio 2012。如果我创建一个新的 win 32 控制台项目并将 property->configuration properties->VC++ Directories->Include Directories 设置为 Dlib(dlib-18.10/) 的路径。
它运行良好,这意味着我可以运行示例。
但是当我将它添加到我的项目中时。我出现错误。(error : "vector" is ambiguous)
我猜可能是因为我包含它的方式。
在Dlib的文件上写着,
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.
但我不清楚上面的意思。我用谷歌搜索了the Visual Studio search path (Tools / Options / Projects and Solutions / VC++ Directories).。但在我的项目中,这是不可编辑的。
我只在 dlib 中使用 optimization.h。如果我删除'using namespace dlib;',然后'typedef matrix column_vector;'则错误是matrix is not a template。如果我继续“使用命名空间 dlib;”我有错误“向量”不明确`。
#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;
【问题讨论】:
-
你不应该指向所有标题所在的目录,而是向上一步。然后,您将包含标题作为#include
. -
@HalilKaskavalci,感谢您的评论。我不确定我将使用的标题。我使用来自 c++ 的向量。正如你所提到的,在 Dlib 本身中有文件 vector.h。但是我应该添加#include
,因为我使用来自 C++ 标准的 vector吗? -
好的,我现在明白你的问题了。第一件事是,只要你想包含来自 std 的内容,你只需包含
#include <vector.h>。假设您想要位于几何图形下的 dlib 向量。那么你应该包括#include <dlib/geometry/vector.h>。每当你想使用它们时,你都应该指定命名空间,因为这也会让编译器感到困惑。如果您的程序中同时使用了 std 和 dlib 命名空间,则无论何时使用它们都应该说std::vector或dlib::vector。希望有帮助! -
@HalilKaskavalci,谢谢。这有帮助。我希望这至少可以工作。但它是手动的。
-
我也发布了答案。享受编码!
标签: c++ visual-studio-2012 dlib