Misc Tips

编译
  • iOS

    • Pro-tip: you can use the xcrun tool to easily refer to the proper version of clang (i.e. the one from the iOS toolchain): CC=$(shell xcrun -sdk iphoneos -find clang)
    • Linking Against stdlibc++
          A static library project (for iOS) with an Objective-C interface uses internally a C++ implementation.

                 When creating an Objective-C application, I would like to keep the app project as less modified as possible when linking against the static library. Well, usually this requires the application to be linked against the C++ library, that is libstdc++.

                 It seems, I have these alternatives:

                     1) rename the main.m file to main.mm and the app project automatically links agains libstdc++.

                     2) add to "Other Linker Flags" the option "-lstdc++" of the target settings of the application.

                     3) add the libstdc++.dylib in the "Link Binary With Libraries" section of the Build Phases in the target settings of the application.   

                     (可能是iOS6的原因,我加入libstdc++.6.dylib才可编译通过,老版本未试验)

                I prefer option 1) as it seems the most reliable method, for several reasons.

                However, is there any better way, possibly one which does not require to add/change application build settings or modifies any of the applications source files?

 

 

 

雑多

  • To display macros which aren't strings, stringify the macro:
    #define STRINGIFY(s) XSTRINGIFY(s)
    #define XSTRINGIFY(s) #s

    #define ADEFINE 23
    #pragma message ("ADEFINE=" STRINGIFY(ADEFINE))

    If you have/want boost, you can use boost stringize to do it for you:
    #include <boost/preprocessor/stringize.hpp>
    #define ADEFINE 23
    #pragma message ("ADEFINE=" BOOST_PP_STRINGIZE(ADEFINE))

  • 制作patch文件
        diff -Naur 旧的目录 新的目录 > patch文件
  • iOS
    • 用NSPR在iOS上输出Log文件
              PRLogModuleInfo* test_lm;
              NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
              NSString *documentsDirectory = [paths objectAtIndex:0];       
              NSString *logPathEnv = [NSString stringWithFormat:@"%@%@/%@",@"NSPR_LOG_FILE=",documentsDirectory, @"test.log"];
             
              if(putenv("NSPR_LOG_MODULES=all:5") != 0){
                  fprintf(stderr, "putenv failed\n");
              }
             
              if(putenv((char*)logPathEnv.UTF8String) != 0){
                  fprintf(stderr, "putenv failed\n");
              }
             
              PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
              test_lm = PR_NewLogModule("test");
              PR_LOG(test_lm, PR_LOG_MIN, ("logfile: test log message"));
              PR_Cleanup();

  • VI光标移动
        ctrl-o 和 ctrl-i  光标上下次位置
        g;  和 g, 编辑过的上下位置

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值