Thread: Error by creating a rpm package from soource with rpmbuild

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    12

    Error by creating a rpm package from soource with rpmbuild

    Hello!

    I am working with SUSE LINUX tumbleweed and want to create a rpm package
    with rpmbuild not as Super User. This is my first time trying to create a rpm.
    I created my programs in the past always with an IDE like codelite, codeblocks , QT-Creator or Anjuta.
    I started them from the shell, example:
    Code:
    ./passungen
    But now i want to create a rpm, but get always errors.


    1. Create a program with Anjuta, codelite or codeblocks

    2 tar up the sources:
    Code:
    bohrungen.h
    bohrungen.h~
    Getvalwelle.cxx
    Getvalwelle.cxx~
    Getvalwelle.h
    etvalwelle.h~
    Getvalwelle.o
    main.cc
    main.cc~
    main.o
    Makefile
    Makefile.am
    Makefile.in
    passungen
    passungen.h
    passungen.h~
    into passungen-0.1.0.tar.gz

    The Makefile is this:

    Code:
    CC = cc
    LD = g++
    CFLAGS   :=  -g -O0 -Wall -c
    SOURCE := main.cpp Bohrung.cpp Bohrwelle.cpp Getvalwelle.cpp Wellen.cpp
    OBJ := main.o Bohrung.o Bohrwelle.o Getvalwelle.o Wellen.o
    DEPS := Getvalwelle.h
    DEST := itbreiten
    
    BINDIR = /usr/local/bin
    DOCDIR = /usr/share/doc/packages/itbreiten
    
    
    .PHONY: clean
    
    #    $(LD) -o $(DEST) main.o
    #Befehl    Bedeutung
    # -c       Compile and assemble, but do not link.
    #main.o: $(SOURCE)
    #    $(CC) $(CFLAGS) $(SOURCE)
    
    
    $(DEST): $(OBJ)
        $(LD) -o $(DEST) $(OBJ)
    
    #main.o: main.cpp
    
    #    $(CC) -c main.cpp
    #bohrposition.o: bohrposition.cpp
    
    #    $(CC) -c bohrposition.cpp    
    #Mit Wildcards k├Ânnen wir Befehle auf eine Gruppe von Dateien anwenden. 
    #Hier sollen nun alle .c-Dateien  zu .o-Dateien kompiliert werden. 
    #Diese werden mit dem %-Operator gesucht. Der gefundene Dateiname kann #mit $< verwendet werden.
    %.o: %.c
    
        $(CC) -c $<
        
    install:
    
        cp itbreiten $(BINDIR)
        mkdir $(DOCDIR)
        cp README $(DOCDIR)    
    
    clean:
    
        rm -f $(OBJ) $(DEST)
    3.Then i wrote this spec file named "passungen1.spec":
    Code:
    Vendor: Josef Wismeth
    Summary: calculates systems of fits according to DIN ISO 286-1 and DIN ISO-286-2
    Name: itbreiten
    Version: 0.1
    Release: 1
    License: GPL
    Group: unsorted
    Source: itbreiten0.0.1.tar.gz
    BuildArch: noarch
    BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
    %description
    This program allows the user to calculate the measurements of bores and shafts
    and their limiting sizes
    
    %prep
    %setup -q
    
    %build
    make %{?_smp_mflags}
    
    %install
    make install
    
    %files
    %{_bindir}/itbreiten
    4.copied the tar "passungen-0.1.0.tar.gz" to /rpmbuild/SOURCES
    5 copied the spec-file into rpmbuild/SPECS
    The other directories form rpmbuild BUILD and BUILDROOT were empty.

    After that changed in direction /rpmbuild/SPECS and started with rpmbuild -ba passungen1.spec using the terminal.


    But i get this error:
    Code:
    josef@PC192-168-2-100:~/rpmbuild/SPECS> rpmbuild -ba itbreiten1.spec
    Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.LhQAUg
    + umask 022
    + cd /home/josef/rpmbuild/BUILD
    + cd /home/josef/rpmbuild/BUILD
    + rm -rf itbreiten-0.1
    + /usr/bin/gzip -dc /home/josef/rpmbuild/SOURCES/itbreiten0.0.1.tar.gz
    + /usr/bin/tar -xof -
    + STATUS=0
    + '[' 0 -ne 0 ']'
    + cd itbreiten-0.1
    + /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
    + exit 0
    Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.mcvIqB
    + umask 022
    + cd /home/josef/rpmbuild/BUILD
    + /usr/bin/rm -rf /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    ++ dirname /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    + /usr/bin/mkdir -p /home/josef/rpmbuild/BUILDROOT
    + /usr/bin/mkdir /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    + cd itbreiten-0.1
    + make -j4
    make: 'itbreiten' is up to date.
    + exit 0
    Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.tJdZZV
    + umask 022
    + cd /home/josef/rpmbuild/BUILD
    + cd itbreiten-0.1
    + make install
    cp itbreiten /usr/local/bin
    cp: cannot create regular file '/usr/local/bin/itbreiten': Permission denied
    make: *** [makefile:39: install] Error 1
    error: Bad exit status from /var/tmp/rpm-tmp.tJdZZV (%install)
    
    
    RPM build errors:
        Bad exit status from /var/tmp/rpm-tmp.tJdZZV (%install)
    I hope someone can help me:
    He who makes no mistakes makes nothing

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    441
    A simple trick I use in makefiles:

    Code:
    # Shortcut to check if user has root privileges.
    define checkifroot
      if [ `id -u` -ne 0 ]; then \
        echo 'Need root privileges!'; \
        exit 1; \
      fi
    endef
    ...
    install:
        @$(call checkifroot)
        ...
    About your makefile, this:
    Code:
    %.o: %.c
        $(CC) -c $<
    Could be simplified to:
    Code:
    %.o: %.c
    Since make knows how to build c files into objects...
    And, in your linker command, you could change it to:
    Code:
    $(LD) -o $@ $^

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    12
    Hi flp1969,

    I changed my makefile to
    Code:
    CC = cc
    LD = g++
    CFLAGS   :=  -g -O0 -Wall -c
    SOURCE := main.cpp Bohrung.cpp Bohrwelle.cpp Getvalwelle.cpp Wellen.cpp
    OBJ := main.o Bohrung.o Bohrwelle.o Getvalwelle.o Wellen.o
    DEPS := Getvalwelle.h
    TARGETS := itbreiten
    
    BINDIR = /usr/local/bin
    DOCDIR = /usr/share/doc/packages/itbreiten
    
    
    .PHONY: clean
    
    #    $(LD) -o $(DEST) main.o
    #Befehl    Bedeutung
    # -c       Compile and assemble, but do not link.
    #main.o: $(SOURCE)
    #    $(CC) $(CFLAGS) $(SOURCE)
    
    
    $(TARGETS): $(OBJ)
        $(LD) -o $@ $^
    
    #main.o: main.cpp
    
    #    $(CC) -c main.cpp
    #bohrposition.o: bohrposition.cpp
    
    #    $(CC) -c bohrposition.cpp    
    #Mit Wildcards k÷nnen wir Befehle auf eine Gruppe von Dateien anwenden. 
    #Hier sollen nun alle .c-Dateien  zu .o-Dateien kompiliert werden. 
    #Diese werden mit dem %-Operator gesucht. Der gefundene Dateiname kann mit $< verwendet werden.
    %.o: %.c
    
    define checkifroot
      if [ `id -u` -ne 0 ]; then \
        echo 'Need root privileges!'; \
        exit 1; \
      fi
    endef
    
    install: itbreiten
      install -m 0755 -d $(DESTDIR)$(PREFIX)/bin
      install -m 0755 itbreiten $(DESTDIR)$(PREFIX)/bin
    
    clean:
        rm -f $(OBJ) $(DEST)
    but i have still this error:
    Code:
    josef@PC192-168-2-100:~/rpmbuild/SPECS> rpmbuild -ba itbreiten.spec
    Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.HRfeZ1
    + umask 022
    + cd /home/josef/rpmbuild/BUILD
    + echo 'BUILDROOT = /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64'
    BUILDROOT = /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    + mkdir -p /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64/usr/local/bin/
    + mkdir -p /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64/usr/local/share/itbreiten-0.1
    + exit 0
    Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.xQDRyg
    + umask 022
    + cd /home/josef/rpmbuild/BUILD
    + /usr/bin/rm -rf /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    ++ dirname /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    + /usr/bin/mkdir -p /home/josef/rpmbuild/BUILDROOT
    + /usr/bin/mkdir /home/josef/rpmbuild/BUILDROOT/itbreiten-0.1-1.x86_64
    + make -j4
    make: *** No targets specified and no makefile found.  Stop.
    error: Bad exit status from /var/tmp/rpm-tmp.xQDRyg (%build)
    
    
    RPM build errors:
        Bad exit status from /var/tmp/rpm-tmp.xQDRyg (%build)
    josef@PC192-168-2-100:~/rpmbuild/SPECS>
    and the rows in the spec-file below the description were changed to
    Code:
    %prep
    echo "BUILDROOT = $RPM_BUILD_ROOT"
    mkdir -p $RPM_BUILD_ROOT/usr/local/bin/
    mkdir -p $RPM_BUILD_ROOT/usr/local/share/itbreiten-0.1
     
    %build
    make %{?_smp_mflags}
     
    %install
    rm -rf $RPM_BUILD_ROOT
    make install DESTDIR=$RPM_BUILD_ROOT
     
    %files
    %defattr(-,root,root,-)
    %doc
    where to the hell is my failure?

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    441
    Notice checkifroot must be called in receipt rule's:
    Code:
    install: $(TARGET)
      $(call checkifroot)
      install...
    And, ok... I'm not sure if %.o: %.c will be dealt correctly. I prefer to list all the targets and sources. Individualy:
    Code:
    main.o: main.cpp
    Bohrunq.o: Bohrunq.cpp
    Bohrwelle.o: Bohrwelle.cpp
    Getvalwelle.o: Getvalwelle.cpp
    Wellen.o: Wellen.cpp
    This way you can add the include files *after* the source so make can check the dependencies:
    Code:
    main.o: main.cpp Bohrunq.h Bohrwelle.h Getvalwelle.h Wellen.h
    Bohrunq.o: Bohrunq.cpp Bohrunq.h
    Bohrwelle.o: Bohrwelle.cpp Bohrwelle.h
    Getvalwelle.o: Getvalwelle.cpp Getvalwelle.h
    Wellen.o: Wellen.cpp Wellen.h
    Since $< will be just the first source.


    You can get these lines with -MM option from GCC. Example: for i in *.cpp; do g++ -MM "$i" >> dependencies.mk; done
    Then, simply include dependencies.mk in your makefile, instead of explicit rules.

    AND notice... your sources are *.cpp, but your receipt is trying to make object files from %.c

    One more thing... .cpp extension should be reserved to "C Preprocessor". On Unix, c++ files are .C (uppercase), .cc, .c++ or .cxx. I prefer *.cc.

    Last edited by flp1969; 07-14-2019 at 07:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. build rpm form a csource rpmbuild returns a error
    By rusyoldguy in forum C Programming
    Replies: 1
    Last Post: 06-21-2019, 04:14 AM
  2. Error while creating socket....
    By sanddune008 in forum C Programming
    Replies: 3
    Last Post: 09-26-2012, 07:15 AM
  3. Error in creating socket in a client (UDP)
    By ferenczi in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-27-2008, 11:11 AM
  4. Error when creating file
    By smarta_982002 in forum C++ Programming
    Replies: 4
    Last Post: 01-30-2008, 04:22 PM
  5. Creating Threads - Compilation error
    By ashu12 in forum C Programming
    Replies: 3
    Last Post: 10-25-2002, 02:43 AM

Tags for this Thread