I have a C script that calls Python, and I've gotten most of it to work properly. However, when I try to run the compiled file, I get the following error:
~/Documents/code/test: error while loading shared libraries: libpython3.9.so.1.0: cannot open shared object file: No such file or directory
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-cdpcz1c5.vwd" 1>"/tmp/Microsoft-MIEngine-Out-j5b1thxt.2vz"
I am writing this in VS Code and my tasks.json
file is:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-I${workspaceFolder}",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I${HOME}/anaconda3/envs/metagenomics/include",
"-I${HOME}/anaconda3/envs/metagenomics/include/python3.9",
"-I${HOME}/anaconda3/envs/metagenomics/lib/python3.9/site-packages/numpy/core/include/numpy",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L${HOME}/anaconda3/envs/metagenomics/lib",
"-L${HOME}/anaconda3/envs/metagenomics/lib/python3.9",
"-L${HOME}/anaconda3/envs/metagenomics/lib/python3.9/config-3.9-x86_64-linux-gnu",
"-lpython3.9",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
And the build command is:
Starting build...
/usr/bin/gcc -fdiagnostics-color=always -I${HOME}/Documents/code -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I${HOME}/anaconda3/envs/myenv/include -I${HOME}/anaconda3/envs/myenv/include/python3.9 -I${HOME}/anaconda3/envs/myenv/lib/python3.9/site-packages/numpy/core/include/numpy -g ${HOME}/Documents/code/test.c -o ${HOME}/Documents/code/test -L${HOME}/anaconda3/envs/myenv/lib -L${HOME}/anaconda3/envs/myenv/lib/python3.9 -L${HOME}/anaconda3/envs/myenv/lib/python3.9/config-3.9-x86_64-linux-gnu -lpython3.9
Build finished successfully.
I've looked at this answer, but it doesn't really help with my question. I am using Anaconda as an environment manager, which shouldn't matter, but I'm not really sure. As shown, I'm including the library "${HOME}/anaconda3/envs/myenv/lib" and there is a "libpython3.9.so.1.0" file within this directory. When I use the command: find ~/anaconda3/envs/myenv/ -name libpython3.9.so.*
, I get this result:
~/anaconda3/envs/myenv/lib/libpython3.9.so.1.0
So, anyhow, I'm not sure why the compiled program is not recognizing this file. Could it be a permissions problem? The permissions for that file are: -rwxrwxr-x
.