我正在交叉编译一个包(libqmi
)。(通过简单的编译就可以了。)
当我尝试遵守 c++ 部分时,问题就出现了。我收到的信息是
"read is not declared"
.
我知道在 C 的情况下不需要包含它,但是 C++ 呢?
我尝试手动添加标题:fcntl.h
并且unistd.h
也没有任何解决方案。(编译器找到并包含它们,但错误消息仍然存在)
你知道这背后的问题是什么吗?我不认为这个问题是错误的,因为它是一个已实现且对主机编译器很好的。
编辑:感谢评论。主机:Linux,x86,目标:Linux,arm
unistd.h 头文件没有解决问题:我也尝试过 type alloc,可能有 misalloc。GobiQMICore.cpp:在成员函数“虚拟 std::vector,std::basic_string > > cGobiQMICore::GetAvailableDevices()”中:GobiQMICore.cpp:319:39:错误:“读取”未在此范围内声明 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;
}
吨