Note that there are some explanatory texts on larger screens.

plurals
  1. POWrapping C++ using ctypes: undefined symbol
    primarykey
    data
    text
    <p>I am experimenting with wrapping C++ in order to use C++ functions in Python. Currently I am trying out ctypes and unfortunately, I have not yet been successful. For starters I have written a Hello World program in C++ and I am trying to call it from Python using ctypes. This is what I have done:</p> <pre><code>path_to_dir $ vim helloworld.cpp 1: #include &lt;iostream&gt; 2: 3: using namespace std; 4: 5: int main() 6: { 7: cout &lt;&lt; "Hello, world!" &lt;&lt; endl; 8: return 0; 9: } path_to_dir $ gcc -shared -Wl,-soname,hello_module -o hello_module.so -fPIC helloworld.cpp path_to_dir $ vim helloworld.py 1: import ctypes 2: 3: libc = ctypes.cdll.LoadLibrary("path_to_dir/hello_module.so") 4: 5: libc.main() path_to_dir $ python helloworld.py Traceback (most recent call last): File "helloworld.py", line 3, in &lt;module&gt; libc = ctypes.cdll.LoadLibrary("/home/carlos/Workspace/Freestyle/Wrapping_C++/ctypes/hello_module.so") File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary return self._dlltype(name) File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__ self._handle = _dlopen(self._name, mode) OSError: /home/carlos/Workspace/Freestyle/Wrapping_C++/ctypes/hello_module.so: undefined symbol: _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_ </code></pre> <p>The traceback mentions something about an undefined symbol however I do not know why I get this error and how to solve it. I also tried standard C++ libraries instead of writing one like this on my own. That worked out fine. Can someone help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload