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

python.library crumbles include directories #5130

Closed
naquad opened this issue May 22, 2024 · 6 comments
Closed

python.library crumbles include directories #5130

naquad opened this issue May 22, 2024 · 6 comments
Labels

Comments

@naquad
Copy link

naquad commented May 22, 2024

Xmake Version

2.9.1

Operating System Version and Architecture

Linux new-nq 6.8.7-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Wed, 17 Apr 2024 15:20:00 +0000 x86_64 GNU/Linux

Describe Bug

python.library rules fail to build library.

Expected Behavior

Expected to build a library

Project Configuration

Took an example configuration from docs.

add_rules("mode.release", "mode.debug")
add_requires("pybind11")

target("example")
     add_rules("python.library")
     add_files("src/*.cpp")
     add_packages("pybind11")
     set_languages("c++11")

Additional Information and Error Logs

[ 50%]: cache compiling.release src/main.cpp
/usr/bin/gcc -c -m64 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++11 -isystem /usr/lib/pkgconfig/../../include -isystem /usr/include/python3.11 -DNDEBUG -o build/.objs/example/linux/x86_64/release/src/main.cpp.o src/main.cpp
error: In file included from /usr/include/c++/14.1.1/ext/string_conversions.h:43,
                 from /usr/include/c++/14.1.1/bits/basic_string.h:4154,
                 from /usr/include/c++/14.1.1/string:54,
                 from /usr/include/c++/14.1.1/stdexcept:39,
                 from /usr/lib/pkgconfig/../../include/pybind11/detail/../detail/common.h:320,
                 from /usr/lib/pkgconfig/../../include/pybind11/detail/../attr.h:13,
                 from /usr/lib/pkgconfig/../../include/pybind11/detail/class.h:12,
                 from /usr/lib/pkgconfig/../../include/pybind11/pybind11.h:13,
                 from src/main.cpp:1:
/usr/include/c++/14.1.1/cstdlib:79:15: fatal error: stdlib.h: No such file or directory
   79 | #include_next <stdlib.h>
      |               ^~~~~~~~~~
compilation terminated.

Happens on both
CLang 17.0.6
GCC 14.1.1

Surprisingly but xmake project -k cmake && cmake . && make is working.

@naquad naquad added the bug label May 22, 2024
@waruqi
Copy link
Member

waruqi commented May 22, 2024

-isystem /usr/lib/pkgconfig/../../include -> /usr/include it will break gcc. gcc will not find stdlib.h

you can try add_requires("pybind11", {system = false}) to disable use pkg-config to find system libs.

@naquad
Copy link
Author

naquad commented May 23, 2024

Yes, this has helped, thank you 👍

However, the point was to build the bindings library only when there's a pybind11 in the system w/o downloading it. The fact that pkg-config is causing a build failure seems like a bug.

@waruqi
Copy link
Member

waruqi commented May 23, 2024

Yes, this has helped, thank you 👍

However, the point was to build the bindings library only when there's a pybind11 in the system w/o downloading it. The fact that pkg-config is causing a build failure seems like a bug.

This is a known gcc issue, we can not set -isystem /usr/include to gcc.

However, we can't get pkg-config not to return the /usr/include path. This may also be an issue of pybind11's .pc file

@naquad
Copy link
Author

naquad commented May 23, 2024

Is there some way to use -I instead of -isystem? Semantics is somewhat different, but it works then.

@waruqi
Copy link
Member

waruqi commented May 23, 2024

add_requires("xxx", {external = false}) or set_policy("package.include_external_headers", false)

@naquad
Copy link
Author

naquad commented May 23, 2024

Perfect! Thank you. The first option is the way to go in my case.

Some further digging just for the reference. The output of the pkg-config is indeed questionable:

❯❯❯ pkg-config --cflags pybind11
-I/usr/lib/pkgconfig/../../include

I would rather expect Python's includes to be listed rather than just /usr/include but we have what we have. Given this and the conversion of the -I to -isystem by default, I think it is safe to say that the package itself (or its build) is a culprit, so it is a corner case and the issue can be closed.

Thank you again for the quick resolution.

@naquad naquad closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants