Skip to content

/usr/bin/ld: cannot find -lpythonxx #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Hydaspex opened this issue Feb 15, 2019 · 4 comments
Open

/usr/bin/ld: cannot find -lpythonxx #90

Hydaspex opened this issue Feb 15, 2019 · 4 comments

Comments

@Hydaspex
Copy link

I have tried to compile an example to no avail on Ubuntu with Python 3.7 (Anaconda) running in a VM on Win10.

Code
g++ modern.cpp -I/usr/include/python3.7 -lpython3.7 --std=c++11 -v

I am not able to get rid of the following error
/usr/bin/ld: cannot find -lpython3.7 collect2: error: ld returned 1 exit status

Any support would be greatly appreciated.

Below I have pasted two excerpts from -verbose log (but I cannot see anything wrong except for the error message).

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/7" ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/include/python3.7 /usr/include/c++/7 /usr/include/x86_64-linux-gnu/c++/7 /usr/include/c++/7/backward /usr/lib/gcc/x86_64-linux-gnu/7/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list.
COLLECT_GCC_OPTIONS='-I' '/usr/include/python3.7' '-std=c++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' as -v -I /usr/include/python3.7 --64 -o /tmp/ccfipdIM.o /tmp/cctxAOiD.s GNU assembler version 2.30 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.30 COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-I' '/usr/include/python3.7' '-std=c++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-linux-gnu/7/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/7/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper -plugin-opt=-fresolution=/tmp/cco1QpeW.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/7/../../.. /tmp/ccfipdIM.o -lpython3.7 -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: cannot find -lpython3.7
collect2: error: ld returned 1 exit status

``

@dist1ll
Copy link

dist1ll commented Feb 19, 2019

Yep, same error. I'm super confused, because I have the binaries in /usr/bin/ld. I don't understand why gcc can't find it.

@lava
Copy link
Owner

lava commented Mar 12, 2019

The last time I built against python3, I had to use -lpython3.7m as linker flag. This was on Ubuntu 18.04, maybe your distribution has the same setup.

@FanchenBao
Copy link

FanchenBao commented Apr 20, 2019

On my system (MacOS, python3.6 installed via Homebrew), even if I use -lpython3.6m as linker flag, it still gives me error ld: library not found for -lpython3.6m. The final solution is to use the --cflags and --ldflags provided in python3-config, and the cpp file compiles.

g++ minimal.cpp -std=c++11 $(python3-config --cflags) $(python3-config --ldflags)

In addition, if at runtime there is error loading matplotlib.pyplot, follow the instruction in #8

@jpan127
Copy link

jpan127 commented Jun 20, 2019

Thank you @FanchenBao that works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants