Why can't I use C++ Eigen (header only lib) in two console apps within the same MS VS solution?

时间:2018-09-18 20:20:29

标签: c++ visual-studio eigen project-settings header-only

I made a Microsoft visual solution with two console app projects. I can use the Eigen library in one project by simply declaring it in the properties like so:

$(ProjectDir)Eigen\eigen3;

I can use library structures like "Eigen::Vector3d" etc no problem. Now when I try to copy the header-only lib into the second project folder and try to set the same property for the second one, and use the the structure I get compile errors.

Then when I don't copy the Eigen folder into the second one and simply try to refer from the second the folder in the first I get another set of compile time errors.

$(SolutionDir)someproject1\Eigen\eigen3;

Errors in second case is like so:

c:\users\alam syed\documents\someproject2.h(11): error C2653: 'Eigen': is not a class or namespace name

c:\users\alam syed\documents\someproject2.h(11): error C2065: 'Vector3f': undeclared identifier

c:\users\alam syed\documents\someproject2.h(11): error C2923: 'std::vector': 'Vector3f' is not a valid template type argument for parameter '_Ty'

c:\users\alam syed\documents\someproject2.h(11): error C2903: 'allocator': symbol is neither a class template nor a function template

c:\users\alam syed\documents\someproject2.h(11): error C3203: 'allocator': unspecialized class template can't be used as a template argument for template parameter '_Alloc', expected a real type

Why is it not ok to have two projects in the same solution trying to independently have their own libs in thier project folders ? Further why can't I refer Eigen folder from one to the first one ? Finally how can we bypass this quirk/by-design issue ?

1 个答案:

答案 0 :(得分:1)

我刚刚测试了这一点,有可能在一种解决方案中。

  • 创建空解决方案
  • 添加了两个控制台项目
  • 从zip复制本征头到两个项目中的每一个
  • 在第一个项目文件夹中将它们重命名为eigen1,在第二个项目文件夹中将其重命名为eigen2
  • 使用本征文档中的教程代码在每个项目中创建了两个.cpp文件
  • 在第一个项目中将($ProjectDir)eigen1设置为“其他包含目录”,然后 ($ProjectDir)eigen2在第二个项目中
  • 检查构建的调试二进制文件中是否引用了正确的特征标头 嵌入式调试信息

即使您不重命名特征文件夹,这甚至也可以使用。

我只能想到两个原因,而不是使用common 目录方式:

  • 每个项目都使用不同版本的库,或者您想拥有 以后可以灵活使用此选项
  • 您要使用本征(和/或其他库)的自定义版本 自己的补丁
相关问题