Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Makefile - Directory structure

$
0
0
I'm attempting to create a project skeleton with the following directory structure:
/
Makefile
README

/bin
Binary files

/src
Contains source files (.cpp, .h)

/build
Contains the build files (.o)



My current Makefile attempt contains this:
# Project name, used to build executable
NAME := skeleton

# Builds list of .cpp files in src/ and src/*/
SOURCES := $(wildcard src/**/*.cpp src/*.cpp)

# Builds object list from sources, substitues .cpp for .o
OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))

# Directories to include for source files
INCLUDE_DIRS := src

CPPFLAGS +=-g -Wall -Wextra
CPPFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
LDFLAGS += -Lbuild

.PHONY: all build clean

all: $(NAME)

$(NAME) : $(OBJECTS)
	$(LINK.cc) $(OBJECTS) -o /bin/$(NAME)

build:
	@mkdir -p build # Makes build dir

clean:
	rm -f /bin/$(NAME) # Just remove the binary file, not the bin directory
	rm -rf build # Remove the entire build directory



That's what I've been able to piece together from information on make from the web, however I'm running into some errors.

$ make
g++  -g -Wall -Wextra -Isrc -Lbuild  src/skeleton.o -o /bin/skelton
/usr/bin/ld: cannot open output file /bin/skelton: Permission denied
collect2: ld returned 1 exit status
make: *** [skelton] Error 1


After I run make, currently it creates the object file in the src/ directory, and no binary files are created. I've tried solving this using the make documentation, however it isn't clear cut. I'm unsure as to why I'm receiving a permission denied error, as I should have sufficient privileges.

Thanks.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>