我正在交叉编译一个包(libqmi
)。(通过简单的编译就可以了。)
当我试图遵从c++的一部分时,问题就出现了。我收到的消息
CCD_ 2。
我知道在C的情况下不需要包含它,但C++呢?
我尝试手动添加标题:fcntl.h
和unistd.h
,但没有任何解决方案。(编译器找到了它们并将其包含在内,但错误消息仍然保留)
你知道这背后的问题是什么吗?我不认为这个问题是错误的,因为它是一个已实现的主机编译器。
编辑:感谢您的评论。主机:Linux、x86、,目标:Linux,arm
unistd.h标头没有解决问题:我也试过打字alloc,可能有拼写错误。GobiQMICore.cpp:在成员函数"虚拟std::vector,std::basic_string>>cGobiQMIC ore::GetAvailableDevices()"中:GobiQMICore.cpp:319:错误:未在此作用域中声明"read"GobiQMICore.cpp:334:21:错误:未在此作用域中声明"关闭"
代码:
/*===========================================================================
METHOD:
GetAvailableQDLPorts (Public Method)
DESCRIPTION:
Return the set of available Gobi QDL ports
RETURN VALUE:
std::vector <sDeviceID>
===========================================================================*/
std::vector <std::string> cGobiQDLCore::GetAvailableQDLPorts()
{
std::vector <std::string> devices;
std::string path = "/sys/bus/usb/devices/";
std::vector <std::string> files;
DepthSearch( path,
2,
"ttyUSB",
files );
int fileNum = files.size();
for (int i = 0; i < fileNum; i++)
{
// Example "/sys/bus/usb/devices/8-1/8-1:1.1/ttyUSB0"
std::string nodePath = files[i];
int lastSlash = nodePath.find_last_of( "/" );
// This is what we want to return if everything else matches
std::string deviceNode = nodePath.substr( lastSlash + 1 );
// Move down one directory to the interface level
std::string curPath = nodePath.substr( 0, lastSlash );
// Read bInterfaceNumber
int handle = open( (curPath + "/bInterfaceNumber").c_str(),
O_RDONLY );
if (handle == -1)
{
continue;
}
char buff[4];
memset( buff, 0, 4 );
bool bFound = false;
int ret = read( handle, buff, 2 );
if (ret == 2)
{
// Interface 1 or 0
ret = strncmp( buff, "01", 2 );
if (ret == 0)
{
bFound = true;
}
ret = strncmp( buff, "00", 2 );
if (ret == 0)
{
bFound = true;
}
}
close( handle );
if (bFound == false)
{
continue;
}
// Move down one directory to the device level
curPath = curPath.substr( 0, curPath.find_last_of( "/" ) );
// Read idVendor
handle = open( (curPath + "/idVendor").c_str(), O_RDONLY );
if (handle == -1)
{
continue;
}
bFound = false;
ret = read( handle, buff, 4 );
if (ret == 4)
{
ret = strncmp( buff, "05c6", 4 );
if (ret == 0)
{
bFound = true;
}
}
close( handle );
if (bFound == false)
{
continue;
}
// Read idProduct
handle = open( (curPath + "/idProduct").c_str(), O_RDONLY );
if (handle == -1)
{
continue;
}
bFound = false;
ret = read( handle, buff, 4 );
if (ret == 4)
{
ret = strncmp( buff, "920c", 4 );
if (ret == 0)
{
bFound = true;
}
}
close( handle );
if (bFound == false)
{
continue;
}
// Success!
devices.push_back( deviceNode );
}
return devices;
}
T
我知道在C的情况下不需要包含它,但C++呢?
我认为您应该始终包含您需要的标题。我想你的编译器正在为你做这项工作,如果你在gcc中使用"-Wall"参数,你应该得到一个警告。
在Linux下,要知道需要包含什么标头,只需键入man function
即可。有时你可能会得到bash手册页,对于open,你需要指出man 2 read
部分,在概要中,你有所需的标题。要获得这些手册页,您还需要在基于Debian的发行版上安装手册页dev。
为了回答您的问题,我在使用名称空间编写C++程序时也遇到过这种问题。如果您在名称空间内,请尝试像::read(...)
那样调用此函数