0

Linux で問題なくコンパイルできる C++ コードをいくつか持っていますが、これまでのところ NetBSD で正しくコンパイルするのに苦労しています。

これらは私のものです:

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include <iomanip>
#include <boost/regex.hpp>

次のコマンドでコンパイルします。

g++ -v -O2 -fno-strict-aliasing -I /usr/pkg/include \
barefoot.cpp -o barefoot -L /usr/pkg/lib/ -lboost_regex \
-L /usr/pkg/lib/ -lboost_regex -lpthreads

この出力をレンダリングするもの:

Using built-in specs.
COLLECT_GCC=g++
Target: x86_64--netbsd

Configured with: /usr/src2/tools/gcc/../../external/gpl3/gcc/dist/configure --target=x86_64--netbsd --enable-long-long --enable-threads --with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD nb2 20111202' --enable-__cxa_atexit --with-tune=nocona --with-mpc=/var/obj/mknative/amd64/usr/src2/destdir.amd64/usr --with-mpfr=/var/obj/mknative/amd64/usr/src2/destdir.amd64/usr --with-gmp=/var/obj/mknative/amd64/usr/src2/destdir.amd64/usr --enable-tls --disable-multilib --disable-symvers --disable-libstdcxx-pch --build=x86_64-unknown-netbsd5.99.56 --host=x86_64--netbsd

Thread model: posix

gcc version 4.5.3 (NetBSD nb2 20110806) 
COLLECT_GCC_OPTIONS='-v' '-O2' '-fno-strict-aliasing' '-I' '/usr/pkg/include/' '-o' 'a.out' '-L' '/usr/pkg/lib/' '-mtune=nocona' '-march=x86-64'
 /usr/libexec/cc1plus -quiet -v -I /usr/pkg/include/ barefoot.cpp -quiet -dumpbase barefoot.cpp -mtune=nocona -march=x86-64 -auxbase barefoot -O2 -version -fno-strict-aliasing -o /var/tmp//cc9Dcmwi.s
GNU C++ (NetBSD nb2 20110806) version 4.5.3 (x86_64--netbsd)
        compiled by GNU C version 4.5.3, GMP version 5.0.2, MPFR version 3.0.1-p4, MPC version 0.9

GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=131007
#include "..." search starts here:
#include <...> search starts here:
 /usr/pkg/include/
 /usr/include/g++
 /usr/include/g++/backward
 /usr/include/gcc-4.5
 /usr/include
End of search list.

GNU C++ (NetBSD nb2 20110806) version 4.5.3 (x86_64--netbsd)
        compiled by GNU C version 4.5.3, GMP version 5.0.2, MPFR version 3.0.1-p4, MPC version 0.9
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=131007
Compiler executable checksum: a34e7d170f4dd8d4687d2b62e8dca4b7
In file included from /usr/include/g++/bits/gthr.h:166:0,
                 from /usr/include/g++/ext/atomicity.h:34,
                 from /usr/include/g++/bits/ios_base.h:41,
                 from /usr/include/g++/ios:43,
                 from /usr/include/g++/istream:40,
                 from /usr/include/g++/fstream:40,
                 from barefoot.cpp:29:
/usr/include/g++/bits/gthr-default.h:130:9: error: 'pthread_detach' was not declared in this scope
/usr/include/g++/bits/gthr-default.h:130:1: error: invalid type in declaration before ';' token
/usr/include/g++/bits/gthr-default.h: In function 'int __gthread_detach(pthread_st*)':
/usr/include/g++/bits/gthr-default.h:668:46: error: '__gthrw_pthread_detach' cannot be used as a function
In file included from /usr/pkg/include/boost/regex/v4/regex_workaround.hpp:25:0,
                 from /usr/pkg/include/boost/regex/v4/regex.hpp:32,
                 from /usr/pkg/include/boost/regex.hpp:31,
                 from barefoot.cpp:32:
/usr/include/g++/cstdlib: At global scope:
/usr/include/g++/cstdlib:132:11: error: '::system' has not been declared

を追加してみ-lpthreadましたが、結果は同じでした。次に何を試すべきかわからない。

4

1 に答える 1

2

この問題に直面している理由は正確にはわかりませんが、次のステップを試してみることができます。

  • 最初のエラーがpthread_detach欠落していることに注意してください。システム ヘッダー ファイルは、通常、必要なヘッダーが含まれていることを確認しますが<pthread.h>、他のすべてのヘッダーの上に追加してみてください。

  • それが失敗した場合は、 を追加した結果として含まれたファイルを特定し、その中に が存在#include <pthread.h>することを確認する必要pthread_detachがあります (実際にはどこかにあるはずです)。

  • そこにあると仮定すると、ソースコードに表示されない原因となっている条件付きコンパイルが必要です。条件付きガードとそれに影響するマクロ値を見つけます。

  • 次に、関数pthread_detachが表示されないようにする方法でシステムがマクロ値を定義している理由を確認する必要があります。

この調査により、正しい<pthread.h>ファイルが含まれていないことがわかる場合があります。これは、システムのインクルード ディレクトリが、使用するインクルード ディレクトリと競合していることが原因である可能性があります。

この質問に対するこの回答(一番下の方にあります)は、g++コンパイラの定義済みマクロを表示する方法を示しています。

于 2015-06-20T01:03:04.290 に答える