jupyter-xeus / xeus-cling

Jupyter kernel for the C++ programming language
BSD 3-Clause "New" or "Revised" License
3.08k stars 297 forks source link

xcpp::xdisplay fails with linking error #526

Open hoorayphyer opened 3 months ago

hoorayphyer commented 3 months ago

I have the following code

#pragma cling add_library_path("/myhome/mambaforge/envs/cling/lib")
#pragma cling load("libxeus")
#pragma cling load("libxeus-cling")

#include <xcpp/xdisplay.hpp>

int a = 1;

xcpp::display(a)

which throws the following error (basically linker can't find xeus::xinterpreter::display_data.)

IncrementalExecutor::executeFunction: symbol '_ZN4xeus12xinterpreter12display_dataEN8nlohmann16json_abi_v3_11_310basic_jsonISt3mapSt6vectorNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEblmdSaNS2_14adl_serializerES5_IhSaIhEEvEESFSF' unresolved while linking [cling interface function]! You are probably missing the definition of xeus::xinterpreter::display_data(nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator >, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator >, void>, nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator >, void>) Maybe you need to load the corresponding shared library? Interpreter Error:

I've created a virtual env cling and installed xeus-cling via mamba install xeus-cling -c conda-forge as instructed and verified that xeus is also installed. I also verified that libxeus.so existed under the lib.

I first tried without the three pragmas, then with, but either way I got the same error. In case it's relevant, I ran jupyter notebook without browser on a remote server, and did an ssh tunnel so as to open it locally where I encountered the above error.

Any help in this is much appreciated!

daviddwlee84 commented 2 months ago

I found that we should make sure the nlohmann json is exactly nlohmann_json=3.11.2, the latest version (3.11.3) won't work.

mamba install -y -c conda-forge nlohmann_json=3.11.2