C++: Makefile: object files not compiling? make then says objects not found - c++

So, client.o and server.o are not being compiled... but the make file doesn't error...
I've checked the directory where all the code is and the sub folders. but client and server .o just aren't there... =\
here is my make file:
main_objects = src/main.o src/fann_utils.o src/Config.o
network_objects = src/neural_network_basic.o
hash_objects = src/hashes.o src/hashes/Murmur.o
cloud_objects = src/cloud/client.o src/cloud/server.o
all_objects = $(main_objects) $(hash_objects) $(network_objects) $(cloud_objects)
all: hPif clean
hPif : $(all_objects)
g++ -o hPif $(all_objects) -lfann -L/usr/local/lib
src/cloud/client.o : src/cloud/chat_client.cpp src/cloud/chat_message.hpp
g++ -c src/cloud/chat_client.cpp
src/cloud/server.o : src/cloud/chat_server.cpp src/cloud/chat_message.hpp src/cloud/chat_server.h
g++ -c src/cloud/chat_server.cpp
neural_network_basic.o : src/neural_network_basic.cpp src/neural_network_basic.h
g++ -c src/neural_network_basic.cpp
hashes/Murmur.o : src/hashes/Murmur.cpp src/hashes/Murmur.h
g++ -c src/hashes/Murmur.cpp
Config.o : src/Config.cpp src/Config.h
g++ -c src/Config.cpp
hashes.o : src/hashes.cpp src/hashes.h
g++ -c src/hashes.cpp
fann_utils.o: src/fann_utils.cpp fann_utils.h
g++ -c src/fann_utils.cpp
main.o: src/main.cpp src/main.h
g++ -c src/main.cpp
clean:
rm -rf src/cloud/*.o
rm -rf src/hashes/*.o
rm -rf src/*.o
rm -rf *.o
Console output looks like this:
g++ -c -o src/main.o src/main.cpp
g++ -c -o src/fann_utils.o src/fann_utils.cpp
g++ -c -o src/Config.o src/Config.cpp
g++ -c -o src/hashes.o src/hashes.cpp
g++ -c -o src/hashes/Murmur.o src/hashes/Murmur.cpp
g++ -c -o src/neural_network_basic.o src/neural_network_basic.cpp
g++ -c src/cloud/chat_client.cpp
g++ -c src/cloud/chat_server.cpp
g++ -o hPif src/main.o src/fann_utils.o src/Config.o src/hashes.o src/hashes/Murmur.o src/neural_network_basic.o src/cloud/client.o src/cloud/server.o -lfann -L/usr/local/lib
i686-apple-darwin10-g++-4.2.1: src/cloud/client.o: No such file or directory
i686-apple-darwin10-g++-4.2.1: src/cloud/server.o: No such file or directory
make: *** [hPif] Error 1

g++ -c src/cloud/chat_client.cpp will build an object file called chat_client.o, not client.o. Either add -o $# to the rule to create an object file with the same name as the target, or rename the file to chat_client.o everywhere it's mentioned in the makefile.

Related

c++ makefile cant find directories

I am trying to run makefile but I cant make him find the files I add to it unless I put full path of the file: /home/"user_name"/CLionProjects/Ass1/src/main.cpp
I try to run the makefile when I am in Ass1 so as much that I understand the makefile should find the main.cpp .
Would love to know where I am wrong here, thank you.
what I write:
all: clean compile link
link:
g++ -o /bin/main /home/daniel/CLionProjects/Ass1/bin/main.o /home/daniel/CLionProjects/Ass1/bin/Workout.o /home/daniel/CLionProjects/Ass1/bin/Trainer.o /home/daniel/CLionProjects/Ass1/bin/Studio.o
compile:
g++ -g -Wall -Weffc++ -c -o bin/main.o /home/daniel/CLionProjects/Ass1/src/main.cpp
g++ -g -Wall -Weffc++ -c -o bin/Studio.o /home/daniel/CLionProjects/Ass1/src/Studio.cpp
g++ -g -Wall -Weffc++ -c -o bin/Workout.o /home/daniel/CLionProjects/Ass1/src/Workout.cpp
g++ -g -Wall -Weffc++ -c -o bin/Trainer.o /home/daniel/CLionProjects/Ass1/src/Trainer.cpp
clean:
rm -f bin/*
what I want to write and cant:
all: clean compile link
link:
g++ -o /bin/main /bin/main.o /bin/Workout.o /bin/Trainer.o /bin/Studio.o
compile:
g++ -g -Wall -Weffc++ -c -o bin/main.o /src/main.cpp
g++ -g -Wall -Weffc++ -c -o bin/Studio.o /src/Studio.cpp
g++ -g -Wall -Weffc++ -c -o bin/Workout.o /src/Workout.cpp
g++ -g -Wall -Weffc++ -c -o bin/Trainer.o /src/Trainer.cpp
clean:
rm -f bin/*
the error I get:
rm -f bin/*
g++ -g -Wall -Weffc++ -c -o bin/main.o /src/main.cpp
g++: error: /src/main.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
make: *** [makefile:7: compile] Error 1

c++ "fatal error C1083: Cannot open include file: 'curl/curl.h': No such file or directory"

I want to use the https://github.com/tensaix2j/binacpp (a Binance c++ library) and I'm getting the same error again and again. I changed the MakeFile in the library to the correct paths but yeah... Here is my MakeFile:
libcurl_dir=../lib/libcurl-7.56.0
libcurl_include=${libcurl_dir}/include
libcurl_lib=${libcurl_dir}/lib
jsoncpp_dir=../lib/jsoncpp-1.8.3
jsoncpp_include=${jsoncpp_dir}/include
jsoncpp_src=${jsoncpp_dir}/src
libwebsockets_dir=../lib/libwebsockets-2.4.0
libwebsockets_include=${libwebsockets_dir}/include
libwebsockets_lib=${libwebsockets_dir}/lib
libbinacpp_dir=../lib/libbinacpp
libbinacpp_include=${libbinacpp_dir}/include
libbinacpp_lib=${libbinacpp_dir}/lib
build_dir=../lib/libbinacpp/lib
objects=$(build_dir)/jsoncpp.o $(build_dir)/binacpp_utils.o
$(build_dir)/binacpp_logger.o $(build_dir)/binacpp.o $(build_dir)/binacpp_websocket.o
build_include=../lib/libbinacpp/include
$(build_dir)/libbinacpp.so: $(objects)
g++ -I$(libcurl_include) -I$(jsoncpp_include) I$(libwebsockets_include) \
-L$(libcurl_lib) \
-L$(libwebsockets_lib) \
$(objects) \
-shared \
-lcurl -lcrypto -lwebsockets -fPIC -o $#
# Make a new copy of the header too
cp *.h $(build_include)
$(build_dir)/binacpp.o: binacpp.cpp binacpp.h
g++ -I$(libcurl_include) -I$(jsoncpp_include) -c binacpp.cpp -fPIC -o $(build_dir)/binacpp.o
$(build_dir)/binacpp_websocket.o: binacpp_websocket.cpp binacpp_websocket.h
g++ -I$(libwebsockets_include) -I$(jsoncpp_include) -c binacpp_websocket.cpp -fPIC -o $(build_dir)/binacpp_websocket.o
$(build_dir)/binacpp_logger.o: binacpp_logger.cpp binacpp_logger.h
g++ -c binacpp_logger.cpp -fPIC -o $(build_dir)/binacpp_logger.o
$(build_dir)/binacpp_utils.o: binacpp_utils.cpp binacpp_utils.h
g++ -c binacpp_utils.cpp -fPIC -o $(build_dir)/binacpp_utils.o
$(build_dir)/jsoncpp.o: $(jsoncpp_src)/jsoncpp.cpp
g++ -I$(jsoncpp_include) -c $(jsoncpp_src)/jsoncpp.cpp -fPIC -o $(build_dir)/jsoncpp.o
clean:
rm $(build_dir)/*.o
rm $(build_dir)/*.so
If I'm inserting the paths like:
#include "../../libcurl-7.56.0/include/curl/curl.h"
instead of:
#include <curl/curl.h>
then it works but I cant change it for all includes.
Here's the Tree:
binacpp
-example
-lib
--jsoncpp-1.8.3
--libbinacpp
---include
----binacpp.h (File with include issue)
----binacpp_logger.h
----binacpp_websocket.h
----binacpp_utils.h
---lib
--libcurl-7.56.0
--(here's some other not important stuff)
-src
--MakeFile
--(here's some other not important stuff)

Makefile giving "No such file or directory"

So I just got through a bunch of compiler issues and finally make runs well for the most part, however now I am getting an error
g++ prog4.cc
g++ -o lextest prog4.o Lexer.o Token.o
g++: prog4.o: No such file or directory
make: *** [lextest] Error 1
This is my makefile
OBJ = prog4.o Lexer.o Token.o
LEXER = Lexer.cc Lexer.h
TOKEN = Token.cc Token.h
OPTS = -g -c -Wall -Werror
lextest: $(OBJ)
g++ -o lextest $(OBJ)
prog4.o: prog4.cc $(LEXER) $(TOKEN)
g++ $(OPTS) prog4.cc
Lexer.o: Lexer.cc Lexer.h
g++ $(OPTS) Lexer.cc
Token.o: Token.cc Token.h
g++ $(OPTS) Token.cc
clean:
rm -f *.o *~
Can anyone see any obvious errors in the makefile or would this error be generated by an issue in prog4.cc?
Pretty new to C++, so I hope this is just some simple error that I can fix.
Thanks!
You are missing the -c and -o options to g++
g++ -c -o prog4.o $(OPTS) prog4.cc

Create a debug file when compiling each source file separately using makefile

I am doing a c++ project with multiple source files and trying to get used to using makefiles. I want to be able to debug this program with gdb. If I use the following command in Terminal to compile, it works fine:
g++ -o main -g *.cpp
But if I just call make it doesn't generate a debug file (the .dSYM file) even though it compiles the program fine. I assume this has something to do with creating the individual object files first. Here is my makefile:
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main *.o -Wall -O2
main.o: main.cpp
g++ -c main.cpp
sort.o: sort.cpp sort.h
g++ -c sort.cpp
bubble.o: bubble.cpp bubble.h
g++ -c bubble.cpp
quickSort.o: quickSort.cpp quickSort.h
g++ -c quickSort.cpp
rbs.o: rbs.cpp rbs.h
g++ -c rbs.cpp
clean:
rm *.o
How do I create the main.dSYM debug file when using a makefile like this?
If you want the debug files, you must compile all of the components with -g.
The crude way to do this would be to add -g to every object rule:
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main *.o -Wall -O2
main.o: main.cpp
g++ -c -g main.cpp
sort.o: sort.cpp sort.h
g++ -c -g sort.cpp
bubble.o: bubble.cpp bubble.h
g++ -c -g bubble.cpp
quickSort.o: quickSort.cpp quickSort.h
g++ -c -g quickSort.cpp
rbs.o: rbs.cpp rbs.h
g++ -c -g rbs.cpp
But that doesn't leave you the option of building without debug information. And there's a lot of redundancy in this makefile. Let's take this in stages. First, we put in automatic variables to simplify the rules:
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main $^ -Wall -O2
main.o: main.cpp
g++ -c -g $<
sort.o: sort.cpp sort.h
g++ -c -g $<
bubble.o: bubble.cpp bubble.h
g++ -c -g $<
quickSort.o: quickSort.cpp quickSort.h
g++ -c -g $<
rbs.o: rbs.cpp rbs.h
g++ -c -g $<
Now we see that all of the *.o rules have the same command, which reminds us that Make already knows how to build foo.o from foo.cpp, with a command that looks like:
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c
So all we have to do is add -g to CXXFLAGS, and we can omit the commands entirely:
CXXFLAGS += -g
all: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o main $^ -Wall -O2
sort.o: sort.h
bubble.o: bubble.h
quickSort.o: quickSort.h
rbs.o: rbs.h
Now that that's in order, we can set up two top-level targets, main and debug, and change CXXFLAGS only for the latter:
debug: CXXFLAGS += -g
main debug: main.o sort.o bubble.o quickSort.o rbs.o
g++ -g -o $# $^ -Wall -O2
sort.o: sort.h
bubble.o: bubble.h
quickSort.o: quickSort.h
rbs.o: rbs.h
You can improve this even more, but that should get you started.

How do I use g++ to create object file with a specific name

I am making a makefile and one of the targets is exptrtest.o how do I use g++ to create an objectfile with that name, the name of my cpp file is exprtest.cpp not exptrtest.cpp?
exptrtest.o: exprtest.cpp
g++ -Wall -g -c exprtest.cpp
to make it more clear, this is my makefile:
all: exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
exptrtest.o: exprtest.cpp
g++ -Wall -g -c exptrtest.o exprtest.cpp
driver.o: driver.cpp scanner.hpp driver.hpp
g++ -Wall -g -c driver.cpp
parser.tab.o: parser.tab.hpp parser.tab.cpp
bison parser.ypp
g++ -Wall -g -c parser.tab.cpp
scanner.o: scanner.cpp scanner.hpp
flex -t scanner.ll > scanner.cpp
g++ -Wall -g -c scanner.cpp
clean:
rm parser.tab.hpp parser.tab.cpp scanner.cpp
I'm getting the error:
"g++: error: exptrtest.o: No such file or directory
make: * [exprtest] Error 1"
Use the -o option in conjunction with -c.
exptrtest.o: exprtest.cpp
g++ -Wall -g -c exprtest.cpp -o exptrtest.o