+ 1

Include C++ Libary in VSCode on Windows

I am writing a CLI program in C++. Using VSCode and mingw64 for the development environment. I use g++-9 (Linux) or g++ (Windows) to build the binaries. My setup is a little different because I need to code from 2 different laptops. Laptop 1 is connected to the internet at home, and I have VS Code setup to connect to a Linux VPS over ssh. So if I build the code on that laptop, it builds under Linux. Laptop 2 is typically offline when I code on it, so I installed the C++ dev files (STL and compilers) locally on this laptop under Windows. When I build on this laptop it builds the program to a windows binary. I use github to host the code between the 2 laptops. When I'm finished working on a laptop, I commit and push the changes to github. Before I continue coding on the other laptop, I pull the changes and carry on developing. Everything has been working well, but now I want to include a library that will let me read data from a PDF file. The suggested library to use is Poppler. I figured I should download the latest Poppler archive, extract it, move its contents to an include/ folder that is inside my project folder. This way, I have the needed poppler files under both dev environments (Linux and Windows) and the poppler files will be included in the github repo. I checked my VSCode configuration and altered c_cpp_properties.json file to add the poppler folder to the include path (in fact, since I located the poppler files inside my workspace folder, it should already be able to see them without changing anything afaik?) When I try to #include poppler-document.h VSCode can't find it. it can see the base poppler folder which is in my project's include folder (the base folder is named poppler-24.05.0/) but it doesn't see the sub folders in there. It CAN see the files in poppler-24.05.0/ Inside poppler-24.05.0/ is a cpp/ folder, and in that folder are the .h and .cpp files you would expect to #include in your project.

1st Jun 2024, 10:50 AM
Nathan Stanley
Nathan Stanley - avatar
6 Answers
+ 1
Well, I am very familiar with your issue and the problem is easy to solve 1. Ensure that mingw is rightly configured. Open the cmd of your computer and type gcc -v or gcc -version. If there is an error or no output, you will have to re-install mingw 2. Ensure that cmake is properly installed in your computer. Open the cmd and type "cmake .", If there is an error output, you have to re-install cmake and add it to path 3. Ensure that the Cmake extension is properly installed in VSCode. 4. Ensure that your "CMakeLists.txt" does not have a programming error. This implies that you have a successful build. Otherwise, you will need to add your CMakeLists.txt info in this discussion. 5. Read about how to add the Popper library to cmake from their official documentation
2nd Jun 2024, 5:42 AM
RuntimeTerror
RuntimeTerror - avatar
+ 1
this is so complicated I'm not sure if i understood everything. It seems like you have an issue with visual studio not able to locate some files that located outsite the root folder of the project? In visual studio there is a setting: additional include directories or something similar. You can add there the path of that folder, so when compiler searching for the files you including, it will search i to that folder too
1st Jun 2024, 11:13 AM
john ds
john ds - avatar
0
Are you using cmake?
1st Jun 2024, 8:48 PM
RuntimeTerror
RuntimeTerror - avatar
0
Yes I am trying to include 3rd party library files (poppler). I have even added them into my project's folder like: myProject/include/poppler and I have configured the includePath as VSCode requests by doing: Ctrl + Shift + P -> C/C++: Edit Configurations (UI) -> Select Windows under the Configuration Name, as I have a Linux and Windows configuration, then scroll down to section titled "Include path" and set it to be: ${workspaceFolder}/** to make it recurse into sub folders in the project workspace folder. I place the poppler files in: myProject/include/poppler but I get the following errors from vscode: On Startup of VS Code: "Configure failed. Would you like to attempt to configure with the CMake Debugger? Source: CMake Tools" and if I try to #include a 3rd part library header file vscode tells me: "#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\path\to\flip-cpp\src\main.cpp).C/C++(1696)" If I press Ctrl + . to do the Quick fix option, it takes me to the Include path that I have already configured. Am I adding the include path correctly?
2nd Jun 2024, 5:00 AM
Nathan Stanley
Nathan Stanley - avatar
0
@White Shadow Thanks for the reply. 1. gcc checks out as working 2. cmake checks out as working 3. I am pretty sure the CMake extensions are installed in VSCode. I have "CMake" and "CMake Tools" extensions installed, which I'm pretty sure were auto installed by the C/C++ Extension Pack Addon. 4. I am not familiar with CMakeLists.txt files. There are a number of them included with the poppler source files. Would one of these suffice or is some editing of one of them probably required? My guess is the one in the poppler/cpp/ folder. 5. I will check that out
2nd Jun 2024, 6:57 AM
Nathan Stanley
Nathan Stanley - avatar
0
RuntimeTerror was onto it. It took me a while to work it all out but I wrote a gist document about what I learned. It's a bit lengthy. You can read it here if you want: https://gist.github.com/Cabji/2f28681b78a6e6a5cb03c130da5a0e2e My problems were more about not understanding what you need to have established "under the hood" to start developing with C++. To summarize it: Install the C++ STL using MSYS2. Install and use CMake. Configure VSCode to use CMake.
22nd Jul 2024, 5:58 AM
Nathan Stanley
Nathan Stanley - avatar