title: How to add cap_net_raw capability via a Makefile to c++ executable file on linux
body: <p>I have created a c++ that runs on Linux and on of its functionalities is to ping on a provided host. The ping has been based on relevant Poco libraries. However in order to run successfully on linux the produced c++ executable file should have the <code>cap_net_raw</code> capability set by giving</p>
  
  <pre><code>setcap cap_net_raw=ep /bin/C++_APP
  </code></pre>
  
  <p>I have also used the following Makefile based on an example I found by googling.</p>
  
  <pre><code>CC := g++ 
  
  # Folders
  SRCDIR := src
  BUILDDIR := build
  TARGETDIR := bin
  
  # Targets
  EXECUTABLE := C++_APP
  TARGET := $(TARGETDIR)/$(EXECUTABLE)
  
  SRCEXT := cpp
  SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
  OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
  CFLAGS := -c -Wall
  INC := -I include -I /usr/local/include
  LIB := -L /usr/local/lib -lPocoFoundation -lPocoNet -lPocoUtil 
  
  $(TARGET): $(OBJECTS)
  @echo " Linking..."
  @echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB)
  
  $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
  @mkdir -p $(BUILDDIR)
  @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $&lt;"; $(CC) $(CFLAGS) $(INC) -c -o $@ $&lt;
  
  clean:
  @echo " Cleaning..."; 
  @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
  
  .PHONY: clean 
  </code></pre>
  
  <p>I added the following command as the last build command</p>
  
  <pre><code>@echo "Setting Capabilities"; sudo setcap cap_net_raw=ep   $(TARGETDIR)/$(EXECUTABLE)  
  </code></pre>
  
  <p>However I got the following error:  </p>
  
  <blockquote>
    <p>Failed to set capabilities on file `bin/NPT' (Invalid argument) The
    value of the capability argument is not permitted for a file. Or the
    file is not a regular (non-symlink) file</p>
  </blockquote>
  
  <p>On the other hand when I give the command after the build of the c++ executable everything works fine. What am I doing wrong?</p>