1

I installed mapnik 4.0.0 from source using cmake. Now Im trying to run C++ default example:

#define _GLIBCXX_USE_CXX11_ABI 0

#include <mapnik/map.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/image.hpp>
#include <mapnik/image_util.hpp>

int main()
{
    mapnik::Map m(256,256);
    mapnik::load_map(m, "/usr/share/renderd/example-map/mapnik.xml");
    m.zoom_all();
    mapnik::image_rgba8 im(256,256);
    mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
    ren.apply();
    mapnik::save_to_file(im, "the_image.png");
    return 0;
}

with this line:

g++ map-renderer.cpp -o a.out -L/usr/local/lib -lmapnik

But I keep getting those errors:

g++ map-renderer.cpp -o a.out -L/usr/local/lib -lmapnik
/usr/bin/ld: /tmp/ccKF0om7.o: warning: relocation against `_ZN6mapnik22MAPNIK_GEOGRAPHIC_PROJE' in read-only section `.text'
/usr/bin/ld: /tmp/ccKF0om7.o: in function `main':
map-renderer.cpp:(.text+0x29): undefined reference to `mapnik::MAPNIK_GEOGRAPHIC_PROJ'
/usr/bin/ld: map-renderer.cpp:(.text+0x3e): undefined reference to `mapnik::Map::Map(int, int, std::string const&)'
/usr/bin/ld: map-renderer.cpp:(.text+0xc1): undefined reference to `mapnik::load_map(mapnik::Map&, std::string const&, bool, std::string)'
/usr/bin/ld: map-renderer.cpp:(.text+0x1cd): undefined reference to `void mapnik::save_to_file<mapnik::image<mapnik::rgba8_t> >(mapnik::image<mapnik::rgba8_t> const&, std::string const&)'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

What could be the reason for those errors? I tried building with CMake, tried running default bootstrap.sh script but the error keeps appearing.

Looks like with order of libraries included everything should be okay.

p.s. Mapnik source: https://github.com/mapnik/mapnik

syat-cd
  • 11
  • 3
  • try to move -lmapnik before it's used (the order matters) – KIIV Aug 30 '23 at 12:11
  • @KIIV The order matters, but it must be *after* files that use it. – Yksisarvinen Aug 30 '23 at 12:12
  • isnt this the same question asked here https://stackoverflow.com/questions/77000966/cannot-properly-link-mapnik-with-cmake ? – 463035818_is_not_an_ai Aug 30 '23 at 12:15
  • There is no mapnik 4.0.0 tho? Latest version is 3.1.0. And according to [release notes](https://github.com/mapnik/mapnik/releases/tag/v3.1.0), you shouldn't use `_GLIBCXX_USE_CXX11_ABI 0`, because this version requires C++14. What is your `g++ --version`? – Yksisarvinen Aug 30 '23 at 12:26
  • 463035818_is_not_an_ai, no it's not. The errors are different – syat-cd Aug 30 '23 at 12:32
  • Yksisarvinen, i suppose they just didn't released new versions. I actually made it built with default bootstrap.sh script, run "mapnik-config -v" and it showed me 4.0.0. g++ version is 11.4.0. I used "_GLIBCXX_USE_CXX11_ABI 0" because of another error which appeared if i wouldn't use that line – syat-cd Aug 30 '23 at 12:36
  • 2
    The missing symbols all involve `std::string`... Instead of turning off the CXX11 ABI you should make sure that all components (both yours and mapnik) are compiled with the same compiler and same compiler settings. – Botje Aug 30 '23 at 13:04
  • 1
    *"I used "_GLIBCXX_USE_CXX11_ABI 0" because of another error which appeared if i wouldn't use that line"* - this proves that this question is actually a typical [XY problem](https://en.wikipedia.org/wiki/XY_problem). You should ask about your original issue instead. – user7860670 Aug 30 '23 at 15:41

0 Answers0