<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ja.Code</title>
    <description>My blog</description>
    <link>https://jacobpan3g.github.io/</link>
    <atom:link href="https://jacobpan3g.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Fri, 01 Sep 2017 09:00:38 +0000</pubDate>
    <lastBuildDate>Fri, 01 Sep 2017 09:00:38 +0000</lastBuildDate>
    <generator>Jekyll v3.5.2</generator>
    
      <item>
        <title>Build dylib on Mac os x</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#write-a-dylib&quot; id=&quot;markdown-toc-write-a-dylib&quot;&gt;Write a dylib&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#otool&quot; id=&quot;markdown-toc-otool&quot;&gt;otool&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#show-all-dylib&quot; id=&quot;markdown-toc-show-all-dylib&quot;&gt;show all dylib&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#show-the-id-of-dylib&quot; id=&quot;markdown-toc-show-the-id-of-dylib&quot;&gt;show the id of dylib&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#change-the-id-of-dylib&quot; id=&quot;markdown-toc-change-the-id-of-dylib&quot;&gt;change the id of dylib&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#change-the-path-where-executable-find-the-dylib&quot; id=&quot;markdown-toc-change-the-path-where-executable-find-the-dylib&quot;&gt;Change the path where executable find the dylib&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#libnet-compling-from-source&quot; id=&quot;markdown-toc-libnet-compling-from-source&quot;&gt;libnet Compling from source&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1-find-the-top-source-direction-with-configure&quot; id=&quot;markdown-toc-1-find-the-top-source-direction-with-configure&quot;&gt;1. Find the top source direction with &lt;code class=&quot;highlighter-rouge&quot;&gt;.configure&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2-check-if-makefile-here&quot; id=&quot;markdown-toc-2-check-if-makefile-here&quot;&gt;2. check if &lt;code class=&quot;highlighter-rouge&quot;&gt;Makefile&lt;/code&gt; here&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#3-done&quot; id=&quot;markdown-toc-3-done&quot;&gt;3. Done!&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;write-a-dylib&quot;&gt;Write a dylib&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gcc -dynamiclib foo.c -o libfoo.dylib
gcc main.c -L. -lfoo -o main
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

To specify a &lt;code class=&quot;highlighter-rouge&quot;&gt;install_name&lt;/code&gt; of a dylib, use &lt;code class=&quot;highlighter-rouge&quot;&gt;-install_name&lt;/code&gt; in &lt;code class=&quot;highlighter-rouge&quot;&gt;gcc&lt;/code&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gcc -dynamiclib foo.c -install_name  -o libfoo.dylib

&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

The &lt;code class=&quot;highlighter-rouge&quot;&gt;install_name&lt;/code&gt; of dylib will be write in &lt;code class=&quot;highlighter-rouge&quot;&gt;main&lt;/code&gt;

&lt;h2 id=&quot;otool&quot;&gt;otool&lt;/h2&gt;

&lt;h3 id=&quot;show-all-dylib&quot;&gt;show all dylib&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;otool -L &amp;lt;executable&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

Check all the dylib linked in &lt;code class=&quot;highlighter-rouge&quot;&gt;main&lt;/code&gt;, where the
&lt;code class=&quot;highlighter-rouge&quot;&gt;install_name&lt;/code&gt; of a dylib is the path where &lt;code class=&quot;highlighter-rouge&quot;&gt;main&lt;/code&gt; links the dylib.

example:
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;otool -L main
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;show-the-id-of-dylib&quot;&gt;show the id of dylib&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;otool -D &amp;lt;dylib&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

Check the &lt;code class=&quot;highlighter-rouge&quot;&gt;install_name&lt;/code&gt; of a dylib

example:
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;otool -D libfoo.dylib
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;change-the-id-of-dylib&quot;&gt;change the id of dylib&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;install_name_tool -id &amp;lt;new name&amp;gt; &amp;lt;dylib&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

Change the &lt;code class=&quot;highlighter-rouge&quot;&gt;install_name_tool&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;libfoo.dylib&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;../libfoo.dylib&lt;/code&gt;

example:
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;install_name_tool -id ../libfoo.dylib libfoo.dylib 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;change-the-path-where-executable-find-the-dylib&quot;&gt;Change the path where executable find the dylib&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;install_name_tool -change &amp;lt;old value&amp;gt; &amp;lt;new value&amp;gt; &amp;lt;executable&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

example:
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;install_name_tool -change ../libfoo.dylib ../../libfoo.dylib main
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

NOTE: One more method, if &lt;code class=&quot;highlighter-rouge&quot;&gt;install_name&lt;/code&gt; of a dylib is not corret, setting
      the environment variable &lt;code class=&quot;highlighter-rouge&quot;&gt;$DYLD_LIBRARY_PATH&lt;/code&gt; to the path where the
      dylib is can let executable find the dylib successfully. More info can
      see &lt;code class=&quot;highlighter-rouge&quot;&gt;man dyld&lt;/code&gt;.

&lt;blockquote&gt;
  More info see &lt;code class=&quot;highlighter-rouge&quot;&gt;mac/dylib&lt;/code&gt;.
&lt;/blockquote&gt;

&lt;h2 id=&quot;libnet-compling-from-source&quot;&gt;libnet Compling from source&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;brew install automake libtool doxygen libdnet
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

Use build process from the source of &lt;code class=&quot;highlighter-rouge&quot;&gt;libnet&lt;/code&gt; for instance.

&lt;h3 id=&quot;1-find-the-top-source-direction-with-configure&quot;&gt;1. Find the top source direction with &lt;code class=&quot;highlighter-rouge&quot;&gt;.configure&lt;/code&gt;&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./configure --prefix=&amp;lt;where you want to install&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;2-check-if-makefile-here&quot;&gt;2. check if &lt;code class=&quot;highlighter-rouge&quot;&gt;Makefile&lt;/code&gt; here&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;make
make install
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;3-done&quot;&gt;3. Done!&lt;/h3&gt;

Generally the the &lt;code class=&quot;highlighter-rouge&quot;&gt;install_name&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;libnet.dylib&lt;/code&gt; will be set properly.

Use the method above &lt;code class=&quot;highlighter-rouge&quot;&gt;configure, make, make install&lt;/code&gt; with 
&lt;code class=&quot;highlighter-rouge&quot;&gt;libnet-1.2-rc3.tar.gz&lt;/code&gt; (recommand)

Or use the method show in &lt;code class=&quot;highlighter-rouge&quot;&gt;BUILD-FROM-GIT.txt&lt;/code&gt;

&lt;hr /&gt;
&lt;blockquote&gt;
  Jacob Pan &lt;a href=&quot;http://jacobpan3g.github.io&quot;&gt;( jacobpan3g.github.io/ )&lt;/a&gt;
&lt;/blockquote&gt;
</description>
        <pubDate>Fri, 01 Sep 2017 08:35:01 +0000</pubDate>
        <link>https://jacobpan3g.github.io/2017/09/01/build-dylib-on-mac/</link>
        <guid isPermaLink="true">https://jacobpan3g.github.io/2017/09/01/build-dylib-on-mac/</guid>
        
        <category>dylib</category>
        
        
        <category>mac</category>
        
      </item>
    
      <item>
        <title>Covert Files' Encode From GBK to UTF-8 in One Time</title>
        <description>
To convert file encode from GBK to UTF-8

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find &amp;lt;dir&amp;gt; -type d -exec mkdir -p &amp;lt;utf dir&amp;gt;/{} \;
find &amp;lt;dir&amp;gt; -type f -exec bash -c &quot;iconv -f GBK -t UTF-8 {} &amp;gt; &amp;lt;utf dir&amp;gt;/{}&quot; \;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

Above, &lt;code class=&quot;highlighter-rouge&quot;&gt;iconv -f GBK -t UTF-8 &amp;lt;file&amp;gt; &amp;gt; &amp;lt;out file&amp;gt;&lt;/code&gt; can convert encode. In Linux, option &lt;code class=&quot;highlighter-rouge&quot;&gt;-o &amp;lt;out file&amp;gt;&lt;/code&gt; can instead by &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt;.

&lt;code class=&quot;highlighter-rouge&quot;&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;&lt;/code&gt; in the &lt;code class=&quot;highlighter-rouge&quot;&gt;find -exec&lt;/code&gt; command represents each line of the output of &lt;code class=&quot;highlighter-rouge&quot;&gt;find&lt;/code&gt;.

&lt;hr /&gt;
&lt;blockquote&gt;
  Jacob Pan &lt;a href=&quot;http://jacobpan3g.github.io&quot;&gt;( jacobpan3g.github.io )&lt;/a&gt;
&lt;/blockquote&gt;

</description>
        <pubDate>Fri, 01 Sep 2017 07:25:01 +0000</pubDate>
        <link>https://jacobpan3g.github.io/2017/09/01/convert-muti-files-from-gbk-to-utf8-in-a-time/</link>
        <guid isPermaLink="true">https://jacobpan3g.github.io/2017/09/01/convert-muti-files-from-gbk-to-utf8-in-a-time/</guid>
        
        <category>shell</category>
        
        
        <category>cmd</category>
        
      </item>
    
      <item>
        <title>Change System Default Xcode in Mac</title>
        <description>
Show the default xcode in mac os x:
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ xcode-select -p
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

Change system default xcode
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# xcode-select -switch /Applications/Xcode.app
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

If there are more than one xcode installed in mac os x, the second one will be named “xcode 2”. Sometimes, it’ll raise some errors because the “ “(space) in the name.

For instance, to build libnet, I followed the &lt;code class=&quot;highlighter-rouge&quot;&gt;BUILD-FROM-GIT.txt&lt;/code&gt; at the top of project. Because my default xcode is named “xcode 2”, it throw an error as
&lt;code class=&quot;highlighter-rouge&quot;&gt;/bin/sh: /Applications/Xcode: No such file or directory&lt;/code&gt;. After I switched to “xcode” using the cmd above, the build process success.

&lt;hr /&gt;
&lt;blockquote&gt;
  Jacob Pan &lt;a href=&quot;http://jacobpan3g.github.io&quot;&gt;( jacobpan3g.github.io/ )&lt;/a&gt;
&lt;/blockquote&gt;
</description>
        <pubDate>Fri, 01 Sep 2017 07:13:01 +0000</pubDate>
        <link>https://jacobpan3g.github.io/2017/09/01/change-default-xcode/</link>
        <guid isPermaLink="true">https://jacobpan3g.github.io/2017/09/01/change-default-xcode/</guid>
        
        <category>xcode</category>
        
        
        <category>mac</category>
        
      </item>
    
  </channel>
</rss>
