jeudi 28 juillet 2016

C++: Library import errors (‘stdin_fileno’ was not declared in this scope)

Right so I've run this code using GCC 4.8.4 as the compiler on another computer running Ubuntu 14.04 and it runs fine but it doesn't seem to compile here.

Here's the code (a pretty standardised piece of code available online). I've stripped pretty much everything away and it still fails on compile :/

#include "company/detectors.hpp"
#include <thread>
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include "opencv2/opencv.hpp"

int kbhit(void)
{
    struct termios oldt, newt;
    int ch;
    int oldf;
    tcgetattr(stdin_fileno, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(icanon | echo);
    tcsetattr(stdin_fileno, tcsanow, &newt);
    oldf = fcntl(stdin_fileno, f_getfl, 0);
    fcntl(stdin_fileno, f_setfl, oldf | o_nonblock);
    ch = getchar();
    tcsetattr(stdin_fileno, tcsanow, &oldt);
    fcntl(stdin_fileno, f_setfl, oldf);
    if (ch != eof) {
        ungetc(ch, stdin);
        return 1;
    }
    return 0;
} 
int main() {}

Here's the type of error I'm receiving:

optimisation.cpp: In function ‘int kbhit()’:
optimisation.cpp:14:12: error: ‘stdin_fileno’ was not declared in this scope
  tcgetattr(stdin_fileno, &oldt);
            ^
optimisation.cpp:16:20: error: ‘icanon’ was not declared in this scope
  newt.c_lflag &= ~(icanon | echo);
                    ^
optimisation.cpp:16:29: error: ‘echo’ was not declared in this scope
  newt.c_lflag &= ~(icanon | echo);
                             ^
optimisation.cpp:17:26: error: ‘tcsanow’ was not declared in this scope
  tcsetattr(stdin_fileno, tcsanow, &newt);
                          ^
optimisation.cpp:18:29: error: ‘f_getfl’ was not declared in this scope
  oldf = fcntl(stdin_fileno, f_getfl, 0);
                             ^
optimisation.cpp:19:22: error: ‘f_setfl’ was not declared in this scope
  fcntl(stdin_fileno, f_setfl, oldf | o_nonblock);
                      ^
optimisation.cpp:19:38: error: ‘o_nonblock’ was not declared in this scope
  fcntl(stdin_fileno, f_setfl, oldf | o_nonblock);
                                      ^
optimisation.cpp:23:12: error: ‘eof’ was not declared in this scope
  if (ch != eof) {
            ^
make: *** [bin/optimisation.o] Error 1

What I don't seem to understand is how this fails to compile on this computer while it compiles absolutely fine with the same makefile on another PC (with nearly identical packages installed etc.). I'm probably making a fundamental error here but I'd love to know what I'm doing wrong...

Here's my Makefile:

CC=g++
OBJ= bin/
TARGET=optimisation

CFLAGS= `pkg-config --cflags opencv` -O2 -Wall -std=c++11 $(BOOST)
LINKFLAGS = `pkg-config --libs opencv`
CUDA = -I/usr/local/cuda/include -L/usr/local/cuda/lib
BOOST = -lboost_system -lboost_filesystem -lboost_regex
COMPDIR= -L/usr/local/lib/ -I/usr/local/include/
COMPLIB = -lcompany
NCURSES = -lncurses

OBJECTS= optimisation.o

all:$(TARGET)

$(TARGET): $(addprefix $(OBJ),$(OBJECTS)) 
    $(CC) -o $(OBJ)$(TARGET) $(addprefix $(OBJ),$(OBJECTS)) $(COMPDIR) $(COMPLIB) $(BOOST) $(NCURSES) $(LINKFLAGS) $(SQL) $(CAFFE) -lglog -lgflags -lcpr -lcurl

$(OBJ)%.o: $(SRC)%.cpp | MKDIR
    $(CC) $< -g -o $@ -c $(CFLAGS) -w $(CUDA)

clean:
    rm -rf $(OBJ)*.o 

MKDIR:
    mkdir -p $(OBJ)

print-%: ; @echo $*=$($*)

As per a post online, I've tried to use -std=gnu+11 instead of -std=c++11 and have also tried to #include <unist.h> but to no avail...

On top of this, no opencv functions/objects (which is definitely installed correctly as I can use it via python) are recognised.

So please let me know what fundamental thing I'm doing wrong! I'm a bit new at this so I'd appreciate any advice/hints & tips!

Thanks!

Aucun commentaire:

Enregistrer un commentaire