I have the following makefile in my c++ program
#All Targets
all: bin/cTrace
bin/cTrace: bin/main.o bin/agent.o bin/session.o bin/graph.o bin/tree.o
#echo 'Building target: main'
#echo 'Invoking: C++ Linker'
g++ -o bin/cTrace bin/main.o bin/agent.o bin/graph.o bin/tree.o bin/session.o
#echo 'Finished building target: main'
#echo ' '
bin/main.o: src/main.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/main.o src/main.cpp
bin/agent.o: src/Agent.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/agent.o src/Agent.cpp
bin/session.o: src/Session.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/session.o src/Session.cpp
bin/graph.o: src/Graph.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/graph.o src/Graph.cpp
bin/tree.o: src/Tree.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/tree.o src/Tree.cpp
but when I write at the terminal: make I get the following message:
'makefile:7 *** missing separator stop'
I have been looking for the problem and I understand that the main cause is that the text editor may change tab to space so I check throughout all my makefile and I hadn't found any problem.
What else can cause it?
edit:
after I compile cat -e -t -v Makefile I get the following result:
spl211#spl211:~/CLionProjects/cTrace$ cat -e -t -v makefile
#All Targets^M$
all: bin/cTrace^M$
^M$
bin/cTrace: bin/main.o bin/agent.o bin/session.o bin/graph.o bin/tree.o^M$
#echo 'Building target: main'^M$
#echo 'Invoking: C++ Linker'^M$
g++ -o bin/cTrace bin/main.o bin/agent.o bin/graph.o bin/tree.o bin/session.o^M$
#echo 'Finished building target: main'^M$
#echo ' '^M$
^M$
bin/main.o: src/main.cpp^M$
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/main.o src/main.cpp^M$
^M$
bin/agent.o: src/Agent.cpp^M$
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/agent.o src/Agent.cpp^M$
^M$
bin/session.o: src/Session.cpp^M$
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/session.o src/Session.cpp^M$
^M$
bin/graph.o: src/Graph.cpp^M$
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/graph.o src/Graph.cpp^M$
^M$
bin/tree.o: src/Tree.cpp^M$
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/tree.o src/Tree.cpp
Related
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
I'm trying to compile a program I wrote, and the structure of the directory is the following:
ctrace > bin, include, src, makefile
bin>
include > Agent.h, Graph.h, Session.h, Tree.h
src> Agent.cpp, ContactTracer.cpp, Graph.cpp, main.cpp, Session.cpp, Tree.cpp, Virus.cpp
The error I'm getting is the following:
g++: error: bin/main.o: No such file or directory
Makefile:5: recipe for target 'cTrace' failed
make: *** [cTrace] Error 1
and this is my make file:
# All Targets
all: cTrace
cTrace: bin/Session.o bin/Agent.o bin/Graph.o bin/Tree.o bin/Virus.o bin/ContactTracer.o
#echo 'Building target: cTrace'
g++ bin/Session.o bin/Agent.o bin/Graph.o bin/Tree.o bin/Virus.o bin/ContactTracer.o bin/main.o -o cTrace
#echo 'target cTrace built successfully'
bin/main.o: src/main.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/main.o src/main.cpp
bin/Session.o: src/Session.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude -o bin/Session.o src/Session.cpp
bin/Agent.o: src/Agent.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Agent.cpp -o bin/Agent.o
bin/Graph.o: src/Graph.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Graph.cpp -o bin/Graph.o
bin/Tree.o: src/Tree.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Tree.cpp -o bin/Tree.o
bin/Virus.o: src/Virus.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/Virus.cpp -o bin/Virus.o
bin/ContactTracer.o: src/ContactTracer.cpp
g++ -g -Wall -Weffc++ -std=c++11 -c -Iinclude src/ContactTracer.cpp -o bin/ContactTracer.o
clean:
rm -rf bin/*.o cTrace
What could be the issue? all directories exist, my guess is that main.o is never generated but I can't see why as I don't fully understand all the flags in the makefile. Any tips on how to write a better makefile would be appreciated.
On a side note, I was able to run this exact same project using a CMake generated by CLion.
Thanks in advance.
You are missing bin/main.o as dependency for cTrace target. That's why make does not compile it, and resulting object file is missing. Just add bin/main.o to your list of dependencies in line 4.
Problem seems to be that bin/main.o should be mentioned as a dependency of cTrace
cTrace: bin/Session.o bin/Agent.o bin/Graph.o bin/Tree.o bin/Virus.o bin/ContactTracer.o bin/main.o
At present building cTrace doesn't cause the make file to try and build bin/main.o and so you get an error about a missing file.
When I try to use the cplex from IBM in my code and try to compile it, it shows the following error. I've provided the path to the cplex include file and the concert include file, but it still says 'ilcplex/ilocplex.h' file not found.
test: test.o assembly.pb.o Mesh.o Assembly.o Part.o Mate.o MateConnector.o ConstraintsMath.o ConnectGraph.o Model.o myOptimizer.o
g++ test.o assembly.pb.o Mesh.o Assembly.o Part.o Mate.o MateConnector.o ConnectGraph.o ConstraintsMath.o Model.o myOptimizer.o -o test -lprotobuf
test.o: test.cc assembly.pb.h Assembly.h Mate.h Model.h Mesh.h Part.h MateConnector.h ConnectGraph.h ConstraintsMath.h myOptimizer.h
g++ -Wall -g -std=c++11 -c test.cc
Mesh.o: Mesh.cc Mesh.h
g++ -Wall -g -std=c++11 -c Mesh.cc
Assembly.o: Assembly.cc Assembly.h Mate.h Model.h Mesh.h MateConnector.h ConnectGraph.h myOptimizer.h
g++ -Wall -g -std=c++11 -c Assembly.cc
Part.o: Part.cc Part.h Model.h Mesh.h MateConnector.h
g++ -Wall -g -std=c++11 -c Part.cc
Mate.o: Mate.cc Mate.h Model.h Mesh.h MateConnector.h
g++ -Wall -g -std=c++11 -c Mate.cc
assembly.pb.o: assembly.pb.cc assembly.pb.h
g++ -Wall -g -std=c++11 -c assembly.pb.cc
MateConnector.o: MateConnector.cc MateConnector.h ConstraintsMath.h Model.h
g++ -Wall -g -std=c++11 -c MateConnector.cc
ConstraintsMath.o: ConstraintsMath.cc ConstraintsMath.h
g++ -Wall -g -std=c++11 -c ConstraintsMath.cc
ConnectGraph.o: ConnectGraph.cc ConnectGraph.h Part.h MateConnector.h
g++ -Wall -g -std=c++11 -c ConnectGraph.cc
Model.o: Model.cc Model.h Mesh.h Mate.h
g++ -Wall -g -std=c++11 -c Model.cc
myOptimizer.o: myOptimizer.cc myOptimizer.h
g++ -DIL_STD -I/Applications/CPLEX_Studio129/cplex/include -I/Applications/CPLEX_Studio129/concert/include \
-Wall -g -std=c++11 -c myOptimizer.cc \
-L/Applications/CPLEX_Studio129/concert/lib/x86-64_osx/static_pic\
-L/Applications/CPLEX_Studio129/cplex/lib/x86-64_osx/static_pic \
-lcplex
clean:
rm -rf test *.o *~ *.dSYM
The error it showed is:
c++ -c -o myOptimizer.o myOptimizer.cc
myOptimizer.cc:4:10: fatal error: 'ilcplex/ilocplex.h' file not found
#include <ilcplex/ilocplex.h>
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [myOptimizer.o] Error 1
I'm getting errors when trying to run the HTTP server example that comes with the source of the boost library, under the path: boost_1_59_0/libs/asio/example/cpp11/http/server/.
I already ran this following commands in the boost_1_59_0 directory:
$ ./bootstrap.sh
$ sudo ./bjam install
$ sudo ./b2 install
After installing all targets, i tried to compile the main.cpp and the server.cpp with this command: g++ -std=c++0x -o main main.cpp -I "/home/user/Desktop/boost_1_59_0" -L "/home/user/Desktop/boost_1_59_0/libs/" -lboost_system.
Any suggestion on how to compile this server example?
I linked all files from the boost_1_59_0/libs/asio/example/cpp11/http/server/ folder after the main.cpp, as #Richard Hodges suggested. It still didn't work, i got errors concerning lpthread, so i added it to the compiling options. The program compiled but it failed the execution, returning an error saying that it didn't find the library libboost_system.so.1.59.0. I tried linking the folders with -L /path/to/library but it didn't work.
Solution:
My compilation command:
g++ -std=gnu++0x -o main main.cpp server.cpp connection.cpp connection_manager.cpp reply.cpp mime_types.cpp request_handler.cpp request_parser.cpp -I "/home/user/Desktop/boost_1_59_0" -lboost_system -lpthread
I solved it with this commands:
$ LD_LIBRARY_PATH="/usr/local/lib/"
$ sudo ldconfig
And then I just ran the executable and it worked!
Here's a simple makefile I just concocted that works:
all:server
CPPFLAGS+=-std=c++11 -Wall -pedantic
CPPFLAGS+=-g -O2
CPPFLAGS+=-pthread
LDFLAGS+=-lboost_system
%.o:%.cpp
$(CXX) $(CPPFLAGS) $^ -c -o $#
server:$(patsubst %.cpp,%.o,$(wildcard *.cpp))
$(CXX) $(CPPFLAGS) $^ -o $# $(LDFLAGS)
It runs make:
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.cpp -c -o connection.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection_manager.cpp -c -o connection_manager.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread main.cpp -c -o main.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread mime_types.cpp -c -o mime_types.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread reply.cpp -c -o reply.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_handler.cpp -c -o request_handler.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_parser.cpp -c -o request_parser.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread server.cpp -c -o server.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.o connection_manager.o main.o mime_types.o reply.o request_handler.o request_parser.o server.o -o server -lboost_system
And the test program runs:
$ ./server 0.0.0.0 9889 . &
$ GET http://localhost:9889/main.cpp > main.cpp.0
Check the files
$ md5sum main.cpp*
be5dc1c26b5942101a7895de6baedcee main.cpp
be5dc1c26b5942101a7895de6baedcee main.cpp.0
Don't forget to kill the server when you're done
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