Search code examples
pythonc++c++11jsoncpppybind11

Using JsonCpp to return data to python with pybind11 produces Symbol not found error in python call


I am attempting to use JsonCpp in order to parse some data before returning it to python (using pybind11).

I have managed to get the make file cooperating with recognizing JsonCpp and compiling, but have been unable so far to get rid of the following error when calling the method in python:

ImportError: dlopen(/PATH/REDACTED/project.cpython-36m-darwin.so, 2): Symbol not found: __ZN4Json5ValueC1ENS_9ValueTypeE

Expected in: flat namespace Referenced from: /PATH/REDACTED/project.cpython-36m-darwin.so

It appears to have an issue with anything from the JsonCpp library.

#include <pybind11/pybind11.h>
#include <pybind11/embed.h>
#include <json/json.h>
void callhome(pybind11::object site, std::string user_name)
{
    pybind11::object page = site.attr("Pages").attr("__getitem__")("User:" + user_name + "/status");
    std::string text = string(py::str(page.attr("text")()));
    Json::Value root;
   /* Json::Reader reader;
    bool parsingSuccessful = reader.parse( text, root );
    if ( !parsingSuccessful )
    {
        cout << "Error parsing the string" << endl;
    }

    const Json::Value mynames = root["run"];

    for ( int index = 0; index < mynames.size(); ++index )
    {
       // py::print()
        cout << mynames[index] << endl;
    }*/
}
PYBIND11_MODULE(music_infobox, m) {
    m.def("callhome",&callhome);
}

Python calling:

import mwclient,music_infobox,mwparserfromhell;
if __name__ == '__main__':
    site = mwclient.Site(('https', 'en.wikipedia.org'), '/w/');
    page = site.Pages['La Más Completa Colección (Marco Antonio Solís album)']
    text = page.text()
    music_infobox.save_edit(page,site,False,text,"DeprecatedFixerBot")

cmake:

cmake_minimum_required(VERSION 2.8.12)
project(music_infobox)

add_subdirectory(pybind11)
add_subdirectory(json)

#target_link_libraries(LibsModule -L/usr/local/Cellar/jsoncpp/1.8.4/include/json)
pybind11_add_module(music_infobox src/example.cpp src/example.h src/example.cpp src/utilities.h src/utilities.cpp)

Any ideas would be greatly appreciated!


Solution

  • You need to link against the JsonCpp library when you build the pybind11 module.

    The error comes because this symbols should be in the library, but it cannot find it because of the missing link.