I didn't find any proper tutorials on installing this library. The closest I got was:
- Build
gumbo-parser
using the instructions in the readme (Linux) - Build
gumbo-query
using the instructions in the readme (Linux) - Copy the lib folder to my windows machine
- Add these lines to my CMake file:
set(CMAKE_PREFIX_PATH "E:/Programs/gumbo-query")
include_directories("E:/Programs/gumbo-query/src")
set(LIBS ${LIBS} "E:/Programs/gumbo-query/src/lib")
But the problem is that when I try to include Document.h, it says gumbo.h: no such file or directory
.
How would I solve this issue? Am I approaching this completely the wrong way?
So I have managed to solve my issue with a help of another fellow in a Discord server, and I'm going to post the solution here to make the life of people in the future easier.
This guide is for Windows, and it was made mostly because there aren't any resources on how to build this stuff on Windows.
Step 1:
Clone both repositories to their default state. (gumbo-parser for C, gumbo-query for C++)
Important!
Make sure that both repositories are located in the same directory, as this tutorial assumes that the repositories' names are not changed and that they are located together in the same directory.
E.g. the following directory is a plausible location for each repository to reside.
C:\C++\gumbo_parser
C:\C++\gumbo_query
Step 2:
Copy this build script into the
gumbo-parser\src
directory:You'll need to make sure you're C compiler (MinGW)
bin
directory is configured in your PATH environment; otherwise, configure the build script and set AR and GCC to the exact path where gcc is located.E.g.
You will also want to run this script in a Windows CMD window, with elevated rights. It didn't work for me otherwise.
This will create a static library of gumbo parser.
Step 3:
Configure CMake for gumbo query.
Primarily, make sure the following variables are set when configuring gumbo_query:
Gumbo_INCLUDE_DIR
<path-to-gumbo-parser>/src
Gumbo_LIBRARY
<path-to-gumbo-parser>/src/libgumbo_parser.a
Gumbo_static_LIBRARY
This should already be set, but just in case make sure your C and C++ compilers are set correctly:
CMAKE_C_COMPILER
<path-to-mingw>\bin\gcc.exe
CMAKE_CXX_COMPILER
<path-to-mingw>\bin\g++.exe
CMAKE_CXX_COMPILER_AR
<path-to-mingw>\bin\gcc-ar.exe
As well as the CMake program (you have to tick advanced for this): CMAKE_MAKE_RPOGRAM
<path-to-mingw>\bin\mingw32-make.exe
Make sure you're configuring the correct directory. Set the build location to the build folder located in gumbo-query.
Step 4: Generate and run CMake.
CMake should be located in your MinGW bin folder
cd
to yourgumbo-query/build
directory. Then, runmingw32-make
to build the target libraries. Once completed, you'll have both a dynamic and static library of gumbo query.Where to find your build files and helpful directories:
Gumbo Query DLL
gumbo-query\build\src\libgq.dll
Gumbo Query Static Librarygumbo-query\lib\libgq.a
Gumbo Query DLL Import Librarygumbo-query\lib\libgq.dll.a
Gumbo Parser Static Librarygumbo-parser\src\libgumbo_parser.a
Gumbo Parser Header Filesgumbo-parser\src
Step 5 (Optional): running example
To compile the example application found in gumbo-query, cd into the example directory and run the following commands:
g++ -c main.cpp -I..\src -I..\..\gumbo-parser\src
g++ -o test.exe main.o -L..\lib -L..\..\gumbo-parser\src -static -lgq -lgumbo_parser
Run:
./test
to test the final application.