Program not compiling on different PC

Hey,

We have a program, which we are compiling by this particular makefile:

COMPILER_CPP = g++
OBJ = o
COMPILER_FLAGS = -g -c
# COMPILER_FLAGS = -g -c -Wall
SRC_CPP=cc
LINK_FLAGS_BEFORE = -g -o
FC = gfortran

CLOE_CLAY_OBJ=

UMAT_DIR=./
UMAT_NAME=umat
LINK_FLAGS_AFTER = -lgfortran
triax: math.$(OBJ) \
rules.$(OBJ) \
unsat.$(OBJ) \
tskh.$(OBJ) \
hypo.$(OBJ) \
count.$(OBJ) \
countgen.$(OBJ) \
tests.$(OBJ) \
testsgen.$(OBJ) \
generalmod.$(OBJ) \
main.$(OBJ) \
$(UMAT_DIR)/$(UMAT_NAME).$(OBJ) \
makefile \
$(CLOE_OBJ) $(CLOE_CLAY_OBJ)
$(COMPILER_CPP) $(LINK_FLAGS_BEFORE) triax *.$(OBJ) $(CLOE_OBJ) $(CLOE_CLAY_OBJ) $(LINK_FLAGS_AFTER)
clean:
rm -f *.$(OBJ) triax $(UMAT_DIR)/*.$(OBJ)

%.$(OBJ) : %.$(SRC_CPP)
$(COMPILER_CPP) $(COMPILER_FLAGS) $(<D)/$(<F)

$(UMAT_DIR)/%.o : $(UMAT_DIR)/%.f
@echo $(FC) $(COMPILER_FLAGS) $(<D)/$(<F) -o $(<D)/$(<F:%.f=%.o); \
$(FC) $(COMPILER_FLAGS) $(<D)/$(<F) -o $(<D)/$(<F:%.f=%.o)
*.$(OBJ): *.h

Everything was working with no issues on my previous machine. However, I moved to a different university, so I was forced to used a different computer: Ubuntu 17.04 64bit with this kernel 4.10.0-21-generic. (The result were the same(meaning not compiling the program) on ubuntu 16.04 on this computer).
Unfortunately I dont have info about the previous PC, but I know the program was compiling with no issues on 3 more computers. So my guess is the problem could be in libraries or something like that. Unfortunately I am mostly changing mathematical formulations etc in single files (like hypo.cc etc) and I am not clearly familiar with the full structure of the whole program. Any ideas what could be wrong?
I clear all the .o files and then while compiling I receive this error, even tho I didnt touch the main.cc file for ages.

Cannot paste the whole error due to lenght, but it seems to be repeating.


asdf@computer:~/hypo/newtriax$ make triax
g++ -g -c ./math.cc
g++ -g -c ./rules.cc
g++ -g -c ./unsat.cc
g++ -g -c ./tskh.cc
g++ -g -c ./hypo.cc
g++ -g -c ./count.cc
g++ -g -c ./countgen.cc
g++ -g -c ./tests.cc
g++ -g -c ./testsgen.cc
g++ -g -c ./generalmod.cc
g++ -g -c ./main.cc
./main.cc: In member function ‘void Input::main(char*, char*)’:
./main.cc:161:8: error: no match for ‘operator==’ (operand types are ‘std::ifstream {aka std::basic_ifstream<char>}’ and ‘long int’)
if (in==NULL) {
^
./main.cc:161:8: note: candidate: operator==(int, long int) <built-in>
./main.cc:161:8: note: no known conversion for argument 1 from ‘std::ifstream {aka std::basic_ifstream<char>}’ to ‘int’
In file included from /usr/include/c++/6/iosfwd:40:0,
from /usr/include/c++/6/ios:38,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from ./triax.h:22,
from ./main.cc:22:
/usr/include/c++/6/bits/postypes.h:216:5: note: candidate: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^~~~~~~~
/usr/include/c++/6/bits/postypes.h:216:5: note: template argument deduction/substitution failed:
In file included from /usr/include/string.h:32:0,
from /usr/include/c++/6/cstring:42,
from ./triax.h:24,
from ./main.cc:22:
./main.cc:161:10: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::fpos<_StateT>’
if (in==NULL) {
^
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
from /usr/include/c++/6/bits/char_traits.h:39,
from /usr/include/c++/6/ios:40,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from ./triax.h:22,
from ./main.cc:22:
/usr/include/c++/6/bits/stl_pair.h:435:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^~~~~~~~
/usr/include/c++/6/bits/stl_pair.h:435:5: note: template argument deduction/substitution failed:
In file included from /usr/include/string.h:32:0,
from /usr/include/c++/6/cstring:42,
from ./triax.h:24,
from ./main.cc:22:
./main.cc:161:10: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::pair<_T1, _T2>’
if (in==NULL) {
^
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
from /usr/include/c++/6/bits/char_traits.h:39,
from /usr/include/c++/6/ios:40,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from ./triax.h:22,
from ./main.cc:22:
/usr/include/c++/6/bits/stl_iterator.h:292:5: note: candidate: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator==(const reverse_iterator<_Iterator>& __x,
^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:292:5: note: template argument deduction/substitution failed:
In file included from /usr/include/string.h:32:0,
from /usr/include/c++/6/cstring:42,
from ./triax.h:24,
from ./main.cc:22:
./main.cc:161:10: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if (in==NULL) {
^
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
from /usr/include/c++/6/bits/char_traits.h:39,
from /usr/include/c++/6/ios:40,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from ./triax.h:22,
from ./main.cc:22:
/usr/include/c++/6/bits/stl_iterator.h:349:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator==(const reverse_iterator<_IteratorL>& __x,
^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:349:5: note: template argument deduction/substitution failed:
In file included from /usr/include/string.h:32:0,
from /usr/include/c++/6/cstring:42,
from ./triax.h:24,
from ./main.cc:22:
./main.cc:161:10: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if (in==NULL) {
^
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
from /usr/include/c++/6/bits/char_traits.h:39,
from /usr/include/c++/6/ios:40,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from ./triax.h:22,
from ./main.cc:22:
/usr/include/c++/6/bits/stl_iterator.h:1113:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
operator==(const move_iterator<_IteratorL>& __x,
^~~~~~~~
/usr/include/c++/6/bits/stl_iterator.h:1113:5: note: template argument deduction/substitution failed:
In file included from /usr/include/string.h:32:0,
from /usr/include/c++/6/cstring:42,
from ./triax.h:24,
from ./main.cc:22:
./main.cc:161:10: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::move_iterator<_IteratorL>’
if (in==NULL) {
^
In file included from /usr/include/c++/6/bits/stl_algobase.h:67:0,
from /usr/include/c++/6/bits/char_traits.h:39,
from /usr/include/c++/6/ios:40,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from ./triax.h:22,
from ./main.cc:22:
/usr/include/c++/6/bits/stl_iterator.h:1119:5: note: candidate: template<class _Iterator> bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
operator==(const move_iterator<_Iterator>& __x,
^~~~~~~~

makefile:42: recipe for target 'main.o' failed
make: *** [main.o] Error 1
From the error message it would appear that in if (in==NULL) {,
the type of in is std::ifstream

To check if the stream is not in a failed state, write if(in) {

And compile C++ code with: g++ -std=c++14 -pedantic-errors -Wall -Wextra -g -c ./math.cc
Thanks!

If I change the code to:

if (in) {
and
if (plasti_data) {

compared to original

if (in==NULL) {
and
if (plasti_data!=NULL) {

it compiles. But I still don't get a solution how to make it work in the way I originaly wanted with NULL...? Sorry for my stupidity...
Why do you want to compare the state of your file stream to the null pointer?
The stream is either valid or not; it doesn't make much sense to compare it against NULL.
Because I want to have it in this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	ifstream in(input_file);
	if (in==NULL) {
		cout<<endl<<endl<<"I can't open "<<input_file<<endl;
		cout<<"Usage: 'triax' or 'triax file.inp' or 'triax file.inp file.out'"<<endl;
		exit(0);	
	}
	cout<<endl<<"Calculation of input file "<<input_file<<endl;

	string slovo;
	double cislo;
	ifstream plasti_data("plasti_data.dta");
	if (plasti_data!=NULL) {
		while(plasti_data>>slovo) {
			cislo = atof (slovo.data());
			if(!cislo==(int)cislo) 	slovo+="0000000000000000000000000";
			else			slovo+=".000000000000000000000000";
			cislo = atof (slovo.data());	
			vari.plasti_data.push_back(cislo);
		}
		external_plasti_data=true;
	}

	bool el=false, pl=false, tr=false, total=false, end=false, after_set_stage=false, 
		comment=false, value=false, condition=false, noresults=false, results=false,
		every=false;
	while (1) {				//read input
		if(!(in>>slovo)) end=true;
		if(slovo=="(") comment=true;
		if(slovo==")") {
			comment=false;
			if(!(in>>slovo)) end=true;
			if(slovo=="(") comment=true;
		}
		if(comment) continue;
		if(string_isdouble(slovo)) value=true;
		else value=false;
		condition=false;
		if (slovo=="q" || slovo=="p" || slovo=="sigax" || slovo=="epax" || slovo=="epsh"
			       || slovo=="epv" || slovo=="lode" || slovo=="eta" || slovo=="suction" || slovo=="ep12"
			       || slovo=="scycle" || slovo=="temper") {
			cout<<"condition: "<<slovo<<" ";
			condition=true;
		}


Simply to print at the beginning that its not working if there is missing input...
Last edited on
1
2
3
4
5
6
std::ifstream in(input_file);

// http://en.cppreference.com/w/cpp/io/basic_ifstream/is_open
if( !in.is_open() ) { 
    std::cout << "failed to open input file '" << input_file << "'\n" ; 
     // ...  



Idiomatic (C++11):
1
2
3
4
5
6
7
8
9
10
if( std::ifstream in{input_file} ) {

       // read and process data from input file 
       // ...
}

else { 

    std::cout << "failed to open input file '" << input_file << "'\n" ; 
}
Topic archived. No new replies allowed.