FindPython3 does not find libraries in virtual environment
Trying to compile program and link it with python 374 libraries on OS Linux Mint 19.1 Tessa Mate, cmake 3.15.
Required libraries are:
libpython3.7m.a -lcrypt -lpthread -ldl -lutil = python lib + dependent libs
find_package(Python3 COMPONENTS Interpreter Development) in virtual python environment is partially buggy. Results are (see below). Maybe using sysconfig is more appropriate, especially if development files are on different location as virtual directory. Virtual environment does not copy or link c-libraries and headers to virtual place. One way to find them is to ask python+sysconfig.
Furthermore static linking requires secondary dependent libraries of libpython_xxx.a.
python -m sysconfig gives:
- LIBS = "-lcrypt -lpthread -ldl -lutil" - secondary dependent libraries
- LIBRARY = "libpython3.7m.a"
- LIBDIR = "/opt/python/python-3.7.4/lib"
- INCLUDEPY = "/opt/python/python-3.7.4/include/python3.7m"
- include = "/opt/python/python-3.7.4/include/python3.7m"
- scripts = "/opt/venv/py374/bin"
It seems to me that sysconfig should be more preferable for virtual environment, it correctly return executable in virtual path and development directories in static installation place. It is consistent with philosophy get executable and ask it where is its development environment.
I didn't check if find_package(Python) is working outside virtual environment and if secondary libraries are considered there. I also didn't check how sysconfig is reliable for other Python implementations and how is solved if both static and dynamic libraries are available.
Result of find_package(Python3 COMPONENTS Interpreter Development)