0

I created a new project in Visual Studio 2015 that consists of just one C++ file "test.cpp" that uses Eigen. I installed Eigen in the "C:\eigen" directory. When I tried to build the solution from within Visual Studio it failed because it couldn't find the Eigen header files, even though I added the "C:\eigen" directory to the include directories of the project. This was the error I got:

Cannot open include file: 'Eigen/Dense': No such file or directory  

However when I opened the "Developer Command Prompt for VS2015", went to the directory containing the "test.cpp" file, and ran the command:

cl test.cpp -I "C:\eigen"

it succeeded. Why would the compilation fail from within Visual Studio but succeed from the command line?

Here is how I added the Eigen library to my Visual Studio Include Directories:

enter image description here

Thomas
  • 1,103
  • 3
  • 13
  • 25
  • 2
    Always post any errors you get *verbatim*, *in* the question. – Jesper Juhl Jan 01 '18 at 16:26
  • ***even though I added the "C:\eigen" directory to the include directories of the project.*** Maybe you did not add it correctly or you did not add it to all configurations. – drescherjm Jan 01 '18 at 16:58
  • I updated my question with the error I was getting, and a screenshot of my VS project properties showing how I added the include directory. – Thomas Jan 01 '18 at 17:23
  • Sounds like the installation of Eigen (which I'm not familiar with) may depend on some things in your environment that aren't there. I bet rebooting your PC would solve the problem (or simply restarting VS). Have you tried this? – Steve Jan 01 '18 at 17:42
  • I tried rebooting and it didn't help. Eigen is just a collection of header files, so it doesn't need to be installed really. – Thomas Jan 01 '18 at 17:49
  • There's a [difference between `-I` and `Include Directories`](https://stackoverflow.com/a/6883392/3426025) have you tried the `Additional Include Directories` under C++/General? And please add the erroneous build output to your question. – BeyelerStudios Jan 01 '18 at 21:43
  • I tried adding "C:\eigen" to `Additional Include Directories` and it still fails to compile in VS. The error I mentioned in the question is the compile error I get. – Thomas Jan 01 '18 at 22:51
  • The only way you'll get to the bottom of your issue is to understand the build output. [Cranking up the verbosity](https://blogs.msdn.microsoft.com/msbuild/2005/09/28/cranking-up-the-build-verbosity-in-the-ide/) should help with that. – BeyelerStudios Jan 02 '18 at 00:00
  • By turning on the detailed build log I was able to see that the `C:\eigen` directory was not being added to the `INCLUDE` environment variable at all, and figured out it was because the configuration and build platforms were different. – Thomas Jan 03 '18 at 02:41

1 Answers1

1

The problem was that I configured the project for the x64 platform, but was building for the x86 platform. After I made the change to build for the x64 platform the build succeeded.

Thomas
  • 1,103
  • 3
  • 13
  • 25