[英]silly C++ syntax has not been declared
I'm trying to take a Qt C++ project originally written for Windows and cross compile it for embedded Linux. 我正在尝试使用最初为Windows编写的Qt C ++项目,并将其交叉编译为嵌入式Linux。 Now this program compiles find and works on Windows, so this problem must be something OS specific (which I didn't think happend with Qt code) or configuration related, but I'm having a hard time tracking it down because I don't fully understand C++ syntax. 现在这个程序在Windows上编译查找和工作,所以这个问题必须是特定于操作系统的东西(我认为不会发生Qt代码)或配置相关,但我很难跟踪它,因为我没有完全理解C ++语法。
my make command: 我的make命令:
arm-linux-gnueabihf-g++ -c -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 -O2 -O3 -Wall -W -D_REENTRANT -DCHL80Net -DPHASE_TO_NEUTRAL -DCHL80NET -DCANLCD_BUILD -DQT_NO_DEBUG -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../mkspecs/qws/linux-am335x-g++ -I. arm-linux-gnueabihf-g ++ -c -march = armv7-a -marm -mthumb-interwork -mfloat-abi = hard -mfpu = neon -mtune = cortex-a8 -O2 -O3 -Wall -W -D_REENTRANT -DCHL80Net - DPHASE_TO_NEUTRAL -DCHL80NET -DCANLCD_BUILD -DQT_NO_DEBUG -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I ../ mkspecs / qws / linux-am335x-g ++ -I。 -I../include/QtCore -I../include/QtGui -I../include/QtXml -I../include -I. -I ../include / QtCore -I ../include/QtGui -I ../include/QtXml -I ../ include -I。 -IApp -IApp/Model/ModelSim -IApp/Model -I. -IApp -IApp / Model / ModelSim -IApp / Model -I。 -IPages -IApp/GUI/Widgets -IApp/GUI/Pages -IApp/GUI -IApp/GUI/Widgets -IApp/GUI/Pages/Util -IApp/GUI/Pages -IApp/Log4Qt -I.obj -o .obj/CanInterface.o App/Can/CanInterface.cpp -IPages -IApp / GUI / Widgets -IApp / GUI / Pages -IApp / GUI -IApp / GUI / Widgets -IApp / GUI / Pages / Util -IApp / GUI / Pages -IApp / Log4Qt -I.obj -o .obj /CanInterface.o App / Can / CanInterface.cpp
The error: 错误:
App/Can/CanInterface.cpp: In member function 'void CanInterface::closeConnection()': App/Can/CanInterface.cpp:68:5: error: '::close' has not been declared make: * [.obj/CanInterface.o] App / Can / CanInterface.cpp:在成员函数'void CanInterface :: closeConnection()'中:App / Can / CanInterface.cpp:68:5:错误:':: close'尚未声明为make: * [.obj /CanInterface.o]
Error 1 错误1
Here's the line of code in question: 这是有问题的代码行:
void CanInterface::closeConnection()
{
::close(m_socket);
m_socket = -1;
I thought this didn't look like valid code at all at first, but I don't really know C++ so I had to do a little research, it seems like this ::function()
syntax is to ensure resolution occurs from the global namespace instead of the local one. 起初我觉得这看起来并不像有效的代码,但我真的不知道C ++所以我不得不做一些研究,看起来这个::function()
语法是确保从全局解决问题命名空间而不是本地命名空间。
So what I'm trying to find out is what namespace should have declaired this close()
function. 所以我想要找出的是命名空间应该声明这个close()
函数。 If my understanding of this code is correct I don't need to look in the CanInterface
class for the undeclaired function, but it's parent class? 如果我对这段代码的理解是正确的,我不需要在CanInterface
类中查找未声明的函数,但它是父类?
In the header file for the CanInterface
class I found this: 在CanInterface
类的头文件中,我发现了这个:
class CanInterface : public QObject
{
Q_OBJECT
which I think means that it inharents from a QObject
class. 我认为这意味着它来自QObject
类的inharents。 So: 所以:
QObject
class for the missing close()
function or if I need to keep going up? 我如何知道是否需要查看缺少close()
函数的QObject
类,或者我是否需要继续运行? Does ::close
somehow tell me how many levels of nested classes I need to search through? 是::close
以某种方式告诉我需要搜索多少级别的嵌套类? You are correct, in that ::some_function()
calls a function from the global scope. 你是对的,因为::some_function()
从全局范围调用一个函数。
This includes all C
library or system functions. 这包括所有C
库或系统功能。 You can lookup global functions on a *nix system with man
, eg 您可以使用man
在* nix系统上查找全局函数,例如
man close
which gives on my Ubuntu 这给了我的Ubuntu
NAME
close - close a file descriptor
SYNOPSIS
#include <unistd.h>
int close(int fd);
So, to fix your compile error, you must include unistd.h
somewhere in your C++ source or in a surrounding header file. 因此,要修复编译错误,必须在C ++源代码或周围的头文件中包含unistd.h
。
You can get the same information, when you google for man close , eg http://linux.die.net/man/2/close 当你谷歌关闭时,你可以获得相同的信息,例如http://linux.die.net/man/2/close
C++ encapsulates names in namespaces to avoid naming collisions. C ++封装名称空间中的名称以避免命名冲突。 It's somewhat analagous to the C practice of prepending a prefix specific to a library to the names of functions in that library, eg, my_library_foo()
in C might be called my_library::foo()
in C++. 将C语言特定于库的前缀添加到该库中的函数名称的C实践有点类似,例如,C中的my_library_foo()
可能在C ++中被称为my_library::foo()
。 When ::
appears at the beginning of a name, it means that name is fully qualified : it is looked up beginning from the global namespace instead of the current/enclosing namespace, much like with absolute ( /etc/passwd/
) vs. relative ( foo/bar
) file names. 当::
出现在名称的开头时,意味着名称是完全限定的 :从全局名称空间开始查找它而不是当前/封闭名称空间,就像绝对( /etc/passwd/
)与相对名称一样。 ( foo/bar
)文件名。
So the name ::close
is intended to resolve to the close function declared in the global namespace, the one which would be put there by including <unistd.h>
on a POSIX system. 因此,名称::close
旨在解析为全局命名空间中声明的close函数,该函数将通过在POSIX系统上包含<unistd.h>
来放置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.