Skip to content
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

platform为windows的情况下默认禁用mingw的库文件 #5595

Open
heheda123123 opened this issue Sep 10, 2024 · 28 comments
Open

platform为windows的情况下默认禁用mingw的库文件 #5595

heheda123123 opened this issue Sep 10, 2024 · 28 comments

Comments

@heheda123123
Copy link
Contributor

heheda123123 commented Sep 10, 2024

你在什么场景下需要该功能?

相关讨论的链接
#5527 (comment)
#4479
#5527 (comment)

之前遇到了这个问题,但是其实是没有解决的,只是自己把PATH里面的mingw/bin去掉了

改进总结:平台指定为windows之后,即便PATH里面有pkg-config,也会默认禁用mingw的库

描述可能的解决方案

感谢 @xq114 提到的 #5527 (comment)

描述你认为的候选方案

No response

其他信息

No response

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Mingw library files are disabled by default when the platform is windows

In what scenario do you need this feature?

Related links
#5527 (comment)
#4479
#5527 (comment)

I encountered this problem before, but it was actually not solved. I just removed mingw/bin in PATH.

Improvement summary: After the platform is specified as windows, even if there is pkg-config in the PATH, the mingw library will be disabled by default.

Describe possible solutions

xq114 mentioned #5527 (comment)

Describe your alternatives

No response

Other information

No response

@star-hengxing
Copy link
Contributor

主要问题应该是“path 里面加了 pkg-config”,xmake会使用这个msys下的pkg-config

话说为啥 xmake 会去找 pkg-config,不应该和 cmake/meson 一样么。
参考 #5474 ,windows 平台应该只找 pkgconf。

@heheda123123
Copy link
Contributor Author

heheda123123 commented Sep 10, 2024

主要问题应该是“path 里面加了 pkg-config”,xmake会使用这个msys下的pkg-config

话说为啥 xmake 会去找 pkg-config,不应该和 cmake/meson 一样么。 参考 #5474 ,windows 平台应该只找 pkgconf。

2023年的issue了,现在我也没测过,当时看输出是这样的
自从有这个问题之后,就没在命令行用过g++了
#4479 (comment)

finding zlib from pkgconfig ..
checking for pkg-config ... ok
checking for zlib ... pkgconfig::zlib 1.3

虽然提示是检查pkg-config,但是找到的包是显示pkgconfig::zlib。这里命名没有统一?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The main problem should be that "pkg-config is added to the path", xmake will use this pkg-config under msys

By the way, why does xmake look for pkg-config? Shouldn’t it be the same as cmake/meson? Referring to #5474, windows platforms should only look for pkgconf.

It’s an issue in 2023. I haven’t tested it now. At that time, the output looked like this.
#4479 (comment)

@xq114
Copy link
Contributor

xq114 commented Sep 10, 2024

话说为啥 xmake 会去找 pkg-config,不应该和 cmake/meson 一样么。 参考 #5474 ,windows 平台应该只找 pkgconf。

pkg-config能找到的pkgconf也会找到,这不是关键问题,关键是找到之后判定后缀是.a还是.lib

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


By the way, why does xmake look for pkg-config? Shouldn’t it be the same as cmake/meson? Refer to #5474, windows platform should only look for pkgconf.

pkgconf that can be found by pkg-config will also be found. This is not the key issue. The key is to determine whether the suffix is ​​.a or .lib after finding it.

@xq114
Copy link
Contributor

xq114 commented Sep 10, 2024

msys2的pkg-config好像内置了PKG_CONFIG_PATH,不过msys2也能装pkgconf,不用msys2也能装pkg-config,这两的区别不是决定性的

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


msys2's pkg-config seems to have built-in PKG_CONFIG_PATH, but msys2 can also install pkgconf, and pkg-config can be installed without msys2. The difference between the two is not decisive.

@waruqi
Copy link
Member

waruqi commented Sep 10, 2024

话说为啥 xmake 会去找 pkg-config,不应该和 cmake/meson 一样么。 参考 #5474 ,windows 平台应该只找 pkgconf。

pkg-config能找到的pkgconf也会找到,这不是关键问题,关键是找到之后判定后缀是.a还是.lib

目前找到后,返回的都是 links ,并不是完整的 filename,而且他设置了 -p windows ,用的 msvc ,那么即使 pkg-config 返回了 -lz -lfoo,xmake 解析成 links (z, foo) ,然后丢给 msvc,xmake 会自动加 z.lib, foo.lib 。。msvc 的 link.exe 是不会找到 mingw 里面的 .a 库的。。

lib = lib .. ".lib"

而之前 #4479 里面反应的 msys/mingw库混用问题,不是库文件混用,是 pkg-config 返回的 includedirs 导致的混用冲突,这里面还是有区别的。所以 lib 库是没用混用问题的,仅仅需要处理 includedir 冲突问题

下面是 #4479 之前的错误描述:

尽管当前项目指定了msvc工具链,但是会去使用msys的头文件,头文件混用,产生了错误的提示。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


By the way, why does xmake look for pkg-config? Shouldn't it be the same as cmake/meson? Refer to #5474, windows platform should only look for pkgconf.

pkgconf that can be found by pkg-config will also be found. This is not the key issue. The key is to determine whether the suffix is ​​.a or .lib after finding it.

After currently finding it, all the links returned are not the complete filename, and he set -p windows and used msvc, so even if pkg-config returns -lz -lfoo, xmake parses it into links (z, foo ), and then throw it to msvc, xmake will automatically add z.lib, foo.lib. . msvc's link.exe will not find the .a library in mingw. .

lib = lib .. ".lib"

The msys/mingw library mixing problem reflected in #4479 before is not a mixing of library files, but a mixing conflict caused by includedirs returned by pkg-config. There is still a difference.

Here is the error description before #4479:

Although the current project specifies the msvc tool chain, the header files of msys will be used, and the header files are mixed, resulting in an error message.

@waruqi
Copy link
Member

waruqi commented Sep 10, 2024

目前一种方式,就是对 windows 平台,完全禁用 pkgconfig 自动找库 ..

table.insert(managers, "pkgconfig")

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The current way is to completely disable pkgconfig's automatic library search for the windows platform..

table.insert(managers, "pkgconfig")

@xq114
Copy link
Contributor

xq114 commented Sep 11, 2024

目前一种方式,就是对 windows 平台,完全禁用 pkgconfig 自动找库 ..

table.insert(managers, "pkgconfig")

这也不合适吧,pkgconfig还是有用的,检测到.a就排除也可以避免头文件混用,而且现在本来就要提取libfiles,其中顺便做个检测不好吗

@xq114
Copy link
Contributor

xq114 commented Sep 11, 2024

不过考虑到有headeronly的library,完全禁用也可以

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


One current method is to completely disable pkgconfig's automatic library search on the windows platform..

table.insert(managers, "pkgconfig")

This is not appropriate, pkgconfig is still useful. If .a is detected, excluding it can avoid the mixing of header files. Moreover, we have to extract libfiles now. Isn’t it good to do a detection by the way?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


However, considering that there is a headeronly library, it can be completely disabled.

@waruqi
Copy link
Member

waruqi commented Sep 11, 2024

目前一种方式,就是对 windows 平台,完全禁用 pkgconfig 自动找库 ..

table.insert(managers, "pkgconfig")

这也不合适吧,pkgconfig还是有用的,检测到.a就排除也可以避免头文件混用,而且现在本来就要提取libfiles,其中顺便做个检测不好吗

没懂,怎么个检测 .a 排除法

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


One current method is to completely disable pkgconfig's automatic library search for the windows platform..

table.insert(managers, "pkgconfig")

This is not appropriate, pkgconfig is still useful. If .a is detected, excluding it can avoid the mixing of header files, and now we have to extract libfiles, wouldn't it be good to do a detection by the way?

I don’t understand, how to test .a elimination method

@xq114
Copy link
Contributor

xq114 commented Sep 11, 2024

没懂,怎么个检测 .a 排除法

https://github.com/xmake-io/xmake/blob/dev/xmake/modules/package/manager/pkgconfig/find_package.lua#L88-L89 这里加个判断?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I don’t understand, how to detect .a elimination method

https://github.com/xmake-io/xmake/blob/dev/xmake/modules/package/manager/pkgconfig/find_package.lua#L88-L89 Add a judgment here?

@waruqi
Copy link
Member

waruqi commented Sep 11, 2024

没懂,怎么个检测 .a 排除法

https://github.com/xmake-io/xmake/blob/dev/xmake/modules/package/manager/pkgconfig/find_package.lua#L88-L89 这里加个判断?

windows plat 检测到 .a 就返回 nil? 那 headeronly 怎么处理呢

@waruqi
Copy link
Member

waruqi commented Sep 11, 2024

我暂时不清楚 #4479 里面的运行环境,但是根据目前的信息看,他多半应该是在加载了 msys2/mingw 的环境下,强行走 xmake f -p windows 去切的 msvc 。。导致的 msvc 和 msys2/mingw 之间的环境变量混用冲突。

本身 windows 下用 pkg-config 并没啥问题,它支持 windows ,那就应该能用。

如果是上述我猜想的环境,那么 应该还存在 PKG_CONFIG_PATH 变量,设置到了 msys2 的路径,类似这种

$ echo $PKG_CONFIG_PATH
/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig

这会导致 pkg-config 默认从 msys2 中找库。

如果这个运行环境猜测的没问题,那么应该可以通过下面的方式来解决:

  1. pkgconfig/find_package 针对 windows plat 下,直接屏蔽系统 os.getenv("PKG_CONFIG_PATH") 的配置,去找库,不再从系统库中去找,仅仅从包的 PKG_CONFIG_PATH 配置中找库。
  2. 针对 mingw 开放系统 PKG_CONFIG_PATH 下的路径查找。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I don’t understand, how to detect .a elimination method

https://github.com/xmake-io/xmake/blob/dev/xmake/modules/package/manager/pkgconfig/find_package.lua#L88-L89 Add a judgment here?

Windows plat returns nil when it detects .a? How to deal with headeronly?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I don’t know the operating environment in #4479 yet, but according to the current information, he forced xmake f -p windows to cut msvc in the environment with msys2/mingw loaded. . Caused conflict between msvc and msys2/mingw.

There is no problem in using pkg-config under windows. It supports windows, so it should work.

If it is the environment I guessed above, then there should still be a PKG_CONFIG_PATH variable set to the path of msys2, similar to this

$ echo $PKG_CONFIG_PATH
/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig

This will cause pkg-config to look for libraries from msys2 by default.

If there is no problem in guessing the running environment, then it should be solved in the following ways:

  1. For windows plat, pkgconfig/find_package directly blocks the system os.getenv("PKG_CONFIG_PATH") configuration and searches for the library. Instead of searching from the system library, it only searches for the library from the PKG_CONFIG_PATH configuration of the package.
  2. Search for the path under PKG_CONFIG_PATH of the mingw open system.

@xq114
Copy link
Contributor

xq114 commented Sep 11, 2024

  1. pkgconfig/find_package 针对 windows plat 下,直接屏蔽系统 os.getenv("PKG_CONFIG_PATH") 的配置,去找库,不再从系统库中去找,仅仅从包的 PKG_CONFIG_PATH 配置中找库。
  2. 针对 mingw 开放系统 PKG_CONFIG_PATH 下的路径查找。

包的 PKG_CONFIG_PATH 是指xmake安装的包吗?那就无意义了,不如直接禁用pkgconfig。

table.insert(managers, "pkgconfig")
在这里改的话我理解还是可以显式写 pkgconfig::xxx 来查找pkgconfig的包,这样处理就可以,windows不加pkgconfig::前缀就不找pkgconfig

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


  1. For windows plat, pkgconfig/find_package directly blocks the system os.getenv("PKG_CONFIG_PATH") configuration and searches for the library. Instead of searching from the system library, it only searches for the library from the PKG_CONFIG_PATH configuration of the package.
  2. Search for the path under PKG_CONFIG_PATH of the mingw open system.

Does the PKG_CONFIG_PATH of the package refer to the package installed by xmake? That's meaningless. It's better to disable pkgconfig directly.

table.insert(managers, "pkgconfig")
If you change it here, I understand that you can still explicitly write pkgconfig::xxx to find pkgconfig. Package, you can do it this way. Windows will not find pkgconfig without adding the pkgconfig:: prefix.

@waruqi
Copy link
Member

waruqi commented Sep 11, 2024

  1. pkgconfig/find_package 针对 windows plat 下,直接屏蔽系统 os.getenv("PKG_CONFIG_PATH") 的配置,去找库,不再从系统库中去找,仅仅从包的 PKG_CONFIG_PATH 配置中找库。
  2. 针对 mingw 开放系统 PKG_CONFIG_PATH 下的路径查找。

包的 PKG_CONFIG_PATH 是指xmake安装的包吗?那就无意义了,不如直接禁用pkgconfig。

table.insert(managers, "pkgconfig")

在这里改的话我理解还是可以显式写 pkgconfig::xxx 来查找pkgconfig的包,这样处理就可以,windows不加pkgconfig::前缀就不找pkgconfig

在这里改,就是 windows 下,完全去掉 pkgconfig 的查找

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


  1. For windows plat, pkgconfig/find_package directly blocks the system os.getenv("PKG_CONFIG_PATH") configuration and searches for the library. Instead of searching from the system library, it only searches for the library from the PKG_CONFIG_PATH configuration of the package.
  2. Search for the path under PKG_CONFIG_PATH of the mingw open system.

Does the PKG_CONFIG_PATH of the package refer to the package installed by xmake? That's meaningless. It's better to disable pkgconfig directly.

table.insert(managers, "pkgconfig")

If you change it here, I understand that you can still explicitly write pkgconfig::xxx to find the pkgconfig package, so it can be processed. Windows will not find pkgconfig without adding the pkgconfig:: prefix.

The change here is to completely remove the search for pkgconfig under windows.

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

No branches or pull requests

5 participants