0

I am trying to use CAN J1939 standard on an embedded Linux system running Ubuntu 18.04, kernel 5.4.0-52-generic.

This elinux page indicates that j1939.h "got in the mainline kernel since v5.4". And kernel.org's documentation for j1939 implies that it is in the main kernel.

Lastly, I do have can-utils installed.

When I compile a cpp file with #include <linux/can/j1939.h>, I get a no such file or directory error.

I've gone through linux/can directory to confirm and j1939.h is not there. Is there any reason why my v5.4 kernel wouldn't have j1939.h? How can I best use j1939.h in my program?

kaylum
  • 13,833
  • 2
  • 22
  • 31
Cameron
  • 3
  • 1

1 Answers1

0

You need development packages for these headers. You can search for which package you need on the Ubuntu Packages site. I.e. in this case packages containing j1939.h. You're probably looking for linux-libc-dev or linux-headers-5.4.0-26.

AVH
  • 11,349
  • 4
  • 34
  • 43
  • Ahh good information. Is there some obvious way to know if some header requires an additional package? – Cameron Oct 28 '20 at 21:58
  • Normally, if you need headers, you're going to need dev packages. It makes little sense for the "general" linux desktop to contain CAN-related headers, so they're not installed by default. Your best bet is to simply search on the page I linked to see which packages are necessary. If they're already installed, Ubuntu will tell you. – AVH Oct 28 '20 at 22:00
  • @Cameron If this answers you're questions please upvote/accept it. – AVH Oct 28 '20 at 22:04
  • It actually appears as though [there isn't a package available for Bionic, 18.04](https://packages.ubuntu.com/search?suite=bionic&arch=any&mode=exactfilename&searchon=contents&keywords=j1939.h) with `j1939.h`. In that case, is there another best practice to use that header? – Cameron Oct 28 '20 at 22:21
  • Ah, that's pretty annoying. What you can try is to download the .deb files for both the headers and the package itself from the Ubuntu Package website and install those manually. Not ideal, but often that does work. – AVH Oct 28 '20 at 22:24
  • Gotcha. Would you recommend placing it in the expected directory `/usr/include/linux/can/` or would it be better to include it in my project includes? – Cameron Oct 28 '20 at 22:27
  • When installing the .deb files they'll be placed in the correct location automatically. But even if installing manually, I'd recommend not to place them inside your project, because that would be pretty "non-standard" for system headers. – AVH Oct 28 '20 at 22:28