万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    __declspec mac gcc C++

    error: unknown type name '__declspec' のエラー。

    本の虫: attributeは難しい

    Macというかgccでは__attribute__なの?

     __declspec(dllexport)

    を単純に

     __attribute__(dllexport)

    置き換え。

    すると

    error: expected '(' after '('

    (を二重にしたw

    __attribute__((dllexport))

    ここ見る c++ - GCC (ARM) equivalent to __declspec(dllexport) - Stack Overflow

    おそらくどっちか?

       #define idaman          EXTERNC __attribute__((visibility("default")))
        #define ida_local       __attribute__((visibility("hidden")))

    defaultの方にした。

    こうではない

    g++ -shared -std=c++11 -Iinclude Source.cpp ../mruby/build/host/lib/libmruby.a -o mruby-sample.dll

    これ

    g++ -shared -std=c++11 -Iinclude Source.cpp ../mruby/build/host/lib/libmruby.a -dynamiclib -fPIC  -o mruby.dylib

    最後

    g++ -shared -std=c++11 -Iinclude Source.cpp ../mruby/build/host/lib/libmruby    .a -dynamiclib  -arch x86_64 -o mruby.bundle

    これmruby.bundlePluginsに入れる。 Unityを再起動しないとミスったときにおかしくなる。

    mrubyの実行 macOS 10.12.3

    mrubyをダウンロードした。 mruby-1.2.0.tar.gz

    展開

    tar zxvf mruby-1.2.0.tar.gz

    ビルド

    cd mruby
    ruby minirake

    mrubyでコンパイル

    sample.cpp作る

    #include <stdlib.h>
    #include <stdio.h>
    #include "mruby.h"
    #include "mruby/compile.h"
    
    int main()
    {
        auto mrb = mrb_open();
        auto ai = mrb_gc_arena_save(mrb);
        mrb_load_string(mrb, "5.times.each {|i| p i * i }");
        mrb_gc_arena_restore(mrb, ai);
        mrb_close(mrb);
        return 0;
    }
    g++ -std=c++11 -Iinclude sample.cpp ../mruby/build/host/lib/libmruby.a

    ../mruby/build/host/lib/libmruby.aがないと

    Undefined symbols for architecture x86_64:
      "_mrb_close", referenced from:
          _main in sample-20efc4.o
      "_mrb_gc_arena_restore", referenced from:
          _main in sample-20efc4.o
      "_mrb_gc_arena_save", referenced from:
          _main in sample-20efc4.o
      "_mrb_load_string", referenced from:
          _main in sample-20efc4.o
      "_mrb_open", referenced from:
          _main in sample-20efc4.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    gcc, clang++, llvm-gcc ....

    $ which clang++
    /usr/bin/clang++
    
    $ which g++
    /usr/bin/g++
    
    $ which llvm-g++
    /usr/bin/llvm-g++
    
    $ which llvm-gcc
    /usr/bin/llvm-gcc
    
    $ which gcc
    /usr/bin/gcc

    Comparing clang to other open source compilers

    バージョンを見る

    $ clang -v
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    
    $ clang++ -v
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    $ g++ -v
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    
    $gcc -v
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    $ llvm-g++ -v
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    
    $ llvm-gcc -v
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

    実体は同じ?

    C++のコマンドラインのコンパイルでカレントでパスを入れたいとき Mac

    #inclide相対パスにしないといけなさそうでいちいちfile not foundになった。

    clang++ -std=c++11 -I ./ sample.cpp

    のように-Iオプションで./を指定した。

    ヘルプはclang++ --helpで見られた。