是的,我在另一台运行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我似乎不明白的是,这是如何在这台电脑上编译失败,而它在另一台电脑上编译完全相同的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 <unist.h>,但都无济于事……
最重要的是,无法识别opencv函数/对象(它肯定是正确安装的,因为我可以通过python使用它)。
所以,请让我知道我到底做错了什么!我在这方面是个新手,所以我希望得到任何建议/提示和提示!
谢谢!
发布于 2021-08-20 20:19:13
几年后回复,以防有人像我一样遇到这个问题。
您只是忘记了包含unistd.h库(使用#include <unistd.h>)。而且所有的宏都应该是大写的。这就是Here的原因。
https://stackoverflow.com/questions/38647842
复制相似问题