'Cmake link libmapnik c++

I am unable to connect Mapnik via cmake to my application.

I tried to do like this:

cmake_minimum_required(VERSION 3.1)

project(MapnikTest)

set(MAPNIK_LIB "/usr/local/lib/libmapnik.so.3.1.0") dont work

#set(MAPNIK_LIB "/usr/local/lib/libmapnik.so") dont work

set(MAPNIK_INCLUDE_DIR "/usr/local/include/mapnik")  work

#find_package(mapnik REQUIRED) dont work

#find_package(Mapnik REQUIRED) dont work

include_directories(${MAPNIK_INCLUDE_DIR})

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE ${MAPNIK_LIB})

The thing is, I don't have mapnikConfig.cmake in /usr/local/bin/cmake

Can't connect the library directly. Include he sees. I edited already LD_LIBRARY_PATH it didn't help either.

/usr/bin/ld: CMakeFiles/MapnikTest.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x3b): undefined reference to `mapnik::Map::Map(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: main.cpp:(.text+0xb8): undefined reference to `mapnik::load_map(mapnik::Map&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: main.cpp:(.text+0x1b9): undefined reference to `void mapnik::save_to_file<mapnik::image<mapnik::rgba8_t> >(mapnik::image<mapnik::rgba8_t> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: CMakeFiles/MapnikTest.dir/main.cpp.o: in function `icu_66::UnicodeString::hashCode() const':
main.cpp:(.text._ZNK6icu_6613UnicodeString8hashCodeEv[_ZNK6icu_6613UnicodeString8hashCodeEv]+0x18): undefined reference to `icu_66::UnicodeString::doHashCode() const'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/MapnikTest.dir/build.make:104: MapnikTest] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/MapnikTest.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

enter image description here

(dont work mean this) enter image description here



Solution 1:[1]

Find where you have mapnikConfig.cmake or mapnik-config.cmake and set mapnik_DIR to it. Like this:

cmake -Dmapnik_DIR="/path/to/config" ..

and it should be

find_package(mapnik REQUIRED)

Solution 2:[2]

Edit
When I inspect github more carefully it turn out that cmake config was introduced recently, after last release. So my answer will become valid for next release of this library.

You can inspect this change to see how import that library.

Original (valid after next release 3.2):
Based on demo form Mapnik repo it should go like this:

cmake_minimum_required(VERSION 3.1)

project(MapnikTest)
find_package(mapnik REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE mapnik::agg mapnik::mapnik)

Didn't test it, but should work. I can see library provides proper config.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ixSci
Solution 2