Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support clang3.4.2 (重要注意事項あり) #21

Merged
merged 6 commits into from May 20, 2019

Conversation

yumetodo
Copy link
Contributor

注意

最強に汚いWorkaroundが含まれています。メンテナンス性を十分に検討してからmergeしてください

手元のCentOS7環境ではこのWorkaroundなしでは

/usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdio:120:11: error: no member named 'gets' in the global namespace
  using ::gets;
        ~~^

のようなエラーが出ていました。これは極めて危険でC11で削除されたgets関数を参照しているために発生しているものです。

この問題を解決する正攻法は
[Clang][C++14][Linux] Clangで標準ライブラリのヘッダでコンパイルエラーが出る場合の対処法 - Qiita
にあるように、libc++を使うか
c++ - clang seems to use the gcc libraries - Stack Overflow
GCC4.9.2以降付属のlibstdc++を使うことです。
が、これは管理者権限のないユーザーには、gccを一からビルドすることを要求することになるので、気軽に勧められません。
(というか私の環境だとそんなにストレージに空きがない
ref: https://yumetodo.hateblo.jp/entry/2017/07/01/123416

そこで登場したのがこの汚いworkaroundです。必要なのはgetsの定義ではなく宣言のみであることを利用し

extern "C" char *gets(char *s);

を予め宣言することで回避します。

このworkaroundはcstdioを読み込むより前に読み込む必要があり、cstdiostringやストリーム系ヘッダ(もっとも基底のiosやその派生クラスのあるfstream/iostream/sstreamヘッダーなど)なんかで読み込まれています。つまり大抵のファイルの先頭でこのworkaroundのあるファイルをincludeする必要があります。

これは言うまでもなくメンテナンス性を下げるworkaroundです。

採用しない場合は 42c55b7 8ec5dc3 を除外してrebaseする必要があります。

概要

$cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
$gcc -v
組み込み spec を使用しています。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
ターゲット: x86_64-redhat-linux
configure 設定: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --d
isable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
スレッドモデル: posix
gcc バージョン 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
$clang -v
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.5

な環境でビルドが通るように。

お知らせ

class foo{
    constexpr foo() noexcept = default;
};

のような定義が大量にありましたが、このnoexceptはつけてはいけません

というか

exception specification of explicitly defaulted move constructor does not match the calculated one

のように言われます。説明が面倒くさくなったので
mapnik/mapnik#3274
に丸投げしますが、そういうことです。

@AsPJT AsPJT merged commit 3091b6b into AsPJT:master May 20, 2019
@AsPJT AsPJT added bug Something isn't working enhancement New feature or request labels May 20, 2019
@AsPJT
Copy link
Owner

AsPJT commented May 20, 2019

Clang 3.4 , 3.5で正常に動作することを確認しました。

@yumetodo yumetodo deleted the fix/clang3_4 branch May 20, 2019 02:32
@AsPJT
Copy link
Owner

AsPJT commented May 22, 2019

@yumetodo

Clang 3.4 , 3.5ですが、

サンプルコード

#include <DTL.hpp>

int main() {

}

出力

Start
0
Finish

サンプルコード

#include <DTL.hpp>
#include <array>

int main() {

	std::array<std::array<int, 80>, 50> matrix{ {} };
	dtl::CellularAutomatonMixIsland<int>(100, 0, 1, 2, 3, 4, 5).draw(matrix);

}

出力

Start
/tmp/prog-fbb02f.o: In function `__tls_init':
prog.cc:(.text+0x1e6): undefined reference to `__cxa_thread_atexit'
prog.cc:(.text+0x207): undefined reference to `__cxa_thread_atexit'
prog.cc:(.text+0x22f): undefined reference to `__cxa_thread_atexit'
clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation)
1
Finish

のように DTL の機能を使用するとエラーが出てしまうみたいですね。

@yumetodo
Copy link
Contributor Author

ん?C++11のThread使ってるんです?それなら対処は簡単ですよ。
https://qiita.com/yumetodo/items/bd8f556ab56298f19ba8#c11-thread%E3%82%92%E4%BD%BF%E3%81%86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants