-
Notifications
You must be signed in to change notification settings - Fork 979
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
[bug] Error when detecting CPython version when included via CMake #16952
Comments
Hi @wawanbreton Thanks very much for your report. |
Related:
Adding |
Hi @wawanbreton The reason it is failing is because being a shared-library, it is not found in the runtime paths. Then it means that the runtime information is needed also at build time (the build-time information contains the runtime paths of the This can be modeled in different ways with Conan, for example: from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.env import VirtualRunEnv
class Pkt(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps"
requires = "cpython/3.12.2"
def configure(self):
self.options["cpython"].shared = True
def layout(self):
cmake_layout(self)
def generate(self):
VirtualRunEnv(self).generate(scope="build")
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build() It can be forced with Please try that and let us know if this makes sense. |
Hi, and thank you very much for you answers. Sorry for the delay in answering, I have been a bit sick. So, setting On the other hand, I am probably not the only one who will run into this issue, in this case I don't have a very exotic setup. But maybe other people can find this discussion, and then the solution for it ? I also see that the Thanks again for you help ! |
Thanks for the feedback! yes, lets leave it open, at least some improvements to the docs could be made. The thing is that "runtime" shared dependencies for "build time" are intrinsically complex, they don't have a great solution, and Conan can in fact do even more than some build systems can do by themselves. Still, it is very common for tools used at build-time to be statically linked to avoid these problems. But yes, at least some docs can be added to explain this, thanks again! |
Just chiming in - I'm glad that sanity check code I added actually caught something :) |
Interestingly, I was trying this in Windows and in Windows it seems to work. if self.options.env_vars:
bindir = os.path.join(self.package_folder, "bin")
self.runenv_info.append_path("PATH", bindir)
self.buildenv_info.append_path("PATH", bindir) Which is Windows location for shared libs, but it doesn't contain the equivalent for Linux LD_LIBRARY_PATH |
Which means that if I add: diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py
index c98c3381c1..d7eb719bd9 100644
--- a/recipes/cpython/all/conanfile.py
+++ b/recipes/cpython/all/conanfile.py
@@ -889,6 +889,9 @@ class CPythonConan(ConanFile):
bindir = os.path.join(self.package_folder, "bin")
self.runenv_info.append_path("PATH", bindir)
self.buildenv_info.append_path("PATH", bindir)
+ if self.options.shared: # So the find_package(Python) works
+ self.buildenv_info.append_path("LD_LIBRARY_PATH", os.path.join(self.package_folder, "lib"))
+ self.buildenv_info.append_path("DYLD_LIBRARY_PATH", os.path.join(self.package_folder, "lib")) to the Thanks for your feedback! |
I am reviewing the recipe, I have a quick question, for @wawanbreton, but also @Ahajha What is the main use you want to do of the python conan package? You want to embed it as a library into your application, or do you want to use Python as a tool in your build process? From what I see the recipe doesn't look intended to link Python as a library, because it doesn't contain |
@memsharded It does have |
In our case, it is even trickier 😃 we have an application that is made of a few sub-projects. Some of them are C++ libraries, one is a C++ executable that runs in background, but our main front-end is a pure Python app. Thus we also have bindings to call the C++ libraries from the front-end. The bindings use Python as a shared library, but our main project embeds the actual Python interpreter, built by Conan. |
Describe the bug
Hi,
I'm trying to consume the
cpython/3.12.2
package for my project, which is Python binding.My
conanfile.py
contains the following:And also the classic CMake generator/build
Now my CMakeLists.txt contains:
Building CPython 2.12.2 works like a charm, and the
FindPython.cmake
file and associated are properly generated. But when I run myconan build .
, I get the following error:Apparently, when trying to detect the Python version, it finds Python 3.12.3 which is the one installed on my system. I indeed have the following:
I can then use the LD_LIBRARY_PATH trick to start the build, and this time the detection works properly. But this really sound like a dirty hack 😃
Do you think this is something about my environment, or is there indeed a bug somewhere ? In this case, I can try to provide a fix, but I don't know what part of the process is faulty.
How to reproduce it
The provided bug description should allow to reproduce it. Otherwise, I can make a minimal projet.
The text was updated successfully, but these errors were encountered: