2

ardupilotというオープンソースのソースを改変しながら開発を進めています。
最近g++でビルドした際に標準ライブラリ内でエラーが発生するようになりました。エラー内容は以下の通りです(環境はubuntudです)。

In file included from /usr/include/c++/5/bits/basic_ios.h:37:0,
             from /usr/include/c++/5/ios:44,
             from /usr/include/c++/5/ostream:38,
             from /usr/include/c++/5/iostream:39,
             from ../../libraries/AP_IRLock/AP_IRLock_SITL.cpp:30:
/usr/include/c++/5/bits/locale_facets.h:2601:44: error: macro "isdigit" passed 2 arguments, but takes just 1
 isdigit(_CharT __c, const locale& __loc)
                                        ^
compilation terminated due to -Wfatal-errors.

内容から察するにlocale_facets.hでしようされているisdigit関数の引数が2つ指定されているが、ctype.h内のisdigit関数の引数は1つしか要求していないということだと思います。
事実、/usr/include/c++/5/bits/locale_facets.h内のisidigitと/usr/include/ctype.h内のisdigitが異なっていることは確認できています。
g++のバージョンを4.7に変更したりしましたが、ダメでした。
ちなみに今のg++のバージョンは5.4.1です。
g++,gccの際インストール等も行いましたが、結果はダメでした。

どなたか助けてください。

0

2 件の回答 2

3

記述されているのはC++のソースかと思いますが、/usr/include/ctype.hはC向けのヘッダファイルなので食い違いが起きています。
include行を見直してもらい、#include <locale>で定義されているstd::isdigitの方を呼び出せば引数を2つ取るisdigitが利用できるようです。

ctype.h の isdigit
std::locale の isdigit

std::isdigit を利用したコードサンプル

// isdigit example (C++)
#include <iostream>       // std::cout
#include <string>         // std::string
#include <locale>         // std::locale, std::isdigit
#include <sstream>        // std::stringstream

int main ()
{
  std::locale loc;
  std::string str="1776ad";
  if (isdigit(str[0],loc))
  {
    int year;
    std::stringstream(str) >> year;
    std::cout << "The year that followed " << year << " was " << (year+1) << ".\n";
  }
  return 0;
}

参考:
英語版SOでの関連質問
c++ - isspace macro conflicting with isspace function in locale_facets.h

3

あなたがソース改変する際に、今まで無かった #include <ctype.h> を追加したのだと思います。これは ヘッダなので ヘッダの #include <locale> と喧嘩してしまいます (#definestd::isdigit を隠蔽してしまうなど)

既存コードが使っているなどの理由により、2引数の std::isdigit ではなくて1引数の isdigit を使う必要があるのなら #include <ctype.h> ではなくて #include <cctype> とするとよいでしょう。

あるいは1引数の isdigit を廃して2引数の std::isdigit に統一する、でしょうか。その場合必要なのは #include <locale> だけなので #include <ctype.h> あるいは #include <cctype> は削除となります。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。