Search code examples
clinuxgccrhelcunit

Installing CUnit on RHEL CUnit/CUnit.h: No such file or directory


I'm trying to set up CUnit for use on Red Hat Enterprise Linux. This is my test file in c:

#include <CUnit/CUnit.h>

int main() {
    return 0;
}

At first, I was getting an error when using gcc cunit-test.c -lcunit:

/usr/bin/ld: cannot find -lcunit
collect2: error: ld returned 1 exit status

So I made a symlink so that /usr/lib64/libcunit.so points to /usr/lib64/libcunit.so.1, which fixed that error.

However, I'm still not able to use the CUnit files. When I compile my test file, with gcc cunit-test.c -lcunit I get the error

cunit-test.c:1:10: fatal error: CUnit/CUnit.h: No such file or directory
 #include <CUnit/CUnit.h>
          ^~~~~~~~~~~~~~~
compilation terminated.

Solution

  • I was able to solve this question thanks to @Shawn.

    To use CUnit, you need two packages: CUnit and CUnit-devel. The CUnit package is in the default RHEL repositories, but the CUnit-devel package is in a repository called codeready-builder. To use CUnit on RHEl, you need to run sudo subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms (or rhel-9 if you are using RHEL 9, etc.) to enable the repository, then install the CUnit-devel package. Then you should be able to compile your program with gcc cunit-test -lcunit.