首页 > 编程问答 >Vcpkg + cmake + pybind 问题“无法找到平台独立库 <前缀>”

Vcpkg + cmake + pybind 问题“无法找到平台独立库 <前缀>”

时间:2024-07-28 05:19:11浏览次数:11  
标签:python cmake pybind11 vcpkg

我发现了 vcpkg erlier,它看起来很有趣,但是易于使用。

据我了解,经过一天的调查,vcpkg pybind11 与 vcpkg python 搭配使用。但是当我启动一个简单的程序时,它被中止并出现以下输出 无法找到平台独立库<前缀>

这是一个已知问题,但不适用于vcpkg python。我不知道为什么?不可能设置 vcpkg python 的路径。

我很高兴有任何想法或见解。

谢谢


我明白了。看来在尝试将 vcpkg cmake pybind11 一起使用以创建 Python 绑定时遇到了问题。具体来说,看到错误消息“无法找到平台独立库<前缀>”,这表明的 Python 解释器找不到的 pybind11 模块。

This is a common issue, and it often arises from how vcpkg manages libraries and how cmake needs to be configured to find them. Here's a breakdown of what's likely happening and how to resolve it:

Understanding the Problem

  • vcpkg's Installation Directory: vcpkg typically installs libraries in a specific directory structure within its own installation folder. This structure is designed for isolation but means your system's default library search paths might not include it.
  • cmake's Need for Guidance: cmake needs explicit instructions on where to find libraries and include files. If you've installed pybind11 and Python through vcpkg , you need to tell cmake to look for them within vcpkg's directories.

Solution: Configuring cmake with vcpkg

The most reliable way to fix this is by integrating vcpkg with your cmake project:

  1. vcpkg Integration:

  2. Use vcpkg.cmake : The recommended approach is to use the vcpkg.cmake helper script. Add these lines to your CMakeLists.txt :

    ```cmake # Specify the vcpkg toolchain file set(CMAKE_TOOLCHAIN_FILE " /scripts/buildsystems/vcpkg.cmake") # Specify the triplet (if you are using a specific one) set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "")

    # Find the package find_package(pybind11 REQUIRED)

    # ... rest of your CMakeLists.txt ... `` * Replace with the actual path to your vcpkg installation. * Adjust x64-windows` if you are using a different triplet.

  3. Link Your Target:

cmake # Assuming you have a library or executable target named 'my_project' target_link_libraries(my_project PRIVATE pybind11::embed)

Additional Tips

  • Clean Build: After making changes to your CMakeLists.txt , it's always a good idea to do a clean build: bash rm -rf build # Or your build directory mkdir build cd build cmake .. cmake --build .

  • Environment Variables (Less Reliable): While you can temporarily set environment variables like PATH and PYTHONPATH to include vcpkg directories, this is less maintainable in the long run. Using vcpkg.cmake is strongly recommended.

By following these steps, you ensure that cmake knows where to find your vcpkg -managed pybind11 and Python installations, resolving the "Could NOT find platform independent libraries " error.

标签:python,cmake,pybind11,vcpkg
From: 78802471

相关文章

  • Python 中的“样板”代码?
    Google有一个Python教程,他们将样板代码描述为“不幸的”,并提供了以下示例:#!/usr/bin/python#importmodulesusedhere--sysisaverystandardoneimportsys#Gatherourcodeinamain()functiondefmain():print'Hellothere',sys.argv[1]#Command......
  • Python 3.9.1 中的 collections.abc.Callable 是否有 bug?
    Python3.9包含PEP585并弃用typing模块中的许多类型,转而支持collections.abc中的类型,现在它们支持__class_getitem__例如Callable就是这种情况。对我来说,typing.Callable和collections.abc.Ca......
  • 列表子类的 Python 类型
    我希望能够定义列表子类的内容必须是什么。该类如下所示。classA(list):def__init__(self):list.__init__(self)我想包含键入内容,以便发生以下情况。importtypingclassA(list:typing.List[str]):#Maybesomethinglikethisdef__init__(self):......
  • Python 中类型友好的委托
    考虑以下代码示例defsum(a:int,b:int):returna+bdefwrap(*args,**kwargs):#delegatetosumreturnsum(*args,**kwargs)该代码运行良好,只是类型提示丢失了。在Python中使用*args,**kwargs来实现​​委托模式是很常见的。如果有一种方法可......
  • 使用 python 支持构建自定义 vim 二进制文件
    背景Debian11vim软件包不包含python3支持。请参阅标题为“Debian11vim中不支持python-证据”的部分下面我需要vim支持python3YouCompleteMevim插件为了构建一个新的,我将vim9.0tarball下载到v......
  • 如何在Python 3.12+中正确使用泛型来提高代码质量?
    我正在尝试使用泛型来改进FastAPI应用程序中的类型注释。我有一个抽象存储库类,在其中使用泛型:fromabcimportABC,abstractmethodfromtypingimportListclassAbstractRepository[T](ABC):@abstractmethodasyncdefadd_one(self,data:dict)->T:......
  • python中的while循环不退出
    我试图完成第一年的python商业课程作业,但我的while循环无法退出,有人能帮忙吗?commisionTable=[{"admin_fee":100,"comm_rate":0.10},{"admin_fee":125,"comm_rate":0.12},{"admin_fee":150,"comm_rate":......
  • python---json文件写入
    ​ 使用到的知识点:os模块执行linux指令、json.dump()、withopenasf代码实现importsysimportosimportjson #向json文件file中添加内容data,其中data的类型为字典defwrite_json(file,data):    #如果文件存在,则删除    if(os.path.exists(fi......
  • python错题记录:布尔运算与逻辑值检测
    一前言环境:python3.10win10二布尔运算与逻辑值检测1案例案例1如上,在布尔运算时,有些时候代码只会运算前面的一部分,剩下的部分根本不会运算。以前在练习算法代码时,就利用这个规则来减少代码的工作量案例2如上,之前好长一段时间,上面的布尔运算总是让我感到困惑布尔运......
  • python---字典遍历
    1、三种常见的字典遍历实现defget_key_value(dics):  '''遍历所有键值对'''  forkey,valueindics.items():    print(f"{key}:{value}")defget_keys(dics):  '''遍历所有的键'''  forkeyindics......