【问题标题】:Get VCPKG to include the VCPKG Include directory in the include path when building a port构建端口时获取 VCPKG 以在包含路径中包含 VCPKG 包含目录
【发布时间】:2020-02-16 04:49:43
【问题描述】:

我正在尝试为 VCPKG 创建一个新端口,即Arabica project。 vcpkg install 命令失败。第一个错误如下。

...\include\XPath/impl/xpath_namespace_context.hpp(7,10):
fatal error C1083: Cannot open include file: 'boost/shared_ptr.hpp':
No such file or directory [D:\vcpkg\buildtrees\arabica\x64-windows-dbg\mangle.vcxproj]

问题是该文件安装在 VCPKG 包含目录中。准确地说,它安装在 D:\vcpkg\installed\x64-windows\include\boost\shared_ptr.hpp。

用于编译文件的命令如下。

...\CL.exe /c /I"D:\vcpkg\buildtrees\arabica\x64-windows-dbg\include" /I"D:\vcpkg\buildtrees\arabica\src\0-February-67b234ed05\include" /Z7 /W3 /WX- /diagnostics:column /MP /Od /Ob0 /D WIN32 /D _WINDOWS /D _DEBUG /D ARABICA_DEBUG /D ARABICA_NOT_USE_PRAGMA_LINKER_OPTIONS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"xgrep.dir\Debug\\" /Fd"xgrep.dir\Debug\vc142.pdb" /Gd /TP /errorReport:queue  /utf-8 "D:\vcpkg\buildtrees\arabica\src\0-February-67b234ed05\examples\XPath\xgrep.cpp"

如果我可以让 VCPKG 添加 /I"D:\vcpkg\installed\x64-windows\include" 命令行参数,它会起作用。

我的CONTROL文件的内容如下。

Source: arabica
Version: 2020-February
Homepage: https://github.com/BenKeyFSI/arabica
Description: Arabica is an XML and HTML processing toolkit, providing SAX2, DOM, XPath, and XSLT implementations, written in Standard C++.
Build-Depends: boost-mpl, boost-type-traits, boost-spirit, boost-function, boost-bind, boost-smart-ptr, boost-lexical-cast

portfile.cmake的内容如下。

include(vcpkg_common_functions)

vcpkg_from_github(
  OUT_SOURCE_PATH SOURCE_PATH
  REPO BenKeyFSI/arabica
  REF 2020-February
  SHA512 3cf56a71c53e35eb2bc48332c96958e6800e5735a629f292f47e9b22b106f378e45abe046d6a7ed8604fe434d356efbf8744bd31fa905de6fcec62c7223f9e4c
  HEAD_REF master
)

vcpkg_configure_cmake(
  SOURCE_PATH ${SOURCE_PATH}
  PREFER_NINJA
)
vcpkg_install_cmake()
vcpkg_copy_pdbs()

file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/arabica RENAME copyright)

由于缺少 Boost 头文件,我上面提到的编译器错误和其他几个错误导致失败。如果它只在包含目录列表中包含 VCPKG 包含目录,则不会发生这些编译器错误,因为 Boost 已经安装并且 CONTROL 文件指出该库依赖于 Boost。

我需要向 vcpkg_configure_cmake 或 vcpkg_install_cmake 传递一个魔法咒语,上面写着“在包含路径中包含 VCPKG 包含目录吗?”

【问题讨论】:

  • 您是否正在为您的项目创建 vcpkg 端口文件?
  • 是的。当我构建端口时,由于缺少头文件而出现编译错误,如果 VCPKG 包含目录包含在包含路径中,则不会发生这种情况。
  • 你能在这里更新你的端口文件吗?
  • @shobhonk 我已经用该信息更新了问题。

标签: vcpkg


【解决方案1】:

如果我可以让 VCPKG 添加 /I"D:\vcpkg\installed\x64-windows\include" 命令行参数,它会起作用。

你不需要说服 vcpkg 这样做,但 cmake。因此,只需将您的 vcpkg_configure_cmake 电话替换为:

vcpkg_configure_cmake(
  SOURCE_PATH ${SOURCE_PATH}
  PREFER_NINJA
  OPTIONS -DBUILD_WITH_BOOST=ON
)

在您的 CMakeLists.txt 中实际执行 find_package 调用以进行提升。 (实际上 BUILD_WITH_BOOST 似乎不是一个选项,因为它是构建要求?!?!)。最好链接到 Boost::headers 目标,因为如果目标不可用,这会引发 CMake 错误。

然后它将构建但无法链接并出现以下错误(三元组x64-windows):

taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_ANY" (?M_ANY@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_EMPTY" (?M_EMPTY@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_PCDATA" (?M_PCDATA@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_ROOT" (?M_ROOT@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::F_RESTART" (?F_RESTART@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::F_CDATA" (?F_CDATA@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::F_NOFORCE" (?F_NOFORCE@Schema@SAX@Arabica@@2HB)
taggle.exe : fatal error LNK1120: 7 unresolved externals

因此,如果找不到内部符号,我假设您的 CMakeLists.txt 存在逻辑错误。 (构建x64-windows-static 是成功的,所以这是一个符号可见性问题)

你还需要添加

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

到你的 portfile.cmake

【讨论】:

  • 谢谢。我终于开始测试这个了。效果很好。
猜你喜欢
  • 2022-07-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 2015-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多