Showing posts with label MacOS. Show all posts
Showing posts with label MacOS. Show all posts

Saturday, April 19, 2014

[MacOS] MacOS 10.9(Mavericks)上clang对未知参数报错的问题

在MacOS 10.9上用pip安装一个库的时候发现clang报错
$ sudo pip install mysql-python
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.16/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.9-intel-2.7/_mysql.o -Os -g -fno-strict-aliasing

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

error: command 'cc' failed with exit status 1

原因

XCode 5.1 以后, XCode的默认编译器clang会对所有它不认识的命令行flag报错 http://kaspermunck.github.io/2014/03/fixing-clang-error/

解决方法

参照这里给出的方案: http://stackoverflow.com/questions/22313407/clang-error-unknown-argument-mno-fused-madd-python-package-installation-fa

在运行安装命令的时候先修改CFLAGS和CPPFLAGS
$ export CFLAGS=-Qunused-arguments
$ export CPPFLAGS=-Qunused-arguments
$ sudo -E pip install mysql-python
注意由于安装过程中需要sudo, 所以为了让环境变量传递过去, 需要加上-E选项

[MacOS] 在MacOS 10.9(Mavericks)设置Apache/PHP

本来想自己写的. 但这篇实在写的太详实太好了.
http://www.coolestguidesontheplanet.com/downtown/get-apache-mysql-php-and-phpmyadmin-working-osx-109-mavericks
就捡几个重点的供我自己查询吧:

启动/关闭/重启apache server

$ sudo apachectl start
$ sudo apachectl stop
$ sudo apachectl restart

几个重要的文件和路径

  • 设置文件
    • httpd的全局设置文件:/etc/apache2/httpd.conf
    • 用户apc999的设置文件:/etc/apache2/users/apc999.conf
  • apache的日志
    • /var/log/apache2/error_log
    • /var/log/apache2/access_log
  • web路径对应的本地路径
    • http://localhost/ 对应的本地路径 /Library/WebServer/Documents/
    • http://localhost/~apc999 对应本地路径 /Users/apc999/Sites

Monday, February 17, 2014

[Emacs] Mac OS Terminal中设置Emacs热键

由于工作条件的一些限制,我不能在MacOS中之间使用单独的Emacs App而必须要在Terminal里运行Emacs.所以我花时间设置了一下我的Emacs,使的它在Terminal中也可以像在App里一样完美运行.

最大的障碍来自于Terminal里对于热键的设置


在Terminal里设置按键(单独的按键以及组合按键)所激发的xterm key code. 下面这张图是我的设置:
主要是关于方向键加上ctrl/shift/alt的组合.

关于xterm key Code:

Terminal将按键事件转换成一个xterm key code并发送给当前窗口中运行的shell. 比如Shift加上方向键up被记录成一个code "\033[1;2A". 这里"\033"其实对应的是Esc键.
关于更多的xterm key code的简介可以从这里获得:


更加完整的的关于xterm code的reference:
总而言之, 你需要把你需要用到的组合按键设置在Terminal中, 使得Emacs可以收到

剩下的就是对于Emacs里热键的设置


Emacs的key mapping系统无比的复杂. 我使用了一种笨办法: 把每一个我关心的热键组合的xterm key code都在input-decode-map里定义成对应的组合键. 比如下面的设置. 这里"\e"相当于"\033"
(define-key input-decode-map "\e[9A" [(meta up)])
(define-key input-decode-map "\e[9B" [(meta down)])
(define-key input-decode-map "\e[9C" [(meta right)])
(define-key input-decode-map "\e[9D" [(meta left)])
(define-key input-decode-map "\e[2A" [(shift up)])
(define-key input-decode-map "\e[2B" [(shift down)])
(define-key input-decode-map "\e[2C" [(shift right)])
(define-key input-decode-map "\e[2D" [(shift left)])
(define-key input-decode-map "\e[10A" [(shift meta up)])
(define-key input-decode-map "\e[10B" [(shift meta down)])
(define-key input-decode-map "\e[10C" [(shift meta right)])
(define-key input-decode-map "\e[10D" [(shift meta left)])

这样Emacs才能在key stream里识别出来传进来的meta/shift/ctrl等热键. 然后再使用Emacs里的global-set-key来绑定组合到特定的function上, 比如我设置meta加up为backward-paragraph:
(global-set-key [(meta up)] 'backward-paragraph)
(global-set-key [(meta down)] 'forward-paragraph)
(global-set-key [(meta left)] 'backward-word)
(global-set-key [(meta right)] 'forward-word)

Wednesday, May 22, 2013

查看gcc预定义的macro

在Linux或者MacOS的terminal里运行:
$ cpp -dM /dev/null
#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 65535
#define __FLT_MIN__ 1.17549435082228750797e-38F
#define __UINT_LEAST8_TYPE__ unsigned char
#define __INTMAX_C(c) c ## L
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 255
#define __WINT_MAX__ 4294967295U
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 18446744073709551615UL
#define __WCHAR_MAX__ 2147483647
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __DBL_DENORM_MIN__ ((double)4.94065645841246544177e-324L)
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __FLT_EVAL_METHOD__ 0
#define __unix__ 1
...
一般说来Linux平台上会预定义__linux__, 而MacOS会预定义__APPLE__

Friday, May 20, 2011

[Linux/Mac]编译相关的工具和命令

GNU make的常用变量

  • CFLAGS: C compiler的flags,会被传递给关于C代码的compile和link的命令
  • CXXFLAGS: C++ compiler的flags,会被传递给关于C++的compile和link的命令
  • CPPFLAGS: C PreProcessor的flags(注意,不要和CXXFLAGS混淆)。它会被传递给编译C以及C++代码的命令
  • LDFLAGS: linking阶段的选项。常用来指定一些库文件的位置 比如"-L/usr/local/Cellar/gettext/0.18.1.1/lib"
  • CC: C Compiler。比如"gcc", "cc"
  • CXX: C++ Compiler。比如"g++"
参考:
http://stackoverflow.com/questions/495598/difference-between-cppflags-and-cxxflags-in-gnu-make

autoconf

根据configure.ac生成configure文件
$ autoconf configure.ac > configure
$ chmod +x configure
$ ./configure
参见A brief introduction to autoreconf
http://sourceware.org/autobook/autobook/autobook_toc.html#SEC_Contents

autoreconf

根据configure.ac, 会调用autoconf, autoheader, aclocal, automake, libtoolize, 以及autopoint等工具生成configure文件. 然后configure再根据Makefile.am生成Makefile
$ autoreconf -is
$ ./configure
$ make
参见Using autoreconf to Update configure Scripts

configure

增加额外的编译参数(比如默认的configure找不到某个包,就需要显式的告诉它路径)
Bash底下
$ LDFLAGS="-L/opt/local/lib" CXXFLAGS="-I/opt/local/include"\
 PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/" ./configure
或者csh底下
$ env LDFLAGS="-L/opt/local/lib" CXXFLAGS="-I/opt/local/include"\
 PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/" ./configure
configure的常用参数包括
  • --prefix: 通常默认为 "--prefix=/usr/local"
  • --enable-shared: build shared libraries,否定为"--enable-shared=no"或者"--disable-shared"
  • --enable-static: build static libraries,否定为"--enable-static=no"或者"--disable-static"

ldd

显示一个可执行文件或者一个shared library文件(.so文件)所dependent的其他.so文件
$ ldd a.out 
 linux-vdso.so.1 =>  (0x00007fff4c5ff000)
 libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f55df989000)
 libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f55df5ea000)
 /lib64/ld-linux-x86-64.so.2 (0x00007f55dfc3b000)

nm

查看一个obj文件的symbol table
$ nm mypair.o
000001c4 s EH_frame1
000001a5 s __GLOBAL__I_mypair.cc
00000254 s __GLOBAL__I_mypair.cc.eh
00000153 s __Z41__static_initialization_and_destruction_0ii
0000022c s __Z41__static_initialization_and_destruction_0ii.eh
         U __ZNKSs4sizeEv
         U __ZNKSsixEm
         U __ZNSt8ios_base4InitC1Ev
         U __ZNSt8ios_base4InitD1Ev
0000012c S __ZSt3minImERKT_S2_S2_
000001e0 S __ZSt3minImERKT_S2_S2_.eh
00000000 t __ZStL17__verify_groupingPKcmRKSs
00000204 s __ZStL17__verify_groupingPKcmRKSs.eh
000002a8 b __ZStL8__ioinit
         U ___cxa_atexit
         U ___dso_handle
         U ___gxx_personality_v0
00000104 t ___tcf_0
00000278 s ___tcf_0.eh

strip

减小一个可执行文件的size。代码体积变小后可能会对icache有帮助。代价是symbol table等帮助debug的信息会被移除。
$ strip a.out

pkg-config

pkg-config相当于一个数据库,用以维护系统中那些已经安装了的library。
比如你可以通过--modversion来查询某个library的版本
$ pkg-config --modversion openssl
0.9.8j
也可以用--cflags以及--libs查询在Makefile里使用一个library所需要使用的include的路径和其他选项。比如:
$ pkg-config --cflags thrift
-I/usr/local/include/thrift  
$ pkg-config --libs thrift  
-L/usr/local/lib -lthrift
pkg-config中的library数据库是通过搜索特定路径下的一系列xxx.pc文件来建立的。每个.pc文件对应一个library,包括了这个library的一些metadata。可以通过如下命令来查看当前数据库中包含了哪些library了。
$ pkg-config --list-all

Thursday, September 09, 2010

[Linux/Mac]删除所有.svn文件夹

用于删除一个目录下(以及其子目录下)所有的.svn目录
$ rm -rf `find . -type d -name .svn`

Saturday, April 17, 2010

[Python]py2app:将python程序转换为Mac OS Application的工具

先安装py2app
安装完毕后会有一个叫py2applet的程序出现
接下来进入我们python程序的目录,比如我们的程序叫HelloWorld.py
第一步: 生成HelloWorld的setup.py
$ py2applet --make-setup HelloWorld.py
第二步: 生成HelloWorld.app的结构
$ python setup.py py2app -A

Monday, March 29, 2010

[Linux/Mac]package/library管理工具

Ubuntu


很好的一个reference: Ubuntu Skills

安装软件
  • 从源安装是最方便最快捷的方式. 源的设置在/etc/apt/sources.list当中.
    如果知道需要安装的包的名称, 比如叫foo. 那么安装foo只需要
    apt-get install foo
    如果不知道确切名字,只知道大概是关于foo这个东西的, 可以通过下面的命令来搜索所有关于foo的包
    apt-cache search foo
    还有时候连包都不知道, 但是只知道需要某个文件比如叫foo.c,但不清楚应该装哪个包, 这时候可以先安装apt-file
    apt-get install apt-file
    然后用apt-file来帮你找可能是哪个包有这个文件
    apt-file search foo.c
  • 也可以下载deb文件来安装
    dpkg -i foo.deb


自动更新所有过时的package
apt-get update
卸载package foo
apt-get remove foo
彻底卸载package foo (连同配置文件一起删除)
apt-get remove --purge foo
自动卸载不需要的包
apt-get autoremove
查看某个包foo的详细信息
apt-cache show foo
查看repository中package foo的版本
apt-cache policy foo
添加某个源的key
apt-key add bar.asc

安装完之后, 通常用dpkg来管理包
查看package foo所安装的文件以及路径
dpkg -L foo
显示包的信息
dpkg -s packagename
显示包括指定文件的包
dpkg -S filename
显示指定包的状态
dpkg --get-selections packagename
配置某个包
dpkg --configure packagename
配置所有的包
dpkg --configure -a


MacOS中的home brew

https://github.com/mxcl/homebrew/wiki/The-brew-command
非常好用的MacOS下的包管理软件.强烈推荐.
一个brew的cheatsheet: http://cheat.errtheblog.com/s/brew/ 一个安装包时候常遇到的问题
$ sudo brew install ruby
Cowardly refusing to `sudo brew install'
这是by design. 我的解决方法是吧brew的onwer设成root
brew install foo
brew cleanup foo

如何为brew制作Formula:Formula Cookbook

MacOS中的port

关于port的使用MacPorts Guide
安装包foo
port install foo
删除包foo
port uninstall foo
查看包foo的相关信息
port info foo
查看所有过时的包
port outdated
更新所有过时的包
port upgrade outdated
查看已经安装的包
port installed
清除所有已安装包的临时文件
port clean --all installed
彻底删除旧的包
port -f uninstall inactive
删除inactive的包
port -u uninstall
port uninstall inactive
清理foo包的中间文件(比如损坏了)
port clean foo
安装foo这个包之前先将其deactivate
port deactivate foo
port activate foo
查看foo这个包都在本机安装了哪些文件
port contents foo
查看foo这个包都依赖哪些其他包
port deps foo
查看哪些包依赖foo
port dependents foo

Saturday, April 11, 2009

[MacOS] MacOS系统使用经验笔记

  1. 在Finder中找隐藏目录的热键: shift+command+G。默认的finder界面里是不会显示隐藏目录的。所以用上述热键然后手动输入路径
  2. MacOS X中设置环境变量和普通Unix/Linux的方法略有不同。你依然可以像在Unix/Linux 中那样在~/.cshrc(tcsh)或者~/.bashrc(bash)里设置环境变量,对于terminal中的程序完全没有问题。但是对于基于Carbon或者Cocoa的Native Mac程序(比如Carbon Emacs)来说是没有用的。它们不会从shell中继承环境变量。一个方法是把$PATH, $PYTHONPATH等环境变量设置在~/.MacOSX/environment.plist这里。可以用(a) "/Developer/Applications/Utilities/Property List Editor.app"这个工具修改. 也可以(b) 用defaults 命令:
    defaults write ${HOME}/.MacOSX/environment PATH "${HOME}/bin:/usr/bin:/bin:/usr/local/bin"

    为了在系统中使用统一的设置,在~/.cshrc中, 使用如下命令:
    setenv PATH `defaults read ~/.MacOSX/environment PATH` 


    注意: 需要重启以使改变生效
    Updated on Aug 27, 2012: ~/.MacOSX/environment.plist 已经deprecated了. 新的方法是修改/etc/launchd.conf使得所有Unix 环境变量在GUI中可见 参考Accessing the Unix environment from emacs and Cocoa apps in OS X Mountain Lion
  3. 显示Mac里系统相关信息
    查看总体的系统信息
    $ system_profiler
    查看CPU信息
    $ sysctl -a machdep.cpu
    或者
    $ sysctl -n machdep.cpu.brand_string
    Intel(R) Core(TM) i5-2435M CPU @ 2.40GHz
  4. 如果从打开Terminal开始到出现提示符为止的等待时间过长, osxdaily说这是由于系统的login process会读取/private/var/log/asl下所有的系统日志文件.所以我们可以把这些日志删除来加速login过程
    sudo rm -rf /private/var/log/asl/*.asl
  5. 用命令行打印文件
    $ lpstat -a
    GHC6107_BW accepting requests since Sun Oct 28 15:30:42 2012
    GHC9206_BW accepting requests since Mon Oct 29 12:48:11 2012
    GHC9206_COLOR accepting requests since Mon Nov 28 13:00:02 2011
    
    $ lp -d "GHC9206_BW" -o sides=two-sided-long-edge *.pdf
    request id is GHC9206_BW-82 (6 file(s))
  6. 在Lion以及Mountain Lion中关掉ipv6
    $ networksetup -setv6off ethernet
    $ networksetup -setv6off wi-fi