0

I have a custom .sublime-build file in Sublime Text 3 (ST3), where I have included folder that I want it to search for a c++ header file:

{
"cmd": ["g++", "$file_name", "-o", "${file_base_name}.exe", "-I C:/package/armadillo74002/include", "-L C:/package/armadillo74002/examples/lib_win64", "-lblas_win64_MT", "-llapack_win64_MT", "&&", "start", "cmd", "/c" , "$file_base_name"],
"selector": "source.c",
"working_dir": "${file_path}",
"shell": true
}

However, when I run the script:

#include <armadillo>

I get the following error:

headerex.cpp:2:21: fatal error: armadillo: No such file or directory

but I can check My Computer and see that the file exists in that directory. Why is it giving me this error? What can I change so that it can find the header file I am looking for?

MattDMo
  • 100,794
  • 21
  • 241
  • 231
AaronJPung
  • 1,105
  • 1
  • 19
  • 35
  • IIRC `C:package` searches from the current working directory of C, not the root. – Captain Obvlious Sep 12 '16 at 17:03
  • @CaptainObvlious -- sorry, that was a mistake when I was typing the question. I've edited my question to reflect that my .sublime-build file is actually `C:/package/...`, rather than the `C:package/...` indicated in my question. I am still getting that error. – AaronJPung Sep 12 '16 at 17:10
  • I don't know a huge amount about C++, but what if you change `#include ` to `#include "armadillo.h"` (with or without the `.h`)? It's my understanding that includes in `< >` angle brackets are for files in the standard lib, while those in `" "` double quotes are in other include directories passed by the `-I` option. – MattDMo Sep 12 '16 at 18:07
  • @MattDMo -- Thank you so much for your help! While this does not answer my question above verbatim, it was the fix I was looking for. The .sublime-build was looking in the proper location, but for some reason I needed to use `" "` instead of `< >`. Making this change has allowed me to successfully call `armadillo`. If you'd like to add this as a solution, I'll accept it as the solution I was looking for, adding a comment why. – AaronJPung Sep 13 '16 at 19:58

1 Answers1

1

I'm not familiar with all of the terminology, as my experience coding in C/C++ is somewhat limited, but it is my understanding that there are two types of #includes. The first type, where the header file name is enclosed in angle brackets < > (#include <stdio.h>, #include <string.h>, etc.), means you are including a header from the standard library.

The second type, where the included file is surrounded by double quotes " " (#include "Python.h", #include "myheader.h", etc.), is for including any other header whose location is specified in the Makefile or on the command line with the -I option (at least for gcc). Subdirectories can also be shown - for example, if you pass the -I/usr/local/include/mylib/include option, your include statement might be #include "x86_64/myheader.h" if there are subdirectories in the original directory.

See What is the difference between #include <filename> and #include "filename"? for a better explanation.

Since armadillo doesn't sound like it's part of the standard lib, and you're passing its location on the command line, it might be a good idea to replace the angle brackets with double quotes and see if that does the trick.

Community
  • 1
  • 1
MattDMo
  • 100,794
  • 21
  • 241
  • 231