I am trying to create an RPM package with some basic C and C++ example files before I try doing the package creation with software at my job that is running on Red Hat Enterprise Linux 6, but having problems.

Here is my example C program:

// main.c - file for testing rpm packages
#include <stdio.h>

void functionone() {
    printf("C function one!\n\n");

void functiontwo() {
    printf("C function two!\n\n");

int main()



    return 0;

And here is the makefile I am using:

all: main

c: main

    gcc main.c -o c

    rm c

The C program and makefile I am than creating a zipped file named "c.tar.gz"

And here is the spec file I am trying to use:

Name:           c
Version:        0.1
Release:        1
Summary:        Example C application for testing rpm packaging

License: GPLv3        
URL: https://example.com/%{name}           
Source0: c.tar.gz

BuildRequires: make      

Example C program for rpm package

%setup -q




 * Mon Mar 9 2020 Michael G. Workman <michael.g.workman@gmail.com>
 - first c program package

Then I enter the following command in the SPECS directory:

rpmbuild -ba c.spec

Then I get the following output from that command:

+ umask 022
+ cd /net/users/mworkman/rpm/BUILD
+ export LANG
+ unset DISPLAY
+ cd /net/users/mworkman/rpm/BUILD
+ rm -rf c-0.1
+ /usr/bin/gzip -dc /net/users/mworkman/rpm/SOURCES/c.tar.gz
+ /bin/tar -xf -
+ '[' 0 -ne 0 ']'
+ cd c-0.1
/net/users/mworkman/rpm/tmp/rpm-tmp.Lhyj19: line 38: no such file or directory
error: Bad exit status from /net/users/mworkman/rpm/tmp/rpm-tmp.Lhyj19 (%prep)
   Bad exit status from /net/users/mworkman/rpm/tmp/rpm-tmp.Lhyj19 (%prep)

Now looking at this output, it looks like it is removing c-0.1 and its contents, then trying to change into it with cd after the delete, so I am not sure why it would do that, either the folder c-0.1 is never created in the first place, and or it is created then deleted.

However, when I run the this command at the command line to create the rpm file, there is no error:

rpm -bs c.spec

output from this command:

Wrote: /net/users/mworkman/rpm/SRPMS/c-0.1-1.src.rpm

Then run this command at the command line from the rpm/SRPMS directory:

rpm -ivh c-0.1-1.src.rpm

And then get this output:

1:c             ################################ [100%]

However, I am not able to find an executable called c after running this operation, I am trying to install the example program as a simple C program, then compile the file main.c into an executable, but that does not appear to work as an rpm package, however, the C program compiles just fine when running the make directly on the main.c file, and correctly produces an executable, but I am not able to also do that with an rpm package. I think I am missing something really simple. Thanks for your help.


Your first error is because %setup expects some structure. You can either change how you create a tarball (see https://rpm-packaging-guide.github.io/#preparing-source-code-for-packaging ) or change the behavior of %setup using arguments (see http://ftp.rpm.org/max-rpm/s1-rpm-inside-macros.html ).

In your however-part, you created source package. Which contains only spec and tarball (try running rpm -qpl /net/users/mworkman/rpm/SRPMS/c-0.1-1.src.rpm). It get installed into~/rpmbuild/` directory and it is not tracked in rpmdb.

| improve this answer | |
  • Thanks for your input, I think what might be a problem here is %{_bindir} is /usr/bin, and I cannot write anything to that directory without root permissions, do you know how I would change the value of %{_bindir} to a different directory I have permissions to, like $HOME. search engine search does not show any way to set the valuer of that variable, thanks for your help. – Michael G. Workman Mar 12 at 16:58
  • Ok thanks for your input, this issue has been resolved and my rpm package is working correctly. some needed changes to SPEC file were to designate the compiler to use, in some of my software C++ is used, but adding g++ to BUILDREQUIRES in SPEC file does not work, you have to use gcc-c++ instead, was not expecting the spec files to be so temperamental, but now they work. – Michael G. Workman Mar 12 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.