fatal error: opening dependency file C++ - c++

I am getting the fatal error while compiling a program (using make). Is it because of some permission issues?
make -C src/hash_function
make[1]: Entering directory `....../src/hash_function'
g++ -std=c++11 -Wall -pedantic -funsigned-char -msse4.2 -I "/export/SOFTWARE/boost_1_61_0" -MMD -c farmhash.cpp -o ../../obj/farmhash.o
farmhash.cpp:1965:1: fatal error: opening dependency file ../../obj/farmhash.d: No such file or directory
} // namespace NAMESPACE_FOR_HASH_FUNCTIONS
^
compilation terminated.
make[1]: *** [../../obj/farmhash.o] Error 1
The Makefile looks like the following and I am bit confused how I handle ../../obj/farmhash.o
CC = g++
CCFLAGS = -std=c++11 -Wall -pedantic -funsigned-char -msse4.2
LDFLAGS =
INCLUDE = -I "/export/SOFTWARE/boost_1_61_0"
EXE = main
AUXFLAGS =
OPTFLAGS =
LIBS = main.a index.a hash_map.a hash_function.a utils.a
LIBS := $(addprefix lib/,$(LIBS))
all: build/$(EXE)
run: all
clear
./build/$(EXE) $(INPUT) $(QUERIES)
build/$(EXE): libs
$(CC) $(LDFLAGS) $(OPTFLAGS) $(LIBS) $(AUXFLAGS) -o $#
libs:
$(MAKE) -C src/hash_function
$(MAKE) -C src/hash_map
$(MAKE) -C src/index
$(MAKE) -C src/main
$(MAKE) -C src/utils
.PHONY: clean
clean:
rm -f build/main
rm -f lib/*.a
rm -f obj/*.d obj/*.o
rebuild: clean all

Related

Why is my makefile not generating the .exe?

I've started to code on Visual Studio Code (I was coding on IDE before) and to make project I learned that you need to do a makefile to link the file in your project.
So i searched a lot of tuto and i come up with this:
DEBUG=yes
CXX=g++
ifeq ($(DEBUG),yes)
CXXFLAGS=-W -Wall -ansi -pedantic -g
LDFLAGS=
else
CXXFLAGS=-W -Wall -ansi -pedantic
LDFLAGS=
endif
OBJDIR:= obj
EXECDIR:= bin
VPATH=src
EXEC=$(VPATH)/prog
SRC= $(wildcard src/*.cpp)
OBJECTS= main.o hello.o
OBJ= $(addprefix $(OBJDIR)/,$(OBJECTS))
all : $(EXEC)
ifeq ($(DEBUG),yes)
#echo "Generation en mode debug"
else
#echo "Generation en mode release"
endif
$(EXECDIR)/$(EXEC): $(OBJ) | $(EXECDIR)
$(CXX) $(CXXFLAGS) -o $# $^
$(EXECDIR):
mkdir $(EXECDIR)
$(OBJDIR)/main.o: src/hello.hpp
$(OBJDIR)/hello.o: src/hello.hpp
$(OBJDIR)/%.o: src/%.cpp | $(OBJDIR)
#$(CXX) -o $# -c $< $(CXXFLAGS)
$(OBJDIR):
mkdir $(OBJDIR)
.PHONY: clean mrproper
clean:
#rm -rf *.o
mrproper: clean
#rm -rf $(EXEC)
but I have a little problem ...
xe: cannot open output file /prog.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [makefile:26: /prog] Error 1
And i really don't know why it is doing this

math.h not found when using llvm

I'm trying to build a python wrapper using the following Makefile:
CC=/usr/local/opt/llvm/bin/clang
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Linux)
LAPACKLDFLAGS=/usr/lib64/atlas/libsatlas.so # single-threaded blas
#LAPACKLDFLAGS=/usr/lib64/atlas/libtatlas.so # multi-threaded blas
#BLAS_THREADING=-D MULTITHREADED_BLAS # remove this if wrong
endif
ifeq ($(OS_NAME),Darwin) # Mac OS X
LAPACKLDFLAGS=-framework Accelerate # for OS X
endif
LAPACKCFLAGS=-Dinteger=int $(BLAS_THREADING)
STATICLAPACKLDFLAGS=-fPIC -Wall -g -fopenmp -static -static-libstdc++ /home/lear/douze/tmp/jpeg-6b/libjpeg.a /usr/lib64/libpng.a /usr/lib64/libz.a /usr/lib64/libblas.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgfortran.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libquadmath.a # statically linked version
CFLAGS= -fPIC -Wall -g -std=c++11 $(LAPACKCFLAGS) -fopenmp -DUSE_OPENMP -O3
LDFLAGS=-fPIC -Wall -g -ljpeg -lpng -fopenmp
CPYTHONFLAGS=-I/usr/include/python2.7
SOURCES := $(shell find . -name '*.cpp' ! -name 'deepmatching_matlab.cpp')
OBJ := $(SOURCES:%.cpp=%.o)
HEADERS := $(shell find . -name '*.h')
all: deepmatching
.cpp.o: %.cpp %.h
$(CC) -o $# $(CFLAGS) -c $+
deepmatching: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(LDFLAGS) $(LAPACKLDFLAGS)
deepmatching-static: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(STATICLAPACKLDFLAGS)
python: $(HEADERS) $(OBJ)
# swig -python $(CPYTHONFLAGS) deepmatching.i # not necessary, only do if you have swig compiler
/usr/local/opt/llvm/bin/clang $(CFLAGS) -c deepmatching_wrap.c $(CPYTHONFLAGS)
/usr/local/opt/llvm/bin/clang -shared $(LDFLAGS) $(LAPACKLDFLAGS) deepmatching_wrap.o $(OBJ) -o _deepmatching.so $(LIBFLAGS)
clean:
rm -f $(OBJ) deepmatching *~ *.pyc .gdb_history deepmatching_wrap.o _deepmatching.so deepmatching.mex???
Previously, CC was set to g++, however, when I tried to build it like this, I'd get "ERROR: clang: error: unsupported option '-fopenmp".
Now I installed "brew install llvm" as this comes with the -fopenmp option. The unsupported error is resolved for now, but now the compiler doesn't seem to find a header file:
(base) MacBook-Pro-van-Brent:deepmatching BrentDeHauwere$ make python
/usr/local/opt/llvm/bin/clang -o hog.o -fPIC -Wall -g -std=c++11 -Dinteger=int -fopenmp -DUSE_OPENMP -O3 -I/usr/local/opt/llvm/include -c hog.cpp
In file included from hog.cpp:18:
In file included from ./std.h:20:
/usr/local/opt/llvm/bin/../include/c++/v1/math.h:300:15: fatal error: 'math.h' file not found
#include_next <math.h>
^~~~~~~~
1 error generated.
make: *** [hog.o] Error 1
I've tried setting options (I might have set them incorrectly) like -L/usr/local/opt/llvm/lib and -I/usr/local/opt/llvm/include, but no result so far. Any idea how I could point the compiler to the right direction for the header files?
Try running xcode-select —install in your terminal. This installs the xcode command line tools which should also install system headers files (as part of the macos sdk) and set your system include paths.

I get a "attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libc++abi.a'" error when I try to statically link libc++abi.a

environment
ubuntu 18.04 (a virtual environment created by vagrant)
gcc5.5.0
I'm trying to build my own little OS.
I'm writing the kernel in C++/NASM.
I'm going to compile each of the several C++ files that make up the kernel and then link them together to create an executable file. (This is because the entry point of my own kernel is not "main", so I dare not link at the same time as compiling)
Error
The compilation of each C++ file will run without any problems and each object file will be created.
However, I get the following error in linking the object files.
But I understand that a ".a" file is a static object, not a dynamic object, so I can not understand why I'm getting this error.
I'd appreciate it if you could let me know.
ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libc++abi.a'
Here's the full text of the log
mkdir -p ./obj
g++ -O2 -g -MMD -Wall -I./include -o obj/hoge.o -c src/hoge.cpp
mkdir -p ./obj
g++ -O2 -g -MMD -Wall -I./include -o obj/huga.o -c src/huga.cpp
mkdir -p ./obj
g++ -O2 -g -MMD -Wall -I./include -o obj/piyo.o -c src/piyo.cpp
mkdir -p ./obj
nasm -f elf64 -o obj/assm.o src/assm.asm
ld --entry <ENTRY_POINT> --static -o ./ELF/kernel.elf ./obj/hoge.o ./obj/huga.o ./obj/piyo.o ./obj/assm.o -lc -lc++ -lc++abi -L/usr/lib/x86_64-linux-gnu
ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libc++abi.a'
Makefile:12: recipe for target 'ELF/kernel.elf' failed
make: *** [ELF/kernel.elf] Error 1
Makefile
COMPILER = g++
CFLAGS = -O2 -g -MMD -Wall
INCLUDE = -I./include
TARGET = ./ELF/kernel.elf
SRCDIR = ./src
SOURCES := $(shell find $(SRCDIR) -name *.cpp -or -name *.c -or -name *.asm)
OBJDIR = ./obj
OBJECTS = $(OBJDIR)/hoge.o $(OBJDIR)/huga.o $(OBJDIR)/piyo.o $(OBJDIR)/assm.o
DEPENDS = $(OBJECTS:.o=.d)
LDFLAGS = --entry <ENTRY_POINT> --static
$(TARGET): $(OBJECTS)
ld $(LDFLAGS) -o $(TARGET) $(OBJECTS) -lc -lc++ -lc++abi -L/usr/lib/x86_64-linux-gnu
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
-mkdir -p $(OBJDIR)
$(COMPILER) $(CFLAGS) $(INCLUDE) -o $# -c $<
$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-mkdir -p $(OBJDIR)
nasm -f elf64 -o $# $<
all: clean $(TARGET)
clean:
rm -rf $(OBJECTS) $(DEPENDS) $(TARGET)
-include $(DEPENDS)

'SDL2/SDL_image.h' file not found

I'm programming on Xcode. I include SDL_image.h as
#include <SDL2/SDL_image.h>
and it says 'SDL2/SDL_image.h' file not found
I have installed and linked binary with libraries both SDL2.framework and SDL2_image.framework.
I used a Makefile to compile and there is an error: fatal error: 'SDL2/SDL_image.h' file not found
Here is my Makefile
# set the compiler
CC := clang
# set the compiler flags
CXXFLAGS = -std=c++14 -Wall -MMD -Werror=vla pkg-config --cflags --libs sdl2 `-L/Library/Frameworks/ sdl2-config --libs --cflags` -ggdb3 -O0 --std=c99 -Wall -l SDL2_image -lm
# add source files here
SRCS := main.cpp #file-name.c
# generate names of object files
OBJS := $(SRCS:.c=.o)
# name of executable
EXEC := sdl #name your executable file
# default recipe
all: $(EXEC)
showfont: showfont.c Makefile
$(CC) -o $# $#.c $(CFLAGS) $(LIBS)
glfont: glfont.c Makefile
$(CC) -o $# $#.c $(CFLAGS) $(LIBS)
# recipe for building the final executable
$(EXEC): $(OBJS) $(HDRS) Makefile
$(CC) -o $# $(OBJS) $(CFLAGS)
# recipe for building object files
#$(OBJS): $(#:.o=.c) $(HDRS) Makefile
# $(CC) -o $# $(#:.o=.c) -c $(CFLAGS)
# recipe to clean the workspace
clean:
rm -f $(EXEC) $(OBJS)
.PHONY: all clean

Makefile is not able to find *.o files to make the .exe

This is my directory structure:
$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
|-Build
|---Bin
|-Include
|-Lib
|-Source
This is my makefile:
Gaurav#Gaurav-PC /cygdrive/d/Pizza/Build
$ pwd
/cygdrive/d/Pizza/Build
Gaurav#Gaurav-PC /cygdrive/d/Pizza/Build
$ ls
Bin Makefile
Gaurav#Gaurav-PC /cygdrive/d/Pizza/Build
$vim Makefile
INCLUDES= ./../Include
OBJDIR= ./Bin
SRCDIR= ./../Source
vpath %.h $(INCLUDES)
vpath %.cpp $(SRCDIR)
vpath %.o $(OBJDIR)
CXX= g++
CXXFLAGS= -Wall -c -I$(INCLUDES)
OBJECTS= Pizza.o PizzaClassMain.o
Pizza: $(OBJECTS)
$(CXX) -Wall $^ -o $(OBJDIR)/$#
PizzaClassMain.o:PizzaClassMain.cpp Pizza.h
$(CXX) $(CXXFLAGS) $< -o $(OBJDIR)/$#
Pizza.o: Pizza.cpp Pizza.h
$(CXX) $(CXXFLAGS) $< -o $(OBJDIR)/$#
.PHONY: clean
clean:
rm -f $(OBJDIR)/*.o $(OBJDIR)/*.exe *~ .Makefile.un~
I am getting below error:
$ make
g++ -Wall -c -I./../Include ./../Source/Pizza.cpp -o ./Bin/Pizza.o
g++ -Wall -c -I./../Include ./../Source/PizzaClassMain.cpp -o ./Bin/PizzaClassMain.o
g++ -Wall Pizza.o PizzaClassMain.o -o ./Bin/Pizza
g++: error: Pizza.o: No such file or directory
g++: error: PizzaClassMain.o: No such file or directory
g++: fatal error: no input files
compilation terminated.
Makefile:18: recipe for target 'Pizza' failed
make: *** [Pizza] Error 1
I have put vpath %.o $(OBJDIR) in my Makefile but still rule: Pizza is not able to find Pizza.o & PizzaClassMain.o though they are being created correctly in directory ./Bin by the rules Pizza.o & PizzaClassMain.o
If I manually run g++ -Wall g++ -Wall Pizza.o PizzaClassMain.o -o Pizza from directory ./Bin then it works fine.
I am not able to figure out why the rule Pizza is not able to find input files?
Can anyone please help?
PS: This Makefile did compile successfully once or twice out of say 40 times. Are there some issues with cygwin package make?
Your objects should be:
OBJECTS= ./Bin/Pizza.o ./Bin/PizzaClassMain.o
These objects are compiled successfully as the rule PIZZA: $(OBJECTS) finds correct rules named "Pizza.o" and "PizzaClassMain.o". These are only names of rules, not actual filenames. When Make utility looks for ./Build/Pizza.o, this file does not exist and is not found. It was created in the ./Build/Bin directory.
Below changes in rule resolved the issue:
Pizza: $(OBJECTS)
$(CXX) -Wall $(addprefix $(OBJDIR)/,$^) -o $(OBJDIR)/$#
Very nice article http://mad-scientist.net/make/vpath.html as pointed by OliCharlesworth.