I have to use https://github.com/google/gumbo-parser library that is written in C.
I have a HtmlParser class which is defined in HtmlParser.h and I implement it's methods in HtmlParser.cpp
I include gumbo.h in HtmlParser.h and call it's functions in implemented by me getLinks(...) function that is in HtmlParser.cpp
When I try to compile it I get undefined reference to 'gumbo_parse' How can I fix it?
My makefile is
cmake_minimum_required(VERSION 3.3)
project(WebCrawler)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp HtmlParser.cpp HtmlParser.h)
add_executable(WebCrawler ${SOURCE_FILES})
The
undefined referenceis an error at link time. It means the symbol (function) that you're using and for which the definition was found when compiling the compilation unit cannot be resolved at link time to link against.If you build in only one command, you probably just need to add a
-lgumboto your command line, eventually with-L<path to directory containing libgumbo.so>if it's not in the default lib path. Typically:or if gumbo lib and headers are in gumbo subdirectories:
If you build in multiple command lines (first building objects, then linking them, then you need to add the
-l(and eventually-L) options to the link command:Edit: With
cmake(that I now see you're using), you must tell that you're using gumbo library. This should be done using find_library:If not supported you may need to use
link_directoriesto specify where to find it. Then usetarget_link_librariesto specify to link with this library for your target.