【问题标题】:C++: Library import errors (‘stdin_fileno’ was not declared in this scope)C++:库导入错误(“stdin_fileno”未在此范围内声明)
【发布时间】:2016-12-03 12:33:22
【问题描述】:

是的,所以我在另一台运行 Ubuntu 14.04 的计算机上使用 GCC 4.8.4 作为编译器运行此代码,它运行良好,但似乎无法在这里编译。

这是代码(一段非常标准化的在线代码)。我已经剥离了几乎所有内容,但编译仍然失败:/

#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() {}

这是我收到的错误类型:

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

我似乎不明白的是,这是如何在这台计算机上编译失败的,而它在另一台 PC 上使用相同的 makefile 编译绝对没问题(安装了几乎相同的软件包等)。我可能在这里犯了一个根本性错误,但我很想知道我做错了什么......

这是我的 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 $*=$($*)

根据网上的帖子,我尝试使用-std=gnu+11 而不是-std=c++11,也尝试使用#include &lt;unist.h&gt;,但无济于事...

除此之外,没有识别出任何 opencv 函数/对象(肯定安装正确,因为我可以通过 python 使用它)。

所以请让我知道我做错了什么基本的事情!我对此有点陌生,所以我很感激任何建议/提示和提示!

谢谢!

【问题讨论】:

  • 所有这些宏都应该是大写的。
  • 你是在 Windows 上编译这个吗?
  • @ImranAhmed 不,我的意思是stdin_fileno => STDIN_FILENO
  • @user657267 所以这实际上已经解决了错误!谢谢!!虽然我知道 c++ 是区分大小写的,但为什么我以前能够编译它,但现在不行?发生了什么变化?
  • 还有@DeepCoder,不,这是在 Ubuntu 14.04 上编译的

标签: c++ c++11 makefile scope


【解决方案1】:

多年后回复,以防有人像我一样遇到这个问题。

您只是忘记包含unistd.h 库(使用#include &lt;unistd.h&gt;)。 而且所有的宏都应该是大写字母。 Here的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多