I have been recently experimenting with Python embedding, but I stumbled across some problems.

#include <python3.1/Python.h>

int main (void) {
    Py_Initialize ();
    PyRun_SimpleString("print (\"Hello World\")");

    Py_Finalize ();
    return 0;
}

As you see it is not the most complicated code :). I have compiled in Code::Blocks using g++. I have linked libpython3.1.a, but i get some errors about the content of the library:

/usr/lib/libpython3.1.a(dynload_shlib.o)||In function `_PyImport_GetDynLoadFunc':|
(.text.unlikely+0x11d)||undefined reference to `dlsym'|
/usr/lib/libpython3.1.a(dynload_shlib.o)||In function `_PyImport_GetDynLoadFunc':|
(.text.unlikely+0x199)||undefined reference to `dlopen'|
/usr/lib/libpython3.1.a(dynload_shlib.o)||In function `_PyImport_GetDynLoadFunc':|
(.text.unlikely+0x1a2)||undefined reference to `dlerror'|
/usr/lib/libpython3.1.a(dynload_shlib.o)||In function `_PyImport_GetDynLoadFunc':|
(.text.unlikely+0x1f4)||undefined reference to `dlsym'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVPnew':|
(.text+0x4b)||undefined reference to `EVP_MD_CTX_copy'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVPnew':|
(.text+0xa4)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `locked_EVP_MD_CTX_copy':|
(.text+0x20f)||undefined reference to `EVP_MD_CTX_copy'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_hexdigest':|
(.text+0x29b)||undefined reference to `EVP_MD_CTX_md'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_hexdigest':|
(.text+0x2a3)||undefined reference to `EVP_MD_size'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_hexdigest':|
(.text+0x2b9)||undefined reference to `EVP_DigestFinal'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_hexdigest':|
(.text+0x2c1)||undefined reference to `EVP_MD_CTX_cleanup'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_digest':|
(.text+0x388)||undefined reference to `EVP_MD_CTX_md'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_digest':|
(.text+0x390)||undefined reference to `EVP_MD_size'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_digest':|
(.text+0x3a6)||undefined reference to `EVP_DigestFinal'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_digest':|
(.text+0x3bc)||undefined reference to `EVP_MD_CTX_cleanup'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_dealloc':|
(.text+0x3f8)||undefined reference to `EVP_MD_CTX_cleanup'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0xa)||undefined reference to `OpenSSL_add_all_digests'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x63)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x7d)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x8e)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0xab)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0xc5)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0xd7)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0xf4)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x10e)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x120)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x13d)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x157)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x168)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x185)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x19f)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x1b1)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x1ce)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x1e8)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `PyInit__hashlib':|
(.text.unlikely+0x1fa)||undefined reference to `EVP_DigestInit'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_new':|
(.text.unlikely+0x8b3)||undefined reference to `EVP_get_digestbyname'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_get_block_size':|
(.text.unlikely+0x900)||undefined reference to `EVP_MD_CTX_md'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_get_block_size':|
(.text.unlikely+0x908)||undefined reference to `EVP_MD_block_size'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_get_digest_size':|
(.text.unlikely+0x925)||undefined reference to `EVP_MD_CTX_md'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_get_digest_size':|
(.text.unlikely+0x92d)||undefined reference to `EVP_MD_size'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_hash':|
(.text.hot+0x19)||undefined reference to `EVP_DigestUpdate'|
/usr/lib/libpython3.1.a(_hashopenssl.o)||In function `EVP_update':|
(.text.hot+0xc8)||undefined reference to `EVP_DigestUpdate'|
/usr/lib/libpython3.1.a(_ctypes.o)||In function `PyCFuncPtr_new':|
(.text+0x19e0)||undefined reference to `dlsym'|
/usr/lib/libpython3.1.a(_ctypes.o)||In function `PyCFuncPtr_new':|
(.text+0x1ae7)||undefined reference to `dlerror'|
/usr/lib/libpython3.1.a(_ctypes.o)||In function `CDataType_in_dll':|
(.text.unlikely+0x1057)||undefined reference to `dlsym'|
/usr/lib/libpython3.1.a(_ctypes.o)||In function `CDataType_in_dll':|
(.text.unlikely+0x1060)||undefined reference to `dlerror'|
/usr/lib/libpython3.1.a(callbacks.o)||In function `_ctypes_alloc_callback':|
(.text+0x197)||undefined reference to `ffi_prep_cif'|
/usr/lib/libpython3.1.a(callbacks.o)||In function `_ctypes_alloc_callback':|
(.text+0x1b9)||undefined reference to `ffi_prep_closure'|
/usr/lib/libpython3.1.a(callproc.o)||In function `_ctypes_callproc':|
(.text+0x5ac)||undefined reference to `ffi_prep_cif'|
/usr/lib/libpython3.1.a(callproc.o)||In function `_ctypes_callproc':|
(.text+0x600)||undefined reference to `ffi_call'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|

If someone can tell what am I doing wrong... :S

I apologise, I forgot to link the .so :))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.