'Undefined Symbol in C++ Using Python
I have seen all the posts about undefined symbols when loading a c++ module from python. What I haven't really seen is undefined symbol once loaded and used.
Here is the python:
import ctypes
libname = "/path/to/library/libtest.so"
c_lib = ctypes.CDLL(libname)
print(c_lib.check("str"))
Here is the C++:
test.h
#include <string>
bool check(const std::string& str);
static std::string mode;
test.cc
bool check(const std::string& str) {
return mode == str;
}
I am using bazel 5.0 on Ubuntu 18.04.
I assume this could be recreated using raw gcc but I am not too familiar with it.
I also tried Export C++ function to python using ctypes: undefined symbol by putting everything in an extern C and ended up with my environment variables being undefined symbols while loading. Updated example accordingly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
