1 1
sgjava

How to compile libgpiod?

Recommended Posts

I've tried to compile libgpiod (my assumption is this is a user space lib) and it depends on gpio.h which is used by the kernel. According to https://github.com/brgl/libgpiod/issues/22 gpio.h should be installed with linux-libc-dev which is already installed and gpio.h is missing. I installed the kernel headers and tried (it ends up with typedef conflicts):

 

./autogen.sh --enable-tools=yes --prefix=/usr/local CFLAGS="-I/usr/src/linux-headers-4.14.14-sunxi/arch/arm/include -I/usr/src/linux-headers-4.14.14-sunxi/include"

 

configure: error: linux/gpio.h header not found (needed to build the library)

 

I've attached the config.log. Maybe I'm totally missing the boat, but there's not a lot of info out there build this for ARM and there are no deb packages for ARM I can find.

config.log

Share this post


Link to post
Share on other sites

As I understand it should be compiled against the userspace headers (/usr/src/linux-headers-$(uname -r)/inclide/uapi/linux/gpio.h).

linux-libc-dev package is irrelevant since it comes from upstream and it will contain wrong headers, and Armbian doesn't package libc-dev headers that should be installed to /usr/include/linux

Share this post


Link to post
Share on other sites

OK, I used armbian-config to get the headers since you cannot get the headers with apt-get install linux-headers-$(uname -r) or apt-get install linux-headers-generic. The later tries to pull the 4.4 headers and libgpiod requires >= 4.8. So it looks like I'm doing it right, but any combination of includes using  /usr/src/linux-headers-4.14.14-sunxi has not worked.

Share this post


Link to post
Share on other sites

OK, I got it to build finally! I'm working on a how-to and will post that once I verify the steps and that it actually works, thanks!

 

Share this post


Link to post
Share on other sites
On 1/24/2018 at 12:03 PM, sgjava said:

OK, I got it to build finally! I'm working on a how-to and will post that once I verify the steps and that it actually works, thanks!

 

@sgjava, could you please post how you manage to get the "linux/gpio.h" file, I am running into the same problem where the autoconfig say it could not find the 'linux/gpio.h' file, Please help with your findings. Thanks. Srin.

Share this post


Link to post
Share on other sites

@Srini gpio.h should be in the downloaded kernel headers. You can sudo find / -name gpio.h to see where it is. https://github.com/sgjava/userspaceio/blob/master/libgpiod/install.sh#L38 is where the kernel header logic is. I tested this with the latest stable release for NanoPi Duo and it worked fine. It also worked on the FriendlyElec image, but I had to manually install the headers.

Share this post


Link to post
Share on other sites
On 9/26/2018 at 10:06 PM, sgjava said:

@Srini gpio.h should be in the downloaded kernel headers. You can sudo find / -name gpio.h to see where it is. https://github.com/sgjava/userspaceio/blob/master/libgpiod/install.sh#L38 is where the kernel header logic is. I tested this with the latest stable release for NanoPi Duo and it worked fine. It also worked on the FriendlyElec image, but I had to manually install the headers.

@sgjava , Thank you so much, but even after I find the gpio.h from kernel source path and installed manually in /usr/src/linux-header-$(uname -r)/ , the configure script could not able to find the path of  "linux/gpio.h" but finally I could solve the compilation by exporting the C_INCLUDE_PATH in the shelling using "export C_INCLUDE_PATH=/usr/src/linux-headers-4.14.72-v7+/include/:/usr/include/" , it's working now.. I could build the libgpiod on the Raspberry CM3.

once again thank you so much.   

Regards,

Srini.

 

Share this post


Link to post
Share on other sites

@Srini If you look at my script I just create an include dir for artifacts missing in the compile path:

 

# Add header file missing from Linux user space includes

mkdir -p $curdir/include/linux >> $logfile 2>&1

cp /usr/src/linux-headers-$kerver/include/linux/compiler_types.h $curdir/include/linux/. >> $logfile 2>&1

log "Running autogen"

export PYTHON_VERSION=3

./autogen.sh --enable-tools=yes --enable-bindings-python --prefix=/usr/local CFLAGS="-I/usr/src/linux-headers-$kerver/include/uapi -I$curdir/include" >> $logfile 2>&1

 

I've talked to the author of libgpiod and whatever distro he's using it builds without doing any of this, but the various ARM based distros need some tweaking.

Share this post


Link to post
Share on other sites
(edited)

Hi, one question about cross-compilation (e.g. for the raspberry). Do you have a working procedure? I have gone along your path but now adding stuff like arch=ARM and all these flags does not solve the issue. I can post the details but i made a lot of guessing so if you have a working procedure or you have a link that points at libgpiod cross-compilation would be very useful. 

 

Thanks 

Edited by modo
Typos

Share this post


Link to post
Share on other sites

I'm having this same trouble.  And I also don't have and can't apt install "armbian config".  I'm on a Neo Air (H2/H3).  Can someone help me get gpio.h.  I'm just trying to get control of GPIO pins on the Air that seem to be out of reach on all the libs i've been trying.  see my other post.  

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
1 1