linking to musl with other headers from /usr/include
Asked Answered
Y

1

8

I am trying to compile a program with x11 and use musl for the c library. I still have glibc on my system. Musl is located at /usr/local/musl/include The glib headers are still in /usr/include

When I muild with

musl-gcc test.c

I get fatal error: X11/Xlib.h: no such file or directory

If I try

musl-gcc test.c -I/usr/include

It includes the glib headers instead of the musl headers and throws a bunch of errors.

If I try

musl-gcc test.c -I/usr/local/musl/include -I/usr/include

It still includes the headers from glib in /usr/include

How do I make musl-gcc use the musl headers but still include other files from /usr/include?

Yoho answered 9/2, 2017 at 4:12 Comment(2)
Symlinking /usr/include/X11 to /usr/local/musl/include/X11 seems working, but I have no success with symlinking libX11.so to /usr/local/musl/lib. If you on gcc 6, use "-mmusl" option.Ranket
for linux headers just make symlinks into your musl tree. for Xlib, you'll need to rebuild Xlib (and its prerequisites) against musl and specify /usr/local/musl as your prefixLatham
R
0

Thanks to @technosaurus from comments. You should add symlinks.

For example, I needed to use linux header linux/userfaultfd.h while compiling with musl-gcc. Just make symlinks to include folder(in my case /usr/include/linux) and put them into default header-path of musl:

pushd /usr/local/musl/include
sudo cp -rs /usr/include/linux/ linux/ # now can #include<linux/...>

Note that most probably it won't be enough since included headers may also use #include <another-path/...>. You'll notice it in compiler error. Symlink all such another-path's and you are done.

As in my case I needed additionally to symlink those paths:

sudo cp -rs /usr/include/asm/ asm/ # now can #include<asm/...>
sudo cp -rs /usr/include/asm-generic/ asm-generic/ # now can #include<asm-generic/...>
Reckford answered 5/8, 2023 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.