1

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?

diniamo
  • 49
  • 3
  • 1
    You can't compile a library on linux and then use it on windows. Generally you shouldn't even use different compiler versions on the same system. – super Sep 07 '21 at 16:26
  • Well, since I couldn't compile it on Windows, I had to do it on Linux. But as far as I know, .a/.lib files are cross-platform. – diniamo Sep 07 '21 at 16:29
  • 2
    They are not. Maybe [this](https://github.com/google/gumbo-parser/issues/380) can help. – super Sep 07 '21 at 16:35
  • ***But as far as I know, .a/.lib files are cross-platform.*** No that is very wrong. They are not even cross compiler on the same platform in many cases. With that said on linux you can use mingw to create mingw compatible binaries. – drescherjm Sep 07 '21 at 16:36
  • Well, I'm trying to use `gumbo-query` though. So that issue might not be that helpful. Also, I am using MinGW if that's relatable. – diniamo Sep 07 '21 at 17:24
  • 1
    If you install msys2 and use that to obtain your mingw gumbo-parser is a package in the msys2 repository: [https://packages.msys2.org/package/mingw-w64-x86_64-gumbo-parser?repo=mingw64](https://packages.msys2.org/package/mingw-w64-x86_64-gumbo-parser?repo=mingw64) installable by `pacman -S mingw-w64-x86_64-gumbo-parser` from the msys2 shell. also https://www.msys2.org/ – drescherjm Sep 07 '21 at 17:26
  • Okay, thanks. But the development itself is done on Windows. – diniamo Sep 07 '21 at 19:00
  • The MSYS solution is actually an interesting one. I personally avoid using MSYS as it's just a hassle to use. But it is a viable solution that should not be overlooked. – JMS Creator Sep 09 '21 at 04:12

1 Answers1

2

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:

@echo off
cls

REM     Build Script

REM Set Compiler Settings Here


set GCC=gcc
set AR=ar
set OUTPUT=libgumbo_parser.a
set DEBUGMODE=0

set REBUILD_LIBRARIES=0

set LINK_ONLY=0
set VERBOSE=0

set ASYNC_BUILD=1

set C_COMPILER_FLAGS=-std=c99 -Wall
set ADDITIONAL_LIBRARIES=
set ADDITIONAL_LIBDIRS=
set ADDITIONAL_INCLUDEDIRS=-I.


del %OUTPUT% 2>nul

setlocal enabledelayedexpansion


if %LINK_ONLY% GTR 0 (
    goto linker
)

if %DEBUGMODE% GTR 0 (
    set DEBUG_INFO=-g
) else (
    set DEBUG_INFO=
)

if %ASYNC_BUILD% GTR 0 (
    set WAIT=
) else (
    set WAIT=/WAIT
)

if %REBUILD_LIBRARIES% GTR 0 (
    del /S /Q "*.o" 2>nul
)

echo Building C Libraries...
for %%F in (*.c) do (
    if not exist %%~nF.o (
        echo Building %%~nF.o
        start /B %WAIT% "%%~nF.o" %GCC% %ADDITIONAL_INCLUDEDIRS% %C_COMPILER_FLAGS% %DEBUG_INFO% -c %%F -o %%~nF.o

        if %VERBOSE% GTR 0 (
            echo %GCC% %ADDITIONAL_INCLUDEDIRS% %C_COMPILER_FLAGS% %DEBUG_INFO% -c %%F -o %%~nF.o
        )
    )
)

REM Wait for building process to finish
:loop
set /a count=0
for /f %%G in ('tasklist ^| find /c "%GCC%"') do ( set /A count=%count%+%%G )
if %count%==0 (
    goto linker
) else (
    timeout /t 2 /nobreak>nul
    goto loop
)

:linker

set "files="
for /f "delims=" %%A in ('dir /b /a-d "*.o" ') do set "files=!files! %%A"

:link
echo Linking Executable...

if %VERBOSE% GTR 0 (
    echo %AR% ru %OUTPUT% %files%
)

%AR% ru %OUTPUT% %files%

:finish
if exist .\%OUTPUT% (
    echo Build Success!
) else (
    echo Build Failed!
)

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.

set GCC=E:\Programs\Qt\Tools\mingw810_64\bin\gcc
set AR=E:\Programs\Qt\Tools\mingw810_64\bin\ar

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.

CMake Gui Setup 1

CMake Gui Setup 2

Step 4: Generate and run CMake.

CMake should be located in your MinGW bin folder cd to your gumbo-query/build directory. Then, run mingw32-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 Library gumbo-query\lib\libgq.a Gumbo Query DLL Import Library gumbo-query\lib\libgq.dll.a Gumbo Parser Static Library gumbo-parser\src\libgumbo_parser.a Gumbo Parser Header Files gumbo-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.

diniamo
  • 49
  • 3