Link libcurl statically in Xcode

[This post does not talk about compilation and installation of curl and libcurl. For more information, please refer to http://curl.haxx.se/docs/install.html.]

Linking *.dylib and *.a in Xcode should be straightforward and much easier than in Visual Studio. What we need to do is just to drag and drop the dependent library to “Link Binary With Libraries” in targets group section. (Surely, we need to set header search path to proceed compilation first.) But sometimes it’s this “straightforward” that makes things complicated instead.

For example, if we want to statically link libcurl.a in an application, intuitively, we will drag and drop libcurl.a to “Link Binary With Libraries”. But, I am sure you will not get what you want if you follow the above steps. When checking with “otool -L”, it’s surprising that your application will link against a dynamic version of libcurl, which is installed in “/usr/lib”. (Not the one you drag and drop) Digging into ld log output, you also will not be able to find libcurl.a shown in command line. Instead, you will see something like “-lcurl”. What’s even worse is that you will not be able to run the application. Exit with error no “-5” indicates “dynamic library not found/loaded”.

The reason is that, when we link against a system pre-installed framework/library, Xcode will not set that specific file in ld command line. Xcode will only set a library search path for it. There’re two kinds of search path format: 1) -L<absolute library install path>; 2) –l<library name>. In our case, “-lcurl” indicates Xcode will search the pre-installed location of libcurl. Another thing is the search ordering. ld will try to locate dynamic version of library, if not found, then try to use static version. [My comments: it’s a bad experience. Xcode should use the one I call out to use – drag and drop. Of course, we will not encounter this kind of silly problem, if we are using library that system doesn’t have the one owning the same library name.]

So, if we want to skip off the above search ordering, we have to explicitly set it. There comes a tool “curl-config” together with curl. We can use “curl-config –static-libs” to get the link options that we should set when using libcurl statically:

austin-dais-macbook:bin daiau$ ./curl-config –static-libs
/Users/daiau/Documents/build/lib/libcurl.a -lssl -lcrypto -lldap -lz

And set the above output directly in “Other Linker Flags” in Xcode’s target build configuration. [My comments: bad experience. Why not provide other linker option that is more descriptive? Like “Dependent Static Libraries”.]

Picture 5

Command + B to build and check the ld log:

Ld "/Users/daiau/Desktop/CIP Mac Client/cURL_Test/build/Debug/cURL_Test" normal i386
    cd "/Users/daiau/Desktop/CIP Mac Client/cURL_Test"
    setenv MACOSX_DEPLOYMENT_TARGET 10.5
    /Developer/usr/bin/gcc-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk "-L/Users/daiau/Desktop/CIP Mac Client/cURL_Test/build/Debug" "-L/Users/daiau/Desktop/CIP Mac Client/cURL_Test" "-F/Users/daiau/Desktop/CIP Mac Client/cURL_Test/build/Debug" -filelist "/Users/daiau/Desktop/CIP Mac Client/cURL_Test/build/cURL_Test.build/Debug/cURL_Test.build/Objects-normal/i386/cURL_Test.LinkFileList" -mmacosx-version-min=10.5 /Users/daiau/Documents/build/lib/libcurl.a -lssl -lcrypto -lldap -lz -o "/Users/daiau/Desktop/CIP Mac Client/cURL_Test/build/Debug/cURL_Test"

Use “otool -L” to validate the dependency libraries:

austin-dais-macbook:bin daiau$ otool -L /Users/daiau/Desktop/CIP\ Mac\ Client/cURL_Test/build/Debug/cURL_Test
/Users/daiau/Desktop/CIP Mac Client/cURL_Test/build/Debug/cURL_Test:
    /usr/lib/libssl.0.9.7.dylib (compatibility version 0.9.7, current version 0.9.7)
    /usr/lib/libcrypto.0.9.7.dylib (compatibility version 0.9.7, current version 0.9.7)
    /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP (compatibility version 1.0.0, current version 2.2.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)

Austin.D

Talking about [健康] 保护脊柱每天只需8分钟 [转载]

 

Quote

[健康] 保护脊柱每天只需8分钟 [转载]

现在不论男女老少,几乎人人都念叨着腰酸背痛,脊柱不好。脊柱的保健工作真的很难做吗?专家告诉我们,其实,只要每天花上8分钟,就能让我们的脊柱挺起来。
  卫生部北京医院康复医学科主任顾新为大家推荐了以下简单易学的脊柱保健操:
第一节:隔墙看戏
  首先踮起脚尖,立起脚后跟,躯干拉直,脖子伸长,下巴往上抬。这节操最大的特点就是用自己的肌肉把自己的后背整个的肌肉拉直,相当于把脊柱拉直,做自我牵引。每天只需做三分钟。

第二节:十点十分操
  当两只手侧平举的时候,在表针上叫9∶15,这个时候各向上5个刻度,就变成了十点十分。每当手臂上来下去时,可摸一下自己颈部的肌肉,随着这个过程,支撑脖子的肌肉能得到有效的锻炼。注意手一定放在自己的两侧,往后张开。每天做1分钟。

第三节:头手对抗
  两只手交叉着放在自己的枕后部,然后保持双眼平视前方,你的颈椎是自然正常的位置,你的手向前用力,头向后用力,这样用力、放松,一方面提高颈后肌肉的力量,一方面能促进颈后的血液循环,对颈椎是非常好的保健动作。可以缓解肌肉的疲劳,特别肌肉在做运动的时候,局部的血液循环量在加大,血液循环量加大以后,局部的营养都会得到改善,这样可以远离一些肌肉的损伤,保证疲劳以后产生的酸性物质,通过加大循环以后都会消除。特别是伏案工作的人,可每天做上两分钟。

第四节:旱地划船
  首先双脚叉开,两手前伸,挺胸塌腰向前。这个时候假设两手握住船桨,两手向后划。这个动作看似简单,但真正的技术要领,是在两手划来的时候,后背肌肉要使劲,向前伸时候放松,向后划时候用力,这节操可每天做1分钟,能有效解除后背疼痛。

第五节:大飞雁
  首先向前迈出半步,重心开始移到前边这条腿上,两手侧平举,这是一个简单的动作,复杂的动作就是两个手向后飞起来,抬头看房顶,这个时候大家可以看到,整个的脊柱都参与运动了。这个动作左边做三十秒,右边也做三十秒,交替做,这个动作对后背有问题的人,有很好的缓解作用。

  除了这五节操,顾主任还建议中老年及病人可以做这样一个动作,即将左手轻轻地搭在座位上,起一个保护作用,抬你的右侧上肢,右侧下肢,昂头,上肢和下肢都往后使劲,这样用力、放松,反复做,比较安全简单,也同样有很好的作用。
  此外,做操时还有不少需要注意的细节。顾主任说,老年人最好别做诸如划圈等环绕动作,以免做了会出现头晕等不适症状。
  在做这些动作的过程中,如果出现了疼痛,或者原先的症状越来越厉害,则应马上停止做操,去医院就医。