jenkins does not recognize the errors when building the cpp code - c++

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

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

Got "-std=c++11: command not found" error when trying to compile a object file using g++

As in the title, when I try to compile an object file using g++ by running this shell script:
#!/bin/bash
name=textsweeper
srcdir=src
buildir=build
cc=g++
cppflags=-Wall -std=c++11 -ggdb -O
libs=
rm -f $buildir/$name $buildir/main.o
$cc $cppflags $srcdir/main.cpp -c -o $buildir/main.o
$cc $buildir/main.o $libs -o $buildir/$name
I get the following error:
$ bash compile
compile: line 6: -std=c++11: command not found
And other errors about things being only available only with stdc++11.
I've tried yahooing the error, but I've only got answers to about errors about actual command not arguments.
Variable assignment is space sensitive. Change:
cppflags=-Wall -std=c++11 -ggdb -O
to
cppflags="-Wall -std=c++11 -ggdb -O"
Otherwise, you're trying to run the command -std=c++11 -ggdb -O with the environment including a setting of cppflags=-Wall. bash allows temporary environment settings to be done this way, which is why its important to quote any variable assignments that contain spaces.

Boost & makefile

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!

Makefile that changes directory then compiles code

I am having difficulty trying to create a makefile that is in a root directory which will then CD into another directory entitled "code" which is where my code will be compiled. Also the executable then needs to be placed in a new directory which will be created called "bin" which will be in the root directory I have this so far:
all: bin/main
test: bin/main
bin/main: main.cpp
mkdir -p bin
g++ -std=c++11 -Wall -Werror -ansi -pedantic -o bin/program main.cpp
NOTE: I need those two target all and test. However this make (above) will only work if my code is already in the root
UPDATE: renamed code directory to src and here is new makefile
all:
mkdir -p ./bin
g++ -std=c++11 -Wall -Werror -ansi -pedantic ./src/main.cpp -o./bin/prgm
test:
mkdir -p ./bin
g++ -std=c++11 -Wall -Werror -ansi -pedantic ./src/main.cpp -o ./bin/prgm
however now I get this error "make: *** makefile: Is a directory. Stop."
Am I trying to run it right? I do this "$ make"
Here is simplest take, You can do many more things like making the target all phoney etc to keep it simple for demonstration.
all:
- mkdir -p bin
g++ -std=c++11 -Wall -Werror -ansi -pedantic -o bin/program src/main.cpp
Hope, you can figure out for target test.

Makefile for small program

all: ship
ship: testShip.o ship.o
g++ -g -Wall -o ship testShip.o ship.o
testShip.o: testShip.cpp
g++ -g -Wall -c testShip.cpp
ship.o: ship.cpp
g++ -g -Wall -c ship.cpp
clean:
rm -rf *.o ship
Does anyone know why I get the error: "Makefile:1: *** missing separator. Stop."?
I googled and I did put a tab after the beginning of every line. Thanks!