C++を混載
mmファイルを使うとCの関数(特にObjective-Cのアマルガム的な)が呼べなくなるので注意
NSNotFound
NSNotFoundは型に注意しないでロジックミスになる。注意。
duplicate symbols
久々にはまったが、よくみたところヘッダーでimportしていたファイルが.mになっていた。。
FaceBookPHP
以下を参照した。
Facebook PHPをComposerで利用するには | hrendoh's memo
comporser.jsonのrequireにfacebook/php-sdkを追加
curl -s http://getcomposer.org/installer | php
でcomposer.pharを落として
php composer.phar install
警告が出た。
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
updateしてみる。
php composer.phar update
次の警告が出た。
Package facebook/php-sdk is abandoned, you should avoid using it. Use facebook/graph-sdk instead.
comporser.jsonのrequireにfacebook/graph-sdkを追加
composer.phar update
***/MAMP/htdocs/hogeApp/vendor/facebook
にインストールされた。
通常使うものイディオム
普段使うものを羅列していく。
特定の文字列を検索
find . -name "*.php"|xargs grep hoge
grep hoge_ -rl ./
権限付与
chmod a+x hoge.txt
例でははすべてのユーザに実行権限を与えている。
他には
Linuxコマンド集 - 【 chmod 】 ファイルやディレクトリのアクセス権を変更する:ITpro
一覧
- ls -a ドットファイル含む
- ls -all すべての情報
ファイル、フォルダ作成
ファイル
touch x.txt
フォルダ
mkdir hoge
名前変更
mv hoge.txt hogeafter.txt
コピー
cp hoge.txt hogecp.txt
中身をみる
cat hoge.txt
ビルトインサーバー
./bin/cake server
で、http://localhost:8765/ にアクセス。
基礎
c++の基礎的なことをさらった。
// // main.cpp // cppABC // // Created by KatagiriSo on 2017/06/28. // Copyright © 2017年 rodhos. All rights reserved. // #include <iostream> #include <sstream> #include <iomanip> #include <fstream> // ref:http://ppp-lab.sakura.ne.jp/ProgrammingPlacePlus/cpp/language/004.html struct Point { int x; int y; int d2(); }; enum MyType : int { GREEN,RED,YELLOW }; enum struct MyType2 : int { GREEN,RED,YELLOW }; enum class MyType3 : int { GREEN,RED,YELLOW }; double getValue(); namespace spaceA { double getValue(); namespace specialB { double getValue(); } inline namespace Util { double getUtilValue(); } } // file only namespace { const int MAX = 1000; } int globalX = 2000; namespace SpaceC { void helloSpaceC(); } int twice(int x); int twice(float x); //float twice(int x); NG // default int fc(int x = 1000); // template template <typename T> void echo(T x); template <typename R, typename T1, typename T2> R echo(T1 x, T2 y); // new function def auto nfunc(int x) -> int; auto nfunc2(int x) -> decltype(x); // inline inline int infunc(int x); // class class Man { public: void hello(); Man(); // default constructer Man(std::string name); ~Man(); // static int commonNumber; bool operator==(const Man& rhs) const; inline bool operator!=(const Man& rhs) const { return !(*this == rhs); } private: std::string name; int age; void util(); int n = 10; }; void hello(Man *m); // constexpr template <typename T> class Poi { public: void echo(T x); }; int main(int argc, const char * argv[]) { // insert code here... std::cout << "Hello, World!\n"; // struct Point p; p.x = 10; std::cout << p.x << std::endl; // enum MyType type = MyType::RED; MyType2 type2 = MyType2::RED; MyType3 type3 = MyType3::RED; std::cout << type << std::endl; std::cout << static_cast<int>(type2) << std::endl; std::cout << static_cast<int>(type3) << std::endl; // auto auto v = getValue(); std::cout << v << std::endl; // namespace double v2 = spaceA::getValue(); double v3 = spaceA::specialB::getValue(); double v4 = spaceA::getUtilValue(); std::cout << v2 << std::endl; std::cout << v3 << std::endl; std::cout << v4 << std::endl; std::cout << MAX << std::endl; std::cout << globalX << std::endl; // using using namespace SpaceC; helloSpaceC(); // alias namespace B = spaceA::specialB; double b = B::getValue(); std::cout << b << std::endl; // string std::string hoge("hoge"); std::string empty; std::string str = hoge; std::string hoge2("hoge"); std::cout << hoge << std::endl; std::cout << "empty=" << empty << std::endl; std::cout << str << empty << std::endl; if (hoge == hoge2) { std::cout << "hoge == hoge2" << std::endl; } std::cout << hoge.size() << std::endl; std::cout << hoge.length() << std::endl; std::cout << empty.empty() << std::endl; // ostringstream std::ostringstream oss; oss << "hello" << std::endl; std::cout << oss.str() << std::endl; // istringstream std::istringstream inputstream("hoge 200 300.3"); std::string s; int num; double d; inputstream >> s >> num >> d; std::cout << "s=" << s << " num=" << num << " d=" << d << std::endl; // escape std::string stresc = "a\nb\nc"; std::string stresc2 = R"(a b c)"; std::cout << stresc << std::endl; std::cout << stresc2 << std::endl; #if 0 // cin std::cout << "input number" << std::endl; int x; std::cin >> x; std::cout << "x=" << x << std::endl; #endif // error std::cerr << "cerr!" << std::endl; std::clog << "clog!" << std::endl; // buffering #if 0 // manipulator std::cout << "input string (size 3)" << std::endl; char ch[3]; std::cin >> std::setw(sizeof(ch)) >> ch; std::cout << "ch=" << ch << std::endl; // endl is also manipulator #endif // file std::ofstream ofs("test.txt"); if (!ofs) { std::cerr << "[error]open file" << std::endl; std::exit(1); } ofs << "Hello, World\n123" << std::endl; // auto close std::ifstream ifs("test.txt"); if (!ifs) { std::cerr << "[error]open file for ifstream." << std::endl; std::exit(1); } std::string bufstr; ifs >> bufstr; std::cout << bufstr << std::endl; //[note] output is Hello, std::ifstream ifs2("test.txt"); if (!ifs2) { std::cerr << "[error]open file for ifstream." << std::endl; std::exit(1); } std::string bufstr2; getline(ifs2, bufstr2); std::cout << bufstr2 << std::endl; //[note] output is Hello, World getline(ifs2, bufstr2); std::cout << bufstr2 << std::endl; //[note] output is 123 if (ifs2.eof()) { std::cout << "eof" << std::endl; //[note] output is 123 } // null pointer int* a = nullptr; if (a == nullptr) { std::cout << "nullptr" << std::endl; } // decltype int sample = 100; decltype(sample) sample2 = 200; // Type of sample2 is Int. decltype(getValue()) sample3 = 3.3;// Type of sample3 is Int. std::cout << sample << sample2 << sample3 << std::endl; // overload std::cout << twice(3) << std::endl; std::cout << twice(3.5f) << std::endl; // default std::cout << fc() << std::endl; // template echo(3); echo("hello"); echo<std::string>("hello"); std::cout << echo<int>(3, 4) << std::endl; std::cout << echo<float>(3.1f, 4.2f) << std::endl; // new function def std::cout << nfunc(10) << std::endl; std::cout << nfunc2(10) << std::endl; // inline std::cout << infunc(100) << std::endl; Man man; Man man2("poi"); man.hello(); man2.hello(); hello(&man); const int c = 3; // c = 4; error Man *man3 = new Man(); man3->hello(); delete man3; // std::cout << "man.commonNumber = " << Man::commonNumber << std::endl; // 3 // ref int r = 0; int& r2 = r; r2 = 100; std::cout << r << std::endl; // 100 // template class Poi<std::string> p1; Poi<int> p2; p1.echo("hello"); p2.echo(3); using Name = std::string; Name name = "name"; typedef Poi<std::string> PoiStr; PoiStr p3; p3.echo("hello2"); return 0; } int Point::d2() { return this->x + this->y; } double getValue() { return 2.0; } namespace spaceA { double getValue() { return 20.0; } namespace specialB { double getValue() { return 30; } } inline namespace Util { double getUtilValue() { return 50; } } } namespace SpaceC { void helloSpaceC() { std::cout << "Hello, CpaceC." << std::endl; } } int twice(int x) { return x * 2; } int twice(float x) { return x * 2; } int fc(int x) { return x+1000; } template <typename T> void echo(T x) { std::cout << x << std::endl; } template <typename R, typename T1, typename T2> R echo(T1 x, T2 y) { return static_cast<R>(x+y); } auto nfunc(int x) -> int { return x*10; } auto nfunc2(int x) -> decltype(x) { return x * 100; } inline int infunc(int x){ return x+1; } void Man::hello() { std::cout << "Hello, my name is " << this->name << std::endl; } void Man::util() { std::cout << "util" << std::endl; } Man::Man() : name("name"), age(0){ // commonNumber++; } Man::Man(std::string name) { this->name = name; age = 0; // commonNumber++; } Man::~Man() { std::cout << "dec" << std::endl; } void hello(Man *m) { m->hello(); } bool Man::operator==(const Man &rhs) const { return name == rhs.name; } template <typename T> void Poi<T>::echo(T x) { std::cout << "echo" << x << std::endl; }
デバッグ クラッシュログ
以下のサイトが参考になった。
stackoverflow.com
デバッグ シンボライズ
Xode内にあるsymbolicatecrashを使う。以下を参照した。
www.crunchtimer.jp
まず探す。Xcode8のフォルダ内で
find . -name symbolicatecrash /Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
面倒なので適当にln -sでシンボリックリンクを作っておく。
次に対応するアプリのdSYMファイルがいる。
Library/Developer/Xcode/DerivedData/hogehoge/Build/Products/Debug-iphoneos
実行してみる
./symbolicatecrash hoge.crash hoge.app.dSYM/ Error: "DEVELOPER_DIR" is not defined at ./symbolicatecrash line 69.
シンボリックリンクをはる。
$ export DEVELOPER_DIR=”/Applications/Xcode.app/Contents/Developer/”
再度実行した。
xcrun: error: missing DEVELOPER_DIR path: ”/Applications/Xcode.app/Contents/Developer/” ## Warning: can't find tool named 'otool' in iOS SDK, falling back to searching the Mac OS X SDK xcrun: error: missing DEVELOPER_DIR path: ”/Applications/Xcode.app/Contents/Developer/” Error: can't find tool named 'otool' in the macosx SDK or any fallback SDKs at ./symbolicatecrash line 122.
以下のサイトのやり方に従う
stackoverflow.com
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer
xcode-selectのヘルプをみてみた。
/usr/bin/xcode-select -h Usage: xcode-select [options] Print or change the path to the active developer directory. This directory controls which tools are used for the Xcode command line tools (for example, xcodebuild) as well as the BSD development commands (such as cc and make). Options: -h, --help print this help message and exit -p, --print-path print the path of the active developer directory -s <path>, --switch <path> set the path for the active developer directory --install open a dialog for installation of the command line developer tools -v, --version print the xcode-select version -r, --reset reset to the default command line tools path
xcode-selectのswitchをやりつつDEVELOPER_DIRのシンボリックリンクをはった結果
symbolicatecrashに成功した。
個々の解析
しかし、なぜかdSYMがうまく読み込めなかったため、方針を変更し以下のサイトに従ってatosをためした。
developer.apple.com
クラッシュレポートの以下をシンボル化したいとする。
0 Hoge 0x00000001000ea5d8 0x100020000 + 828888
atos -arch arm64 -o HogeApp.app.dSYM/Contents/Resources/DWARF/Hoge -l 0x100020000 0x00000001000ea5d8
Hogeはbinary image name
0x100020000はload address
0x00000001000ea5d8はシンボル化したいアドレス
これでシンボル化ができた。
参照したサイト
www.crunchtimer.jp
irabbit.seesaa.net
stackoverflow.com
swiftc failed with exit code 1
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
で妙な現象にあった。
func reload(completion:@escaping (T?, Error?) -> Void) { objc_sync_enter(self.loadCompletions) loadCompletions.append(completion) objc_sync_exit(self.loadCompletions) self.reload() }
とすると発生し、
func reload(completion:@escaping (T?, Error?) -> Void) { objc_sync_enter(self.loadCompletions) loadCompletions = loadCompletions + [completion] objc_sync_exit(self.loadCompletions) self.reload() }
とすると発生しない。
これに気づくのにだいぶ時間を取られたが、発生理由がわからない。。loadCompletionsはvarで定義してあるのでappendで問題ないはずだが..。
同じ現象にあわれた人の参考になれば幸いです..orz。
swiftc
swiftcを使う。
which swiftc /usr/bin/swiftc
適当にswiftでコードを書いて、
import Foundation print("hello, world!")
ここではmain.swiftという名前にした。
swiftc main.swift
これで、mainという実行ファイルができるのじ実行するとhello worldできる。
出力を変えたい場合は
swiftc -o hoge main.swift
複数ファイル
main.swiftは
import Foundation
print("start")
let hello = Hello()
hello.hello()
新しくHello.swiftを
import Foundation
class Hello {
func hello() {
print("hello")
}
}
と作る。
swiftc main.swift Hello.swift
でいける。
ヘルプを見る
swiftc -help OVERVIEW: Swift compiler USAGE: swiftc [options] <inputs> MODES: -dump-ast Parse and type-check input file(s) and dump AST(s) -dump-parse Parse input file(s) and dump AST(s) -dump-type-refinement-contexts Type-check input file(s) and dump type refinement contexts(s) -emit-assembly Emit assembly file(s) (-S) -emit-bc Emit LLVM BC file(s) -emit-executable Emit a linked executable -emit-ir Emit LLVM IR file(s) -emit-library Emit a linked library -emit-object Emit object file(s) (-c) -emit-sibgen Emit serialized AST + raw SIL file(s) -emit-sib Emit serialized AST + canonical SIL file(s) -emit-silgen Emit raw SIL file(s) -emit-sil Emit canonical SIL file(s) -parse Parse input file(s) -print-ast Parse and type-check input file(s) and pretty print AST(s) OPTIONS: -application-extension Restrict code to those available for App Extensions -assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Unchecked, DisableReplacement. -D <value> Marks a conditional compilation flag as true -embed-bitcode-marker Embed placeholder LLVM IR data as a marker -embed-bitcode Embed LLVM IR bitcode as data -emit-dependencies Emit basic Make-compatible dependencies files -emit-module-path <path> Emit an importable module to <path> -emit-module Emit an importable module -emit-objc-header-path <path> Emit an Objective-C header file to <path> -emit-objc-header Emit an Objective-C header file -fixit-all Apply all fixits from diagnostics without any filtering -fixit-code Get compiler fixits as code edits -framework <value> Specifies a framework which should be linked against -F <value> Add directory to framework search path -gdwarf-types Emit full DWARF type info. -gline-tables-only Emit minimal debug info for backtraces only -gnone Don't emit debug info -g Emit debug info. This is the preferred setting for debugging with LLDB. -help Display available options -import-underlying-module Implicitly imports the Objective-C half of a module -index-store-path <path> Store indexing data to <path> -I <value> Add directory to the import search path -j <n> Number of commands to execute in parallel -L <value> Add directory to library link search path -l<value> Specifies a library which should be linked against -module-cache-path <value> Specifies the Clang module cache path -module-link-name <value> Library to link against when using this module -module-name <value> Name of the module to build -nostdimport Don't search the standard library import path for modules -num-threads <n> Enable multi-threading and specify number of threads -Onone Compile without any optimization -Ounchecked Compile with optimizations and remove runtime safety checks -output-file-map <path> A file which specifies the location of outputs -O Compile with optimizations -o <file> Write output to <file> -parse-as-library Parse the input file(s) as libraries, not scripts -parse-sil Parse the input file as SIL code, not Swift source -parseable-output Emit textual output in a parseable format -profile-coverage-mapping Generate coverage data for use with profiled execution counts -profile-generate Generate instrumented code to collect execution counts -sanitize-coverage=<type> Specify the type of coverage instrumentation for Sanitizers and additional options separated by commas -sanitize=<check> Turn on runtime checks for erroneous behavior. -save-temps Save intermediate compilation results -sdk <sdk> Compile against <sdk> -serialize-diagnostics Serialize diagnostics in a binary format -static-stdlib Statically link the Swift standard library -suppress-warnings Suppress all warnings -target-cpu <value> Generate code for a particular CPU variant -target <value> Generate code for the given target -tools-directory <directory> Look for external executables (ld, clang, binutils) in <directory> -use-ld=<value> Specifies the linker to be used -version Print version information and exit -v Show commands to run and use verbose output -warnings-as-errors Treat warnings as errors -whole-module-optimization Optimize input files together instead of individually -Xcc <arg> Pass <arg> to the C/C++/Objective-C compiler -Xlinker <value> Specifies an option which should be passed to the linker
参考になりそうなサイト
qiita.com
yamaimo.hatenablog.jp