wlav / cppyy

Other
384 stars 38 forks source link

Initialization of an std::string fails in version 3.0.0 #196

Closed felixfeliz closed 7 months ago

felixfeliz commented 8 months ago

I installed version 3.0.0 of cppyy in a virtual environment using pip. When I initialize an std::string, I get an error related to a missing definition of std::basic_string. More precisely, if I run

import cppyy
cppyy.cppexec(r"""std::string hello = "Hello, World!";""")
cppyy.cppexec("std::cout << hello << std::endl;")

the code fails with

[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZN11__cling_N505helloB5cxx11E, _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, __orc_init_func.cling-module-140, __clang_call_terminate, __cxx_global_var_initcling_module_140_, _GLOBAL__sub_I_cling_module_140, _ZN11__cling_N5015__cling_Un1Qu30EPv, $.cling-module-140.__inits.0 }) }
Traceback (most recent call last):
  File "/home/username/Programs/testcppyy/test.py", line 3, in <module>
    cppyy.cppexec(r"""std::string hello = "Hello, World!";""")
  File "/home/username/Programs/testcppyy/testcppyy/lib/python3.11/site-packages/cppyy/__init__.py", line 224, in cppexec
    raise SyntaxError('Failed to parse the given C++ code%s' % err.err)
SyntaxError: Failed to parse the given C++ code
IncrementalExecutor::executeFunction: symbol '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE17_M_use_local_dataEv' unresolved while linking [cling interface function]!
You are probably missing the definition of std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_use_local_data()
Maybe you need to load the corresponding shared library?

However, if I change the code to

import cppyy
cppyy.cppexec(r"""std::string hello; hello = "Hello, World!";""")
cppyy.cppexec("std::cout << hello << std::endl;")

separating the instantiation and initialization of the string, it works as expected.

I also compiled the current version from source and I got the same problem. When I use version 2.4.2 of cppyy both codes work as expected.

I am running Gentoo Linux with gcc 12.3.1 and Python 3.11.5.

wlav commented 8 months ago

This is https://github.com/wlav/cppyy/issues/175 . I don't think it's related to std::string per se, but interesting finding that that initialization v.s. assignment makes a difference.

I still need to try the docker recipe provided in the other issue. Hopefully that allows me to reproduce it.

felixfeliz commented 8 months ago

I see, sorry for the duplicate issue. It does seem to be the same problem. Let me know if there is anything I can test or help with.

wlav commented 7 months ago

Should all be good now with release 3.1.0. Feel free to reopen if you find otherwise.