CEC 3.0.0 on the Raspberry Pi

UPDATE 20180123

This article is now years out of date.  you should simply be able to install the cec-utils package and all should be well.

sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get install cec-utils

Background

In a previous blog I gave some instructions on how to compile up libcec on the RPi. Those no longer work as of CEC 3.0.0. In this post I’ll give you the new instructions that work as at 11 June 2015. To be specific, I have tested these instructions on an RPi2 running Raspbian. I have to say thankyou to nlrb for leaving excellent instructions on the RPi forums.

The first thing to do is update your RPi to the latest packages.

sudo apt-get update && sudo apt-get dist-upgrade
sudo rpi-update
sudo reboot

Next install the prerequisites for building libcec

sudo apt-get install git cmake g++-4.8 checkinstall liblockdev1-dev libudev-dev libxrandr-dev python-dev swig

Clone the Pulse-Eight libcec repository

Be careful to do the clone recursively otherwise you will be missing the “platform” submodule.

cd [workarea]
git clone --recursive https://github.com/Pulse-Eight/libcec.git

Patch src/libcec/cmake/CheckPlatformSupport.cmake

(remove the line with the -sign and add the lines with the +sign. Other lines are just included for context. Around about line 80) with

- check_library_exists(bcm_host vchi_initialise "" HAVE_RPI_API)
+ check_library_exists(bcm_host bcm_host_init "" HAVE_RPI_API)
 if (HAVE_RPI_API)
 set(LIB_INFO "${LIB_INFO}, 'RPi'")
+ include_directories(/opt/vc/include /opt/vc/include/interface/vcos/pthreads /opt/vc/include/interface/vmcs_host/linux)
 list(APPEND CMAKE_REQUIRED_LIBRARIES "vcos")

Create the cec platform library

cd [workarea]/libcec/src/platform
mkdir build
cd build

Note the dot dot at the end of the following line

cmake -DCMAKE_CXX_COMPILER=g++-4.8 ..
make
sudo checkinstall

Finally build libcec

cd [workarea]/libcec
mkdir build
cd build
cmake -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=1 ..
make
sudo -s
export LIBRARY_PATH=/opt/vc/lib
checkinstall
Tagged with: , , ,
Posted in Uncategorized
48 comments on “CEC 3.0.0 on the Raspberry Pi
  1. eman says:

    Sadly It don’t work as described on my RaspberryPi:

    When I do “git clone –recursive git@github.com:Pulse-Eight/libcec.git”

    it answers:
    Cloning into ‘libcec’…
    Permission denied (publickey).
    fatal: The remote end hung up unexpectedly

    • Hi Eman,

      You will get that error if you have not ever created an account with Github. You create an account at https://github.com/join

      Hopefully that will solve your issue.

      Best wishes,
      Geoff

      • eman says:

        Hi Geoff,

        thanks for your reply.
        There is no default package ‘libcec’ (as far as I know) installed. Raspbian is set up clean from downloaded File with no further packages. F. e. dpkg -l|grep “libcec” says nothing.

    • kernelsmith says:

      Actually, I think u just need to create a public ssh key to present to ssh. Any key will do, u can use ssh-keygen to create one. However, the easier thing to do is switch from a got url to an https one. git clone–recursive https://github.com/Pulse-Eight/libcec.git will work

  2. Lutz says:

    Everything works fine once you have mastered the <permission denied (publickey)-thing (there is a how-to on the github-website). However one has to close the parenthesis at

    + include_directories(/opt/vc/include /opt/vc/include/interface/vcos/pthreads /opt/vc/include/interface/v…………")"

    Obviously there is something missing (……), I have left out "/opt/vc/include/interface/v" entirely.
    What do we have to put there?

    • Sorry about the cut’n’paste error. The last include directory is supposed to be

      /opt/vc/include/interface/vmcs_host/linux

      I’ve fixed the article. Many thanks for taking the time to point the error out to me.

      Best wishes,
      Geoff

  3. curcuz says:

    Hi there, thank for the guide, the installation went fine. However, when i try to actually use the cec-client, it cannot find any adapter:

    # cec-client -l
    libCEC version: 3.0.0, compiled on Linux-3.18.16-v7+, features: P8_USB, P8_detect, randr
    Found devices: NONE

    any hint?

    thanks

    • Hi curcuz,

      I see on the “features:” part of the output that you are missing ‘RPi’.

      Makes me think that the HAVE_RPI_API variable in the cmake configs hasn’t been triggered.

      What OS are you using? I’d guess something other than Raspbian.

      I’ll see if I can dig anything else up.

      Best wishes,
      Geoff

      • curcuz says:

        Hi drgeoffathome, thanks for the response.

        I am on a Rpi 2 model B with the latest raspbian install. I double-checked that i correctly patched src/libcec/cmake/CheckPlatformSupport.cmake with the istructions you provided

        Please tell me if i can do more to help you fig this up

        Best regards

      • Hi,

        Can you send me a copy of that src/libcec/cmake/CheckPlatformSupport.cmake file please. Send to at gmail.com. I’ll do a diff of your file to my file to check for any crazy errors.

        Thanks,
        Geoff

      • curcuz says:

        sent, thanks a lot

      • eman says:

        Hello Geoff, hello Patrick

        I experienced nearly exact the same Problem – Output of cec-clinet says:
        libCEC version: 3.0.0, compiled on Linux-3.18.11+, features: P8_USB, P8_detect, randr
        Found devices: NONE

        The OS-Image I use is Raspbian Debian Wheezy 3.18 Release date 2015-05-05 from this site: https://www.raspberrypi.org/downloads/

        So what can we do? Which OS are you (Geoff) using?

        Best regards & Thank for the great work

      • Did either of you remove the default libcec package?

  4. Patrick Roncagliolo says:

    Hi, building libcec on ubuntu-mate for RPi2. I’m getting this error while trying to “make”:

    Scanning dependencies of target cec
    [ 2%] Building CXX object src/libcec/CMakeFiles/cec.dir/CECClient.cpp.o
    [ 5%] Building CXX object src/libcec/CMakeFiles/cec.dir/CECProcessor.cpp.o
    [ 8%] Building CXX object src/libcec/CMakeFiles/cec.dir/LibCEC.cpp.o
    [ 10%] Building CXX object src/libcec/CMakeFiles/cec.dir/LibCECC.cpp.o
    [ 13%] Building CXX object src/libcec/CMakeFiles/cec.dir/adapter/RPi/RPiCECAdapterDetection.cpp.o
    /home/patrick/libcec/libcec/src/libcec/adapter/RPi/RPiCECAdapterDetection.cpp:40:47: fatal error: interface/vmcs_host/vc_cecservice.h: No such file or directory
    #include
    ^
    compilation terminated.
    src/libcec/CMakeFiles/cec.dir/build.make:146: recipe for target ‘src/libcec/CMakeFiles/cec.dir/adapter/RPi/RPiCECAdapterDetection.cpp.o’ failed
    make[2]: *** [src/libcec/CMakeFiles/cec.dir/adapter/RPi/RPiCECAdapterDetection.cpp.o] Error 1
    CMakeFiles/Makefile2:227: recipe for target ‘src/libcec/CMakeFiles/cec.dir/all’ failed
    make[1]: *** [src/libcec/CMakeFiles/cec.dir/all] Error 2

    in /opt/vc there is no “interface” or “include” directory, that I think are required (the patch you mentioned in your guide tells to add “include_directories(/opt/vc/include …”).

    Can you help me?

    • Hi Patrick,

      The first thing to make sure of is that you have libraspberrypi-dev installed.

      sudo apt-get install libraspberrypi-dev 
      

      Also note that Ubuntu MATE has a different directory structure to Raspbian. The RPi specific header files are installed to /usr/include by Ubuntu MATE. I think if you just put “usr” in where my instructions say “opt/vc” then all will be well. Leave out the include that collapses to /usr/include.

      Let me know if that doesn’t work.

      Cheers,
      Geoff

      • Patrick Roncagliolo says:

        seems that libraspbverrypi-dev wasn’t installed. Now compiling… I’ll give you updates soon 😉 thanks a lot for your help 😉

      • Patrick Roncagliolo says:

        Ok, worked with that package installed, and /usr/instead of /opt/vc…
        I suggest you to modify your useful guide, mentioning these tricks for Ubuntu MATE, so that people won’t need to read our comments desperately 😉 Thank you so much fo your help

  5. Lutz says:

    Hi Geoff,

    just now managed to find the time to compile with the updated patch. Same results as man and curcus. Do have also the same raspbian as eman and did not remove libcec1.

    Then I renamed /opt/vc, so I would get an error during the compile; there was no error, though. Checking the cmake output I found
    — Looking for bcm_host_init in bcm_host
    — Looking for bcm_host_init in bcm_host – not found

    I checked the /opt/vc/lib and libbcm_host.so war there. Then I inserted
    Message(raspberry + ${HAVE_RPI_API}) in the patched file (as in your post).

    When I re-installed (actually I found that one has to start over by eliminating the two build dirs), I got:

    — Looking for bcm_host_init in bcm_host
    — Looking for bcm_host_init in bcm_host – found
    RASPBERRY+1
    — Looking for include files tda998x_ioctl.h, comps/tmdlHdmiCEC/inc/tmdlHdmiCEC_Types.h
    — Looking for include files tda998x_ioctl.h, comps/tmdlHdmiCEC/inc/tmdlHdmiCEC_Types.h – not found.
    — Found SWIG: /usr/bin/swig2.0 (found version “2.0.7”)
    — Configured features:
    — Pulse-Eight CEC Adapter: yes
    — Pulse-Eight CEC Adapter detection: yes
    — lockdev support: yes
    — xrandr support: yes
    — Raspberry Pi support: yes
    — TDA995x support: no
    — Exynos support: no
    — Python support: version 2.7.3 (2.7)
    — lib info: compiled on Linux-3.18.11-v7+, features: P8_USB, P8_detect, randr, ‘RPi’
    — Configuring done
    — Generating done
    — Build files have been written to: /home/pi/libcec/build
    root@rasPi2:/home/pi/libcec/build# make
    Scanning dependencies of target cec
    [ 2%] Building CXX object src/libcec/CMakeFiles/cec.dir/CECClient.cpp.o

    [ 13%] Building CXX object src/libcec/CMakeFiles/cec.dir/adapter/RPi/RPiCECAdapterDetection.cpp.o
    [ 16%] Building CXX object src/libcec/CMakeFiles/cec.dir/adapter/RPi/RPiCECAdapterCommunication.cpp.o
    [ 18%] Building CXX object src/libcec/CMakeFiles/cec.dir/adapter/RPi/RPiCECAdapterMessageQueue.cpp.o

    So, the lib was found, the RPI support was flagged and the RPi were binaries built.

    I have, however, no idea what I changed (other than repeating the install process a couple of times), surely that -command did not make the compiler find a file ?!?

    Anyway, it works now:

    root@rasPi2:/home/pi/libcec/build# cec-client
    No device type given. Using ‘recording device’
    CEC Parser created – libCEC version 3.0.0
    no serial port given. trying autodetect:
    path: Raspberry Pi
    com port: RPI

    opening a connection to the CEC adapter…
    DEBUG: [ 83] Broadcast (F): osd name set to ‘Broadcast’
    DEBUG: [ 84] InitHostCEC – vchiq_initialise succeeded
    DEBUG: [ 84] InitHostCEC – vchi_initialise succeeded
    DEBUG: [ 84] InitHostCEC – vchi_connect succeeded
    DEBUG: [ 84] logical address changed to Free use (e)
    DEBUG: [ 84] Open – vc_cec initialised
    NOTICE: [ 85] connection opened
    DEBUG: [ 85] processor thread started
    DEBUG: [ 85] < TV (0): POLL

  6. Alexander P says:

    With new version of libCEC (changed 6 days ago) you don’t need patch src/libcec/cmake/CheckPlatformSupport.cmake.

    And in the finally build must use:
    cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=1 ..

    • eman says:

      Hello Alexander

      works fine for me. You’ve made a very sad man happy 🙂
      Thanks again for the great work

      Regards

      eman

  7. Ted Barnes says:

    Have just tried to make the changes to the “CheckPlatformSupport.cmake” (newly downloaded onto my Pi1), but it does not match the instructions. The relevant bit prior to trying to make changes is:

    # raspberry pi
    find_library(RPI_BCM_HOST bcm_host “${RPI_LIB_DIR}”)
    check_library_exists(bcm_host bcm_host_init “${RPI_LIB_DIR}” HAVE_RPI_API)
    if (HAVE_RPI_API)
    find_library(RPI_VCOS vcos “${RPI_LIB_DIR}”)
    find_library(RPI_VCHIQ_ARM vchiq_arm “${RPI_LIB_DIR}”)
    include_directories(${RPI_INCLUDE_DIR} ${RPI_INCLUDE_DIR}/interface/vcos/pt$

    set(LIB_INFO “${LIB_INFO}, ‘RPi'”)

    Could you please clarify the changes needed

  8. ferdydek says:

    Hi,

    I’m having some difficulties with cmake

    root@RasTha:/opt/workarea/libcec/build# cmake -DCMAKE_CXX_COMPILER=g++-4.8 ..
    — The C compiler identification is unknown
    CMake Error at CMakeLists.txt:1 (project):
    No CMAKE_C_COMPILER could be found.

    Tell CMake where to find the compiler by setting either the environment
    variable “CC” or the CMake cache entry CMAKE_C_COMPILER to the full path to
    the compiler, or to the compiler name if it is in the PATH.

    — Configuring incomplete, errors occurred!
    See also “/opt/workarea/libcec/build/CMakeFiles/CMakeOutput.log”.
    See also “/opt/workarea/libcec/build/CMakeFiles/CMakeError.log”.
    root@RasTha:/opt/workarea/libcec/build#

    and then the log file:

    Compiling the C compiler identification source file “CMakeCCompilerId.c” failed.
    Compiler: CMAKE_C_COMPILER-NOTFOUND
    Build flags:
    Id flags: -c

    • Ted Barnes says:

      Thanks for taking the time to try to help, Alexander. I get:

      cec-client -l
      libCEC version: 3.0.1, git revision: , compiled on Mon Jul 20 12:38:45 UTC 2015 by pi@raspberrypi on Linux 4.0.8+ (armv6l), features: P8_USB, P8_detect, randr
      Found devices: NONE

      I note that “RPi” is missing from the list of “features” – any idea what I have done wrong?

  9. Ted Barnes says:

    Following Alexander P’s comment, I have tried omitting the changes to the cmake file on my pi1, and then get an error:

    “CMake Error at cmake_install.cmake:44 (FILE):
    file INSTALL cannot find
    “/home/pi/libcecworkarea/libcec/src/platform/src/posix/os-threads.h”.”

    at the “sudo checkinstall” stage. However the relevant file does exist in that location and the permissions look OK

    • Alexander P says:

      I used Pi2. Maybe there are some differences. I can not test for Pi1, unfortunately.
      Try using sudo apt-get install cec-utils.

      • Ted Barnes says:

        Thanks. Have tried “sudo apt-get install cec-utils”, but this installs version 2.2 and this is not working with my Sony TV. The problem could be the cable or finger trouble, but I wanted to use the latest version of libcec if possible to cut down on the possible sources of problems (especially as doing anything that involves fiddling with the TV means upsetting SWMBO!).

      • Alexander P says:

        Error occurs during installation platforms or libcec?
        If the installation libcec then check where you create folders “build”. In your case, it should be /home/pi/libcecworkarea/libcec/build/.
        With my TV Samsung and Phillips version 2.2 also does not work, and 3.0 works fine. 🙂

      • Ted Barnes says:

        Sorry if I did not make it clear – my problem with the file not being found is at the “sudo checkinstall” at the end of the creation of the cec platform library. What I find particularly confusing is that it really does exist at the location where it claims to be looking.

    • Ted Barnes says:

      Fixed my problem with not finding the file by rebuilding from a clean Raspbian image. I had previously deleted the whole work area, but this does not seem to have been adequate.

      Cec-client now runs, but “cec-client -l” does not find any devices, whereas version 2.2. found the one in the Pi. Is this normal?

      • Alexander P says:

        Here that on my PI:

        cec-client -l
        libCEC version: 3.0.1, git revision: 7599a30, compiled on Fri Jul 10 12:33:27 UTC 2015 by root@pipaos on Linux 3.18.6-v7+ (armv7l), features: P8_USB, P8_detect, randr, ‘RPi’
        Found devices: 1

        device: 1
        com port: RPI
        vendor id: 2708
        product id: 1001
        firmware version: 1
        type: Raspberry Pi

    • Ted Barnes says:

      Thanks for taking the time to try to help, Alexander. I get:

      cec-client -l
      libCEC version: 3.0.1, git revision: , compiled on Mon Jul 20 12:38:45 UTC 2015 by pi@raspberrypi on Linux 4.0.8+ (armv6l), features: P8_USB, P8_detect, randr
      Found devices: NONE

      I note that “RPi” is missing from the list of “features” – any idea what I have done wrong?

      • Alexander P says:

        ‘RPi’ perhaps the most important thing. 🙂
        Check out all the steps, including all updates. I checked on the clean image. Everything worked for this instruction.
        Check ‘— Raspberry Pi support: yes’ on cmake step.

      • Ted Barnes says:

        Making some progress it seems to compile, recognises it should work with RPi, but when I try to run cec-client I get:

        “cec-client: error while loading shared libraries: libplatform.so.1.0: cannot open shared object file: No such file or directory”.

        Any ideas?

      • Hi Ted,

        What that error means is that the directory the libplatform.so got installed in is not in the default locations that the dynamic linker looks up to find dynamic libraries.

        libplatform is one of the shared libraries that gets built and installed in this whole process you’ve been through.

        It is possible to add user defined paths in the LD_LIBRARY_PATH environment variable but it would probably be better to get the library into the more usual location.

        Where did libplatform.so.1.0 actually end up when you installed the package? Try “locate libplatform” will tell you that.

        Cheers,
        Geoff

      • Ted Barnes says:

        Have found the source of my problems – I was trying to use a bash script to minimise the possibility of mistakes, and it didn’t like the “sudo -e” or my use of sudo prefix in subsequent lines instead. However when I reverted to use of “sudo make install” as in nlrb’s procedure all seemed to be OK on my Pi2. Will try on my Pi1 later.

      • Glad to see you later solve this. Good work.

        Best wishes,
        Geoff

  10. simar says:

    Hi,
    As mentioned in comments, I did not patch the file.
    Then after running this
    cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=1 ..

    It displays these errors
    CMake Error at src/cec-client/CMakeLists.txt:21 (find_package):
    By not providing “Findplatform.cmake” in CMAKE_MODULE_PATH this project has
    asked CMake to find a package configuration file provided by “platform”,
    but CMake did not find one.

    Could not find a package configuration file provided by “platform” with any
    of the following names:

    platformConfig.cmake
    platform-config.cmake

    Add the installation prefix of “platform” to CMAKE_PREFIX_PATH or set
    “platform_DIR” to a directory containing one of the above files. If
    “platform” provides a separate development package or SDK, be sure it has
    been installed.

    — Configuring incomplete, errors occurred!

    • Hi,

      Your errors make me think that you missed the step in the section titled “Create the cec platform library”. Let me know how you get on.

      Best wishes,
      Geoff

  11. Hello geoff

    Could you also send me a copy of that src/libcec/cmake/CheckPlatformSupport.cmakefile that you received from curcuz? I’m going through the same issue i think. guywilsonjr@gmail.com

    Best

    • Hi,
      Yes, I’ll send you the cmakefile but I don’t think you need it. Pulse-Eight have been updating libcec and I think this workaround step is no longer necessary. But I haven’t had time to test myself so that’s why I’m using weasel words like “I think”.
      Best wishes,
      Geoff

  12. Simon says:

    Hi I am getting the following after running all the steps. cmake had Raspberry Pi support yes:

    Now I plug it into HDMI and run cec-client -l and get this:

    cec-client -l
    libCEC version: 3.0.0, compiled on Linux-3.18.14+, features: P8_USB, P8_detect, randr, ‘RPi’
    Found devices: NONE

    Am I missing something?

    Any help would be greatly appreciated.
    Thanks in advance,

    Simon

  13. Robert says:

    I know this is a RPi thread but I was wondering if anyone has this working on Android?

  14. Liam says:

    So, I’ll preface my question by stating that I am a raspberry pi novice, but I was trying to use this guide in order to install libcec to a pi running debian v2. I manage to get all the way to the “cmake -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=1 ..” step.

    However, I run into an error with the following message.

    CMake Error at src/libcec/cmake/CheckPlatformSupport.cmake:193 (if):
    if given arguments:

       "3" "GREATER" "2" "AND" "3" "GREATER_EQUAL" "7"
    
    Unknown arguments specified
    

    Call Stack (most recent call first):
    src/libcec/CMakeLists.txt:133 (include)

    I would appreciate any help in getting this figured out.

  15. Liam says:

    Update: I added the cec-utils package, and it should suit my needs.

Leave a reply to Robert Cancel reply