undefined symbol: MD5_Final > Error on Ubuntu with Anaconda while a compiling a python extension

0

This is my hasher.c , source of python/c extension for my program

#include <stdio.h>
#include <openssl/md5.h>
#include <Python.h>


static PyObject* gethash(PyObject* self , PyObject* args)
{
    // char inputfile;
    char *filename;

    if (!PyArg_ParseTuple(args, "s", &filename))
        return NULL;

    unsigned char c[MD5_DIGEST_LENGTH];

    int i;
    FILE *inFile = fopen (filename, "rb");
    MD5_CTX mdContext;
    int bytes;
    unsigned char data[1024];

    if (inFile == NULL) {
        printf ("%s can't be opened.\n", filename);
        return 0;
    }

    MD5_Init (&mdContext);
    while ((bytes = fread (data, 1, 1024, inFile)) != 0)
        MD5_Update (&mdContext, data, bytes);
    MD5_Final (c,&mdContext);
    for(i = 0; i < MD5_DIGEST_LENGTH; i++) printf("%02x", c[i]);
    printf (" %s\n", filename);
    fclose (inFile);
    return 0;    

}

static PyMethodDef HelloMethods[] = {
    {"gethash", gethash, METH_VARARGS, "Greet somebody (in C)."},
    {NULL, NULL, 0, NULL}  /* Sentinel */
};

static struct PyModuleDef HelloDemo =
{
    PyModuleDef_HEAD_INIT,
    "hellomodule", /* name of module */
    "",          /* module documentation, may be NULL */
    -1,          /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
    HelloMethods
};

PyMODINIT_FUNC PyInit_hasher(void)
{
    return PyModule_Create(&HelloDemo);
}

and this is my setup.py to build this extension:

from distutils.core import setup, Extension

module = Extension("hasher" , sources = ["hasher.c"] , extra_compile_args=["-lssl -lcrypto"])

setup(name = "hellomod",
        version = '1.0',
        description = "hello",
        ext_modules = [module])

but when i test my extension with this code it gave me error mentioned bellow

testing code

import hasher
hasher.gethash("hasher.c")

when i run i got this>

$ py test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import hasher
ImportError: /home/palash/Desktop/pal/hasher.cpython-36m-i386-linux-gnu.so: undefined symbol: MD5_Final

i'm running on ubuntu 17.04 , with anaconda , conda 4.4.4 and gcc version 7.0.1

Help Me..

*Edit

output of,

$ nm -S hasher.cpython-36m-i386-linux-gnu.so | grep MD5

is

U MD5_Final
U MD5_Init
U MD5_Update

Edit*

output of

$ ldd hasher.cpython-36m-i386-linux-gnu.so

is

linux-gate.so.1 =>  (0xb7723000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb76df000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7525000)
/lib/ld-linux.so.2 (0x8008d000)
python
c
anaconda
md5
pyopenssl
asked on Stack Overflow Dec 27, 2017 by Palash Bauri • edited Dec 29, 2017 by Palash Bauri

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0