1

I'm new to programming. I'm currently working on a web scrapper using C++. I'm using the cpr and gumbo libraries (installed using vcpkg). Whenever I try to run my code I get the error,

scrapper.cpp:3:10: fatal error: 'cpr/cpr.h' file not found
#include "cpr/cpr.h"
         ^~~~~~~~~~~
1 error generated

I have no idea where I need to write the file path. This is the path to the file documents/GitHub/vcpkg/packages/cpr_arm64-osx/include/cpr.

So far I've tried to write the entire directory of the file in the preprocessor directive. ex) #include "documents/GitHub/vcpkg/packages/cpr_arm64-osx/include/cpr/cpr.h". I've also tried to make a c_cpp_properties.json file to write my file path there but I wasn't able to figure out what to write there.

JaMiT
  • 14,422
  • 4
  • 15
  • 31
Ryan
  • 11
  • 1
  • `c_cpp_properties.json` is for the Intellisense of the editor. It's not involved in building at all. `tasks.json` does the building unless you are using an extension like code-runner, CMakeTools or MakeFileTools. You may want to go through the official VSCode macOS tutorial to understand the 3 json files used: [https://code.visualstudio.com/docs/cpp/config-clang-mac](https://code.visualstudio.com/docs/cpp/config-clang-mac) – drescherjm Mar 28 '23 at 23:23
  • Note: Visual Studio Code is not kind to users who do not read the documentation thoroughly. – user4581301 Mar 28 '23 at 23:29
  • You copied the error message into your question, which is good. However, you copied it as one line, when it was not (or at least should not have been). Let me restore the original formatting (to my best guess), then you can take another look at it. The first line is the error. The second line is from your code; it is the line of your code that triggered the error. The third line has an arrow pointing to a specific character in the line from your code; that is the exact position where the compiler detected the error (in this case, the file name from the `#include` directive). – JaMiT Mar 29 '23 at 07:27

1 Answers1

0

#includes look in a certain number of predefined places for the files being included. If you use quotes around the file name ("stdio.h"), the preprocessor will first look in the current directory and then look in the system include paths. If you use angle brackets (<stdio.h>), it will skip immediately to the system include paths.

There are a couple ways of making the preprocessor "find" your file. Ideally you would specify that the preprocessor should search in the directory that you've already installed the library to. This can be done with environmental variables or with command line flags. The man page for your compiler should be more detailed, but generally it entails setting the variable CPATH or using the -I <directory> flag. You may also need to link the library explicitly with -l. Alternatively, though I don't recommend this method as highly, you could continue using quotes and put the .h in your current directory.

Also, you appear to be trying to build with VSCode's default build system, which can be less than friendly if you don't know how to build your projects already. You might want to try building from the command line first, and then learning how VSCode's config files build it.

Questant
  • 1
  • 2
  • By any chance could you add a bit more detail on setting the variable CPATH? Does this make sense export CPATH=/Users/ryanparhizi/Documents/packages/cpr – Ryan Mar 30 '23 at 06:35
  • Yes that makes sense, though you might want to check your path; in your original question it was in Documents/GitHub/.... It should be the path to the directory that the `.h` file is in. Also, relative paths from there work. So you can do `CPATH=C:\...\include` and then `#include .` The idea is to get CPATH + {include_path} to be the full path – Questant Mar 31 '23 at 23:05
  • If you're using gcc, [this](https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html) has more information. (cpp there refers to C PreProcessor, the program that deals with includes, not c++) – Questant Mar 31 '23 at 23:08
  • Exactly where the compiler looks for headers files (whatever the filename delimiter) is implementation-defined. See: [What is the difference between #include and #include "filename"?](https://stackoverflow.com/q/21593/10871073) – Adrian Mole Apr 01 '23 at 12:56