For all of my c++ projects using netbeans, whenever I make a single small change the entire project is rebuilt. There must be a way to prevent this.
My build logs ends up looking like this:
mkdir -p build/Debug/CLang-Windows/_ext/237546996
rm -f "build/Debug/CLang-Windows/_ext/237546996/Sensor.o.d"
clang++ -g -std=gnu++11 -c -g -DSFML_STATIC -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/libsndfile/windows -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/libfreetype/windows -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/jpeg -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/AL -I../SFML/src -I../SFML/include -MMD -MP -MF "build/Debug/CLang-Windows/_ext/237546996/Sensor.o.d" -o build/Debug/CLang-Windows/_ext/237546996/Sensor.o ../SFML/src/SFML/Window/Sensor.cpp
mkdir -p build/Debug/CLang-Windows/_ext/237546996
rm -f "build/Debug/CLang-Windows/_ext/237546996/SensorManager.o.d"
clang++ -g -std=gnu++11 -c -g -DSFML_STATIC -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/libsndfile/windows -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/libfreetype/windows -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/jpeg -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/AL -I../SFML/src -I../SFML/include -MMD -MP -MF "build/Debug/CLang-Windows/_ext/237546996/SensorManager.o.d" -o build/Debug/CLang-Windows/_ext/237546996/SensorManager.o ../SFML/src/SFML/Window/SensorManager.cpp
mkdir -p build/Debug/CLang-Windows/_ext/237546996
rm -f "build/Debug/CLang-Windows/_ext/237546996/Touch.o.d"
clang++ -g -std=gnu++11 -c -g -DSFML_STATIC -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/libsndfile/windows -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/libfreetype/windows -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/jpeg -I/C/Users/izack_000/Documents/Programming/Projects/SynapseCpp/SFML/extlibs/headers/AL -I../SFML/src -I../SFML/include -MMD -MP -MF "build/Debug/CLang-Windows/_ext/237546996/Touch.o.d" -o build/Debug/CLang-Windows/_ext/237546996/Touch.o ../SFML/src/SFML/Window/Touch.cpp
As as you can see the object files are being removed before generating new files. Is there a setting for this or do I have to change the makefiles generated by netbeans?
Or perhaps there is something I accidentally turned on? (always clean?) Though I don't think its likely because its happening for both of my projects.
Edit: this seems to only happens on windows
Related
I have trouble creating dependency files while using make re. The %.d pattern rule will be called before fclean, also only the %.o pattern rule were called by all after fclean.
Here is the output when i use make vs make re:
mkdir -p srcs/depends
c++ -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes -MM srcs/tests.cpp -o srcs/depends/tests.d
c++ -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes -MM srcs/main.cpp -o srcs/depends/main.d
mkdir -p srcs/obj
c++ -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes -c srcs/main.cpp -o srcs/obj/main.o
c++ -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes -c srcs/tests.cpp -o srcs/obj/tests.o
c++ -lstdc++ srcs/obj/main.o srcs/obj/tests.o -o main
vs (make re)
rm -f -rv srcs/obj srcs/depends
srcs/obj/main.o
srcs/obj/tests.o
srcs/obj
srcs/depends/main.d
srcs/depends/tests.d
srcs/depends
rm -f main
mkdir -p srcs/obj
c++ -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes -c srcs/main.cpp -o srcs/obj/main.o
c++ -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes -c srcs/tests.cpp -o srcs/obj/tests.o
c++ -lstdc++ srcs/obj/main.o srcs/obj/tests.o -o main
My makefile:
NAME = main
SRCSDIR = srcs
SRCS = $(wildcard $(SRCSDIR)/*.cpp)
OBJSDIR = srcs/obj
OBJS = $(SRCS:$(SRCSDIR)/%.cpp=$(OBJSDIR)/%.o)
DEPENDSDIR = srcs/depends
DEPENDS = $(SRCS:$(SRCSDIR)/%.cpp=$(DEPENDSDIR)/%.d)
CPPFLAGS = -Wall -Werror -Wextra -Wshadow -std=c++98 -pedantic -Iincludes
DEPFLAGS = -MM
LDFLAGS = -lstdc++
all: $(NAME)
$(NAME): $(OBJS)
c++ $(LDFLAGS) $^ -o $#
$(OBJSDIR)/%.o: $(SRCSDIR)/%.cpp | $(OBJSDIR)
c++ $(CPPFLAGS) -c $< -o $#
$(DEPENDSDIR)/%.d: $(SRCSDIR)/%.cpp | $(DEPENDSDIR)
c++ $(CPPFLAGS) $(DEPFLAGS) $< -o $#
$(OBJSDIR) $(DEPENDSDIR):
mkdir -p $#
-include $(DEPENDS)
clean:
$(RM) -rv $(OBJSDIR) $(DEPENDSDIR)
fclean: clean
$(RM) $(NAME)
re: fclean all
.PHONY: all clean fclean re
I have looked up the gnu make documentation and couldn't find any details. (Maybe I don't know where to look it up). Anybody knows why or are there any other cleaner solution to this ? Thanks in advance
You are using the old-style header file generation method where make builds dependency files, then re-execs itself to read in the changed dependencies. So, when you run make first it parses all the .d files that currently exist (due to the include line) then it tries to rebuild the .d files, then if any have changed it re-execs, then it runs the rest of the makefile. Once it loads all the .d files and determines that they're up to date, make is done with them (for that invocation). If they later get deleted, it's not going to try to recreate them. They will be recreated the next time make is run.
In general, it's a bad idea to have a rule that runs clean and all as prerequisites. What if you enable parallel builds? Now make is running the clean and all rules in parallel. If you want to do this, you need to invoke them as sub-makes rather than via prerequisites, like this:
re:
$(MAKE) fclean
$(MAKE) all
This will ensure each target is built serially, even with parallel builds, and that make will be started from scratch to build all.
Another thing you should consider is using a more modern form of dependency generation; for example: https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
In my source directory, I type make main.o, which issues the command:
g++ -DHAVE_CONFIG_H -I. -I.. -std=gnu++11 -fpermissive -Wno-write-strings -O0 -g -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cc
mv -f .deps/main.Tpo .deps/main.Po
Some of this was created by me (-std=gnu++11 -fpermissive -Wno-write-strings -O0 -g) and some of it wasn't (-g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo)
Q1: How do I tell autotools to stop inserting -g -O2?
Q2: What's the deal with -MT main.o -MD -MP -MF .deps/main.Tpo? Is it necessary? Unnecessary? Can I get rid of it? If so, how?
Q3: How do I add to AM_CXXFLAGS via m4 macros seemlessly? The approach I have adopted so far is to define the macro m4/ax_debug.m4 as follows:
AC_DEFUN([AX_DEBUG], [
AC_ARG_WITH([debug],
[AS_HELP_STRING([--with-debug], [Enable debug (default is no)])],
[with_debug=$withval],
[with_debug=no])
AM_CONDITIONAL([WITH_DEBUG], [test "x$with_debug" = "xyes"])
AS_IF([test "x$with_debug" = "xyes"], [
AC_SUBST([DEBUG_CXXFLAGS], ["-O0 -g"])
])
AC_MSG_NOTICE([checking if debugging required ... $with_debug])
])dnl AX_DEBUG
and to use those flags within src/Makefile.am as follows:
AM_CXXFLAGS = ... $(DEBUG_CXXFLAGS)
Is there a way I can arrange it so that DEBUG_CXXFLAGSis added automatically?
Update (with possible answers): In regards to Q1, the answer appears to be to add the following line to configure.ac after AC_INIT(...):
: ${CXXFLAGS=""}
and delete $(DEBUG_CXXFLAGS) from src/Makefile.am.
In regards to Q2, I still have no idea what that's about.
In regards to Q3, the answer would appear to be to write
AC_SUBST([CXXFLAGS], ["$CXXFLAGS -O0 -g"])
instead of
AC_SUBST([DEBUG_CXXFLAGS], ["-O0 -g"])
I'm not sure if that's an "official" solution though.
i'm trying to use the boost_math libs on OS X (i'm not using Xcode), specifically the one containing the error function
I downloaded and compiled boost_1_60_0 myself (using bootstrap.sh and following the instructions.) I didn't use home-brew or something else, which might be why my installation seems so screwed up.
What i'm trying to include in my Szabo.hpp is this:
#include <boost/math/special_functions/erf.hpp>
My makefile goes like this:
LIB_FLAGS = -L/Documents/boost_1_60_0/stage/lib -lboost_math
ALL_OBJECTS = main.o Gaussienne.o Grille.o Szabo.o
all: $(ALL_OBJECTS)
g++ -o hydrogene $(ALL_OBJECTS) $(LIB_FLAGS)
Gaussienne.o: Gaussienne.cpp
g++ -o Gaussienne.o -c Gaussienne.cpp -W -Wall -ansi
main.o: Gaussienne.hpp Grille.hpp main.cpp Szabo.o
g++ -o main.o -c main.cpp -W -Wall -ansi
Grille.o: Grille.cpp Gaussienne.cpp
g++ -o Grille.o -c Grille.cpp -W -Wall -ansi
Szabo.o: Szabo.cpp Gaussienne.cpp
g++ -o Szabo.o -c Szabo.cpp -W -Wall -ansi
clean:
rm -rf *.o
mrproper: clean
rm -rf hydrogene
I get no linking error from g++, however i got:
In file included from Szabo.cpp:12:
./Szabo.hpp:21:10: fatal error: 'boost/math/special_functions/erf.hpp' file not found
#include <boost/math/special_functions/erf.hpp>
^
1 error generated.
Can you please provide help on how to fix this? Thanks in advance
Ok so apparently likes this, it works:
LIB_FLAGS = -L/Users/devolution/Documents/boost_1_60_0/stage/lib -lboost_math_tr1
I_FLAGS = -I/Users/devolution/Documents/boost_1_60_0/
ALL_OBJECTS = main.o Gaussienne.o Grille.o Szabo.o
all: $(ALL_OBJECTS)
g++ -o hydrogene $(ALL_OBJECTS) $(LIB_FLAGS)
Gaussienne.o: Gaussienne.cpp
g++ -o Gaussienne.o -c Gaussienne.cpp -ansi ${I_FLAGS}
main.o: Gaussienne.hpp Grille.hpp main.cpp Szabo.o
g++ -o main.o -c main.cpp -ansi ${I_FLAGS}
Grille.o: Grille.cpp Gaussienne.cpp
g++ -o Grille.o -c Grille.cpp -ansi ${I_FLAGS}
Szabo.o: Szabo.cpp Gaussienne.cpp
g++ -o Szabo.o -c Szabo.cpp -ansi ${I_FLAGS}
.PHONY: clean mrproper
clean:
rm -rf *.o
mrproper: clean
rm -rf hydrogene
Is there a way to pass I_FLAGS?
You've compiled Boost's separately-compiled libraries, which is great, but you didn't copy the headers to your toolchain's include path. Indeed, most of Boost is comprised of header-only libraries, so this is arguably the more crucial step of installing Boost.
The internet tells me you may be able to find the default header search path with the following command at shell:
gcc -x c++ -v -E /dev/null
(https://stackoverflow.com/a/19852298/560648)
When you find it, copy the distribution's boost subdirectory to it.
And, yes, having home-brew install Boost for you would have been much easier… probably one command!
I have a Makefile that works for how I'm using it, but will anyone tell me if what I'm doing is good practice? Or if there is a better, cleaner or more efficient way to achieve the goal I am reaching?
Here is my Makefile Code.
# Object files to either reference or create
OBJECTS = Proj2.o Blackjack.o Deck.o Card.o Hand.o Player.o
# The executable file that will be created
EXEC = Proj2.out
# The c++ flags to use for compilation
CXXFLAGS = -Wall
# The c++ compiler to use for compilation
CXX = g++
# This section is called on 'make'
# Will call compile, and then call clean
all: compile clean
# Perform action on all object files (May or may not exist)
# The makefile will implicitly compile all .o files needed
# Will also compile them into the EXEC file listed
compile: $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $(EXEC) $(OBJECTS)
# This section is called after compilation is completed
# This will clean all existing .o files listed in the directory
clean:
rm -f *.o
Here is the terminal output when I call make.
g++ -Wall -c -o Proj2.o Proj2.cpp
g++ -Wall -c -o Blackjack.o Blackjack.cpp
g++ -Wall -c -o Deck.o Deck.cpp
g++ -Wall -c -o Card.o Card.cpp
g++ -Wall -c -o Hand.o Hand.cpp
g++ -Wall -c -o Player.o Player.cpp
g++ -Wall -o Proj2.out Proj2.o Blackjack.o Deck.o Card.o Hand.o Player.o
rm -f *.o
Is it good practice to use a Makefile like this? Specifically, am I doing the cleaning part of my Makefile correctly?
You should not make all depend on clean at all. By doing this you are ensuring that every time you run make, you have to recompile everything. If you want to do that then using make is itself useless: just write a shell script that compiles and links your code.
The clean target should be a separate target and if you want to clean your workspace you run make clean explicitly.
The other problem with your makefile is that the link rule lists compile as the target, but it builds $(EXE). It's almost never a good idea to have a rule create a file which is not exactly the target you told make it would build. To ensure this, always use $# as the target to generate. Rewrite it like this:
compile: $(EXE)
$(EXE): $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $# $^
I am using jenkins for my CI server but i have problems when i want to build the project because jenkins does not recognize the compilation errors.This is my problem:
creating objects directory obj
g++ -I../src -I third-party/cppunit-1.12.1/include -fPIC -g -Wall -c booktest.cpp -o obj/booktest.o
g++ -I../src -I third-party/cppunit-1.12.1/include -fPIC -g -Wall -c reader/bookreadertest.cpp -o obj/reader/bookreadertest.o
g++ -I../src -I third-party/cppunit-1.12.1/include -fPIC -g -Wall -c indexer/indexertest.cpp -o obj/indexer/indexertest.o
indexer/indexertest.cpp: In constructor ‘IndexerTest::IndexerTest()’:
indexer/indexertest.cpp:17:12: error: ‘failMethod’ was not declared in this scope
make: *** [obj/indexer/indexertest.o] Error 1
creating objects directory obj
g++ -I ../src -fPIC -g -Wall -c src/main.cpp -o obj/src/main.o
g++ -o oreallybooks -fPIC -g -Wall obj/src/main.o -L/user/local/lib -L../src/lib -loreally -lm
Finished: SUCCESS
I am using bash files to build and clean the cpp project
I "execute shell" for "build steps" in jenkins and this is the command:
/var/lib/jenkins/jobs/OreallyBooks/workspace/buildProject
"buildProject" is bash file and contains:
!/bin/bash
cd src;
make;
cd ../test;
make;
cd ../ui
make;
Someone can help me please? thanks all
If anything other than the final make fails then the bash script will ignore the error.
You need to set the script to fail on first error
#!/bin/bash -e
Stop on first error