More Related Content
Similar to 家に帰るまでが遠足です (20)
家に帰るまでが遠足です
- 13. プログラムを実⾏する
までが C++ です.
$ g++ ‐c main.cpp
$ g++ main.o
$ ./a.out
Segmentation fault (core dumped)
13
- 14. プログラムを実⾏する
までが C++ です.
$ g++ ‐c main.cpp
$ g++ main.o
$ ./a.out
Segmentation fault (core dumped)
ここまでが C++ による
プログラミングです 14
- 21. デバッグビルド &
リリースビルド
デバッグ情報あり
最適化なし
$ g++ ‐g main.cpp
and デバッグ情報なし
最適化あり
$ g++ ‐O3 main.cpp
21
- 22. シングルスレッド &
マルチスレッド
スレッドなし
$ g++ ‐DSINGLE_THREAD
main.cpp
and スレッドあり
$ g++ ‐DMULTI_THREAD
‐pthread main.cpp
22
- 34. {GCC 4.6.3, GCC 4.7.1}
×
Boost.Build を使えば……
{デバッグビルド,リリースビルド}
×
{シングルスレッド,マルチスレッド}
# jamfile
exe main.exe : main.cpp ;
の合計8通りのビルド設定同時⼀⻫
$ bjam toolset=gcc‐4.6.3,gcc‐4.7.1
variant=debug,release
threading=single,multi
34
- 39. Boost.Build のターゲットと
実際のファイルは一対多
<variant>debug
bin/debug/main.o
# jamfile bin/debug/main
exe main.exe
: main.cpp ;
bin/release/main.o
<variant>release
bin/release/main 39
- 40. Boost.Build のターゲットと
実際のファイルは一対多
<variant>debug
bin/debug/main.o
# jamfile bin/debug/main
exe main.exe feature が依存物の
: main.cpp ; パスとして埋め込まれる
bin/release/main.o
<variant>release
bin/release/main 40
- 46. 最終成果物がリリースなら
中間⽣成物も全部リリース
中間⽣成物も全部
リリースビルド
foo.o 最終成果物をリリース
$ g++ ‐O3 –c foo.cpp ビルドするなら……
bar.o リリースビルド
リンク
$ g++ ‐O3 –c bar.cpp 実⾏バイナリ
main.o
$ g++ ‐O3 –c main.cpp
46
- 49. 最終成果物がデバッグなら
中間⽣成物も全部デバッグ
中間⽣成物も全部
デバッグビルド
foo.o 最終成果物をデバッグ
$ g++ ‐g –c foo.cpp ビルドするなら……
bar.o デバッグビルド
リンク
$ g++ ‐g –c bar.cpp 実⾏バイナリ
main.o
$ g++ ‐g –c main.cpp
49
- 52. 共有ライブラリをビルドす
るなら中間⽣成物全部 PIC
中間⽣成物
全部 PIC
foo.o 共有ライブラリを
$ g++ ‐fPIC –c foo.cpp ビルドするなら……
bar.o
libfoo.so
$ g++ ‐fPIC リンク
–c bar.cpp
baz.o
$ g++ ‐fPIC –c baz.cpp
Linux/ELF 52
- 68. feature の伝播
(feature propagation)
foo.cpp main.cpp
$ g++ ‐g ‐c foo.cpp $ g++ ‐g ‐c main.cpp
foo.obj main.obj
<variant>debug <variant>debug
bin/debug/foo.o bin/debug/main.o
$ g++ foo.o main.o –o main
main.exe
<variant>debug
68
bin/debug/main
- 69. feature の伝播
(feature propagation)
foo.cpp main.cpp
$ g++ ‐g ‐c foo.cpp $ g++ ‐g ‐c main.cpp
foo.obj main.obj
やりたかったことが
<variant>debug <variant>debug
実現できました
bin/debug/foo.o bin/debug/main.o
$ g++ foo.o main.o –o main
main.exe
<variant>debug
69
bin/debug/main
- 76. // foo.hpp マクロ定義で
class Foo
ABI が変化
{
.....
#if defined(CHECK)
#include DebugInfo dbg_info_; #include
#endif
bar.cpp }; main.cpp
76
- 77. // foo.hpp マクロ定義で
class Foo
ABI が変化
{
.....
#if defined(CHECK)
#include DebugInfo dbg_info_; #include
#endif
bar.cpp }; main.cpp
$ g++ ‐DCHECK –c bar.cpp $ g++ –c main.cpp
bar.o main.o
77
- 78. // foo.hpp マクロ定義で
class Foo
ABI が変化
{
.....
#if defined(CHECK)
#include DebugInfo dbg_info_; #include
#endif
bar.cpp }; main.cpp
$ g++ ‐DCHECK –c bar.cpp $ g++ –c main.cpp
bar.o Foo のオブジェクトをやり取り main.o
78
- 79. // foo.hpp マクロ定義で
class Foo
ABI が変化
{
.....
#if defined(CHECK)
#include DebugInfo dbg_info_; #include
#endif
bar.cpp }; main.cpp
$ g++ ‐DCHECK –c bar.cpp $ g++ –c main.cpp
bar.o Foo のオブジェクトをやり取り main.o
$ g++ main.o bar.o
a.out 79
- 80. // foo.hpp マクロ定義で
class Foo
ABI が変化
{
.....
#if defined(CHECK)
#include DebugInfo dbg_info_; #include
#endif
bar.cpp }; main.cpp
$ g++ ‐DCHECK –c bar.cpp $ g++ –c main.cpp
bar.o Foo のオブジェクトをやり取り main.o
$ g++ main.o bar.o
a.out 80
- 81. // foo.hpp マクロ定義で
class Foo
ABI が変化
{
.....
#if defined(CHECK)
#include DebugInfo dbg_info_; #include
ABI を変化させる
#endif
bar.cpp }; main.cpp
マクロ定義を
安全に扱いたい
$ g++ ‐DCHECK –c bar.cpp $ g++ –c main.cpp
bar.o Foo のオブジェクトをやり取り main.o
$ g++ main.o bar.o
a.out 81
- 86. Boost.Build を使えば……
# jamfile 新しい feature
<check> をユーザ定義
import feature ;
feature.feature check
: off on : propagated ;
feature.compose <check>on
: <define>CHECK ; 86
- 87. Boost.Build を使えば……
# jamfile 新しい feature
<check> をユーザ定義
import feature ;
feature.feature check
: off on : propagated ; なら
<check>on
“CHECK” マクロを定義
feature.compose <check>on
: <define>CHECK ; 87
- 95. 共有ライブラリに依存した
バイナリを実⾏したい
foo.cpp
$ g++ ‐fPIC –shared …
libfoo.so test.o
$ g++ test.o ‐lfoo –o test
test
$ ./test
95
- 96. 共有ライブラリに依存した
バイナリを実⾏したい
foo.cpp
$ g++ ‐fPIC –shared …
libfoo.so test.o
$ g++ test.o ‐lfoo –o test
foo が見つからねーよ!
96
- 98. 共有ライブラリに依存した
バイナリを実⾏したい
foo.cpp
$ g++ ‐fPIC –shared …
libfoo.so test.o
$ g++ test.o ‐L. ‐lfoo –o test
test
$ ./test
98
- 99. 共有ライブラリに依存した
バイナリを実⾏したい
foo.cpp
$ g++ ‐fPIC –shared …
libfoo.so test.o
$ g++ test.o ‐L. ‐lfoo –o test
test
$ ./test
libfoo.so 見つからねーよ! 99
- 110. usage-requirement
(これを使うならこうしろ!)
foo.lib test.obj
bin/debug/libfoo.so
test.exe $ g++ ‐Lbin/debug …
<library-path>bin/debug
bin/debug/test
$ LD_LIBRARY_PATH=bin/debug …
test.run
<xdll-path>bin/debug
110
bin/debug/test.run
- 111. usage-requirement
(これを使うならこうしろ!)
foo.lib test.obj
bin/debug/libfoo.so
test.exe $ g++ ‐Lbin/debug …
やりたかったことが
<library-path>bin/debug
実現できました bin/debug/test
$ LD_LIBRARY_PATH=bin/debug …
test.run
<xdll-path>bin/debug
111
bin/debug/test.run