I'm trying to implement an algorithm in the form of the C programming language into my system that runs using the python programming language. I'm trying to implement the Python C API with the intention that my algorithm will run in a python environment. As a result it produces an error which I have been trying to fix for several days but still can't find it. Here is the result of the error I got:
$ pip install .
Processing c:\users\angga danar\documents\skripsi\project\gimli
Preparing metadata (setup.py) ... done
Installing collected packages: gimlihash
DEPRECATION: gimlihash is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for gimlihash ... error
error: subprocess-exited-with-error
× Running setup.py install for gimlihash did not run successfully.
│ exit code: 1
╰─> [17 lines of output]
running install
C:\python3.10\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_ext
building 'gimli' extension
creating build
creating build\temp.win-amd64-cpython-310
creating build\temp.win-amd64-cpython-310\Release
creating build\temp.win-amd64-cpython-310\Release\Hash
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\python3.10\include -IC:\python3.10\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /TcHash/hashing.c /Fobuild\temp.win-amd64-cpython-310\Release\Hash/hashing.obj
hashing.c
creating C:\Users\Angga Danar\Documents\skripsi\Project\Gimli\build\lib.win-amd64-cpython-310
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\python3.10\libs /LIBPATH:C:\python3.10 /LIBPATH:C:\python3.10\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22621.0\\um\x64" /EXPORT:PyInit_gimli build\temp.win-amd64-cpython-310\Release\Hash/hashing.obj /OUT:build\lib.win-amd64-cpython-310\gimli.cp310-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-310\Release\Hash\gimli.cp310-win_amd64.lib
LINK : error LNK2001: unresolved external symbol PyInit_gimli
build\temp.win-amd64-cpython-310\Release\Hash\gimli.cp310-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> gimlihash
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Here is the code for my hashing.c file:
char print_tex(char* string, char* hex_string) {
uint8_t output[32];
size_t l = strlen(string);
Gimli_hash(string, strlen(string), output, 32);
int i;
for (i = 0;i < 32;++i)
fprintf( stderr, "%02x",output[i]);
hex_string[i] = (char)output[i];
return 0;
}
static PyObject* hash(PyObject *self, PyObject *args) {
char *str;
char final[32];
if (!PyArg_ParseTuple(args, "s", &str)){
return NULL;
}
print_tex(str, final);
return PyUnicode_FromString(final);
}
static PyMethodDef hashMethods[] = {
{"gimli", hash, METH_VARARGS, "Gimli Algorithm Hash"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef hashModule = {
PyModuleDef_HEAD_INIT,
"hashModule",
"hash module",
-1,
hashMethods
};
PyMODINIT_FUNC PyInit_hash(void) {
return PyModule_Create(&hashModule);
}
Basically I implemented a hashing algorithm where the input is in the form of a string and the resulting output is also in the form of the result string of the algorithm. I tried to install the file using the following setup.py file using the pip install .
command
from setuptools import setup, Extension
setup(name = "gimlihash",
version = "0.1",
ext_modules = [Extension("gimli", ["Hash/hashing.c"])])
Hopefully I can create a local library for my project and I can call the library. Please help because I'm still a beginner.
PyMODINIT_FUNC PyInit_gimLi(void) { ... }
instead ofPyInit_hash
might work as well. – Disrespectful