0

パッケージ ( ) をクロスコンパイルしています (libqmi単純なコンパイルでは問題ありませんでした。)

C++の部分に準拠しようとしたときに問題が発生しました。というメッセージが届きました

"read is not declared".

C の場合は含める必要がないことはわかっていますが、C++ の場合はどうでしょうか。

手でヘッダーを追加しようとしましたが、解決策もfcntl.hありunistd.hませんでした。(コンパイラはそれらを見つけて含めましたが、エラーメッセージはまだ残っています)

この背後にある問題について何か考えがありますか? ホストコンパイラで実現され、良好であるため、問題が間違っているとは思いません。

編集:コメントに感謝します。ホスト: Linux、x86、ターゲット: Linux、アーム

unistd.h ヘッダーは問題を解決しません: type alloc も試しましたが、misalloc がある可能性があります。GobiQMICore.cpp: メンバー関数 'virtual std::vector, std::basic_string > > cGobiQMICore::GetAvailableDevices()': GobiQMICore.cpp:319:39: エラー: 'read' はこのスコープで宣言されていません GobiQMICore.cpp :334:21: エラー: 'close' はこのスコープで宣言されていません

コード:

/*===========================================================================
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

4

1 に答える 1

2

C の場合は含める必要がないことはわかっていますが、C++ の場合はどうでしょうか。

必要なヘッダーは常に含める必要があると思います。gcc で「-Wall」パラメータを使用すると、コンパイラが作業を行っていると思います。警告が表示されるはずです。

Linux では、どのヘッダーを含める必要があるかを知るには、 と入力するだけですman function。場合によっては、bash の man ページを取得することがあります。開くには、セクションを示す必要がありman 2 read、概要には、必要なヘッダーがあります。これらの man ページを取得するには、Debian ベースのディストリビューションに manpages-dev をインストールする必要もあります。

あなたの質問に答えるために、名前空間を使用して C++ プログラムを書いていたときにも、そのような問題がありました。名前空間内にいる場合は、この関数をそのように呼び出してみてください::read(...)

于 2013-08-06T15:18:00.277 に答える