﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Clear</title><link>http://www.cppblog.com/newclear/</link><description>记忆中的闪光，总会蒙尘。</description><language>zh-cn</language><lastBuildDate>Mon, 13 Apr 2026 09:38:06 GMT</lastBuildDate><pubDate>Mon, 13 Apr 2026 09:38:06 GMT</pubDate><ttl>60</ttl><item><title>让Premake4支持protobuf的protoc生成源文件</title><link>http://www.cppblog.com/newclear/archive/2012/11/15/195245.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Thu, 15 Nov 2012 14:44:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2012/11/15/195245.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/195245.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2012/11/15/195245.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/195245.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/195245.html</trackback:ping><description><![CDATA[<p>最近在使用Premake4进行项目配置生成makefile之类。</p>
<p>比较而言，Premake4比cmake还是感觉简单一点，至少lua语法简单，premake4的配置文件比较简单易读，而cmake的配置文件就比较复杂，而且又是自己定义的一套东西，用起来实在比较烦。</p>
<p>Premake4还有一个比较好用的特性，可以直接用 **/*.cpp 指定项目包含所有目录下的cpp文件，而不用单个指定。这样每次增加一个文件不用老等编译了才想起来忘记了增加文件到配置中。算是给懒人的一个福利吧。</p>
<p>当然，Premake4也有自己的缺陷，目前还不支持自定义规则，所以如果项目中有用到什么自动生成源文件的特性就比较麻烦了，比如这次说到的protobuf要用protoc编译.proto文件生成.pb.cc和.pb.h文件，另外QT也有类似的需求，就我之前某项目中，也使用了tolua++生成过c++的lua接口文件。</p>
<p>但是，Premake4虽然还不支持自定义规则，但是总算有一个prebuildcommands可以用，于是研究了一下，自制了一个.proto文件的"编译规则":</p>
<pre>function protobufs(pat)<br />  local list = {}<br />  if type(pat) == "string" then<br />    list[1] = pat;<br />  elseif type(pat) == "table" then<br />    list = pat;<br />  end<br />  local proj = project();<br />  for _,pat in ipairs(list) do<br />    local protofiles = os.matchfiles(pat);<br />    for _,protofile in ipairs(protofiles) do<br />      local basename = path.getbasename(protofile);<br />      local sourcedir = proj.basedir.."/"..path.getdirectory(protofile);<br />      local sourcefile = proj.basedir.."/"..protofile;<br />      local targetdir = "$(OBJDIR)/proto/"..path.getdirectory(protofile);<br />      local targetfile = targetdir.."/"..basename..".pb.cc";<br />      prebuildcommands {<br />        "@mkdir -p "..targetdir,<br />        "@test "..sourcefile.." \\\n"<br />        .."\t\t\t -ot "..targetfile.." || \\\n"<br />        .."\t\t( echo protoc "..protofile.." &amp;&amp; \\\n"<br />        .."\t\tprotoc --cpp_out "..targetdir.."\\\n"<br />        .."\t\t\t"..sourcefile.."\\\n"<br />        .."\t\t\t".." -I"..sourcedir.." ) \\\n"<br />      }<br />      files {<br />        path.join(targetdir, basename..".pb.h"),<br />        path.join(targetdir, basename..".pb.cc"),<br />      }<br />      includedirs { targetdir }<br />    end<br />  end<br />end</pre>
<p>使用方法呢，就是把上面的代码保存到protobuf.lua里面，然后在premake4.lua最开始的时候，调用</p>
<pre>dofile "protobuf.lua"</pre>
<p>然后在项目定义的时候，使用</p>
<pre>protobufs { "**/*.proto" }</pre>
<p>就可以了。</p>
<p> </p>
<p>当然，还有一点要注意的，我的系统是mac，但脚本在linux下应该也能同样运行，但是windows下面的话，可能就需要做一点改动了。</p><img src ="http://www.cppblog.com/newclear/aggbug/195245.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2012-11-15 22:44 <a href="http://www.cppblog.com/newclear/archive/2012/11/15/195245.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MacVim中Pyclewn的配置</title><link>http://www.cppblog.com/newclear/archive/2012/11/11/195038.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Sun, 11 Nov 2012 09:38:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2012/11/11/195038.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/195038.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2012/11/11/195038.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/195038.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/195038.html</trackback:ping><description><![CDATA[<p>换到Mac下面，MacVim自然装上了。</p>
<p>要想调试程序，直接gdb倒也可以，不过就是找代码很费力，这就要看Pyclewn了。</p>
<p>下载，安装，一切似乎都正常。</p>
<p>可是启动pyclewn以后，发现gdb的命令没有输出到buffer？怎么搞？</p>
<p>原来pyclewn用的还是系统自带的gdb，晕，版本好老了。</p>
<p>在.vimrc里面加上</p>
<pre>set pyclewn_args='-p ggdb'</pre>
<p>指定使用macports的gdb，这就行了。</p>
<p>ps.</p>
<p>MacVim 的snapshot 64版本的balloon显示不出来，不知道怎么回事。</p>
<p>升级到snapshot 65就ok了。</p><img src ="http://www.cppblog.com/newclear/aggbug/195038.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2012-11-11 17:38 <a href="http://www.cppblog.com/newclear/archive/2012/11/11/195038.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GDB在Mac下的调试信息</title><link>http://www.cppblog.com/newclear/archive/2012/10/28/193994.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Sun, 28 Oct 2012 15:47:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2012/10/28/193994.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/193994.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2012/10/28/193994.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/193994.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/193994.html</trackback:ping><description><![CDATA[<p>上次说了GDB的pretty printer，这次来说说调试程序的问题。<br /><br />在Linux或者Windows下面，写好代码，g++编译，连接，调试，一切很顺畅。<br /><br />但是在Mac下面，有点小问题。<br /><br />我们如果是直接编译生成可执行文件：</p>
<pre>g++ test.cpp -g -o test</pre>
<p>ok，我们用GDB调试，没有问题。<br />但是如果我们分两步，编译和连接分开的话：</p>
<pre>g++ test.cpp -g -c -o test.o<br />g++ -o test test.o</pre>
<p>这次我们gdb test再调试，会发现GDB找不到调试符号信息！<br /><br />两次生成有什么不同呢？<br />一次编译生成的test，旁边有一个test.dSYM，而单独连接的test，没有这个。<br /><br />test.dSYM就是调试符号信息。<br />要想生成这个东西，也简单，运行dsymutil就可以了： </p>
<pre>dsymutil test</pre>
<p>再然后，就可以用GDB顺利调试了。<br /><br />g++直接生成可执行文件的时候，会帮我们调用一次dsymutil，但是单独连接的时候却不会做这个，这就是造成差别的原因。</p><img src ="http://www.cppblog.com/newclear/aggbug/193994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2012-10-28 23:47 <a href="http://www.cppblog.com/newclear/archive/2012/10/28/193994.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mac 下使用GDB的pretty printer</title><link>http://www.cppblog.com/newclear/archive/2012/09/24/191889.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Mon, 24 Sep 2012 15:15:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2012/09/24/191889.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/191889.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2012/09/24/191889.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/191889.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/191889.html</trackback:ping><description><![CDATA[<p>GDB 从7.x版本开始就支持pretty printer</p>
<p>可是一直以来都没有见到这个东西起作用，最近就研究了一下。</p>
<p>我的环境是Mac Mountain Lion + macports，GCC 4.7，GDB 7.5</p>
<p>首先，按照</p>
<p><a href="http://sourceware.org/gdb/wiki/STLSupport">http://sourceware.org/gdb/wiki/STLSupport</a><br /></p>
<p>下载checkout STL的pretty printer。</p>
<p>设置好.gdbinit以后，运行告知已经注册，不能重复注册。</p>
<p>$locate printers.py</p>
<p>发现在/opt/local/share/gcc-4.7/gcc-4.7.1/python/libstdcxx/v6已经有一份现成的了。</p>
<p>好吧，我们就使用现有的好了。</p>
<p>写个程序，调试，print，怎么回事？还是不成？</p>
<p>头晕了好久，好在python的源码是可以随便看随便改的，于是在printers.py里面改来改去，调试了半天，发现：</p>
<p>这个printers.py注册了好多stl类型的printer，打印出来有以下这些：</p>
<p>std::__cxx1998::__7::unordered_multiset<br /></p>
<p>std::tr1::unordered_multiset</p>
<p>std::unordered_set</p>
<p>std::tr1::unordered_multimap</p>
<p>std::tr1::__7::weak_ptr</p>
<p>std::__7::bitset</p>
<p>std::__cxx1998::multiset</p>
<p>std::bitset</p>
<p>std::forward_list</p>
<p>std::__7::forward_list</p>
<p>std::__cxx1998::forward_list</p>
<p>std::__7::_Rb_tree_iterator</p>
<p>std::__7::list</p>
<p>std::__debug::unordered_multimap</p>
<p>__gnu_cxx::slist</p>
<p>std::__7::priority_queue</p>
<p>std::__debug::map</p>
<p>std::_List_const_iterator</p>
<p>std::__debug::unordered_map</p>
<p>__gnu_cxx::_Slist_iterator</p>
<p>std::set</p>
<p>std::__cxx1998::__7::_Deque_const_iterator</p>
<p>std::__7::_List_const_iterator</p>
<p>std::__7::multiset</p>
<p>std::shared_ptr</p>
<p>std::__7::queue</p>
<p>std::__cxx1998::_List_iterator</p>
<p>std::tr1::unordered_map</p>
<p>std::__7::vector</p>
<p>std::__debug::queue</p>
<p>std::__norm::_Deque_const_iterator</p>
<p>std::__7::unordered_set</p>
<p>std::__norm::_Deque_iterator</p>
<p>std::__cxx1998::_Deque_iterator</p>
<p>__gnu_cxx::__7::_Slist_iterator</p>
<p>std::__cxx1998::list</p>
<p>std::__cxx1998::__7::list</p>
<p>std::unordered_multimap</p>
<p>std::__cxx1998::unordered_multiset</p>
<p>std::__cxx1998::__7::_List_iterator</p>
<p>std::__7::map</p>
<p>std::__debug::vector</p>
<p>std::tr1::__7::unordered_set</p>
<p>std::__7::basic_string</p>
<p>std::weak_ptr</p>
<p>std::__7::set</p>
<p>std::__7::unordered_multiset</p>
<p>__gnu_cxx::__7::__normal_iterator</p>
<p>std::__cxx1998::__7::vector</p>
<p>std::unordered_map</p>
<p>std::list</p>
<p>std::tr1::__7::unordered_map</p>
<p>std::__7::unordered_multimap</p>
<p>std::vector</p>
<p>std::tr1::unordered_set</p>
<p>std::_List_iterator</p>
<p>std::__7::_Deque_iterator</p>
<p>std::__cxx1998::map</p>
<p>std::__cxx1998::bitset</p>
<p>std::__7::weak_ptr</p>
<p>std::__cxx1998::vector</p>
<p>std::__cxx1998::unordered_set</p>
<p>std::priority_queue</p>
<p>__gnu_cxx::__7::slist</p>
<p>std::__7::_Rb_tree_const_iterator</p>
<p>std::_Deque_const_iterator</p>
<p>std::__7::deque</p>
<p>std::__cxx1998::set</p>
<p>std::__cxx1998::__7::bitset</p>
<p>__gnu_debug::_Safe_iterator</p>
<p>std::tr1::__7::unordered_multimap</p>
<p>__gnu_cxx::__normal_iterator</p>
<p>std::__cxx1998::__7::multiset</p>
<p>std::__cxx1998::__7::unordered_map</p>
<p>std::__debug::unique_ptr</p>
<p>std::__cxx1998::_List_const_iterator</p>
<p>std::_Deque_iterator</p>
<p>std::tr1::__7::unordered_multiset</p>
<p>std::unordered_multiset</p>
<p>std::__cxx1998::__7::unordered_multimap</p>
<p>std::__debug::multiset</p>
<p>std::tr1::weak_ptr</p>
<p>std::__cxx1998::_Deque_const_iterator</p>
<p>std::__cxx1998::unordered_map</p>
<p>std::__7::unique_ptr</p>
<p>std::__debug::list</p>
<p>std::__debug::unordered_multiset</p>
<p>std::__cxx1998::deque</p>
<p>std::_Rb_tree_const_iterator</p>
<p>std::__debug::bitset</p>
<p>std::queue</p>
<p>std::tr1::__7::shared_ptr</p>
<p>std::__debug::unordered_set</p>
<p>std::tr1::shared_ptr</p>
<p>std::__cxx1998::__7::_List_const_iterator</p>
<p>std::__cxx1998::__7::_Deque_iterator</p>
<p>std::__cxx1998::__7::map</p>
<p>std::__7::stack</p>
<p>std::unique_ptr</p>
<p>std::__cxx1998::__7::deque</p>
<p>std::map</p>
<p>std::__7::multimap</p>
<p>std::stack</p>
<p>std::__debug::stack</p>
<p>std::_Rb_tree_iterator</p>
<p>std::multimap</p>
<p>std::__norm::_List_const_iterator</p>
<p>std::__debug::multimap</p>
<p>std::__norm::_List_iterator</p>
<p>std::deque</p>
<p>std::tuple</p>
<p>std::__cxx1998::unordered_multimap</p>
<p>std::basic_string</p>
<p>std::__7::tuple</p>
<p>std::__debug::deque</p>
<p>std::__debug::priority_queue</p>
<p>std::__7::_Deque_const_iterator</p>
<p>std::__7::shared_ptr</p>
<p>std::__cxx1998::__7::multimap</p>
<p>std::__debug::forward_list</p>
<p>std::__7::unordered_map</p>
<p>std::__debug::set</p>
<p>std::__cxx1998::__7::unordered_set</p>
<p>std::__cxx1998::__7::set</p>
<p>std::__7::_List_iterator</p>
<p>std::__cxx1998::multimap</p>
<p>std::__cxx1998::__7::forward_list</p>
<p>std::multiset:</p>
<p>然后，我们的一个简单的string类型，传入到python的lookup里面查找，找不到？</p>
<p>最后发现，string类型传入python以后的basename是basic_string，没有前面的namespace！</p>
<p>于是，在Printer类的add_version函数里面，增加一行</p>
<p>self.add(name, function)<br /></p>
<p>保存，重新打开GDB，调试程序，OK了：</p>
<p>(gdb) p s</p>
<p>$1 = "great"</p>
<p>(gdb) p v</p>
<p>$2 = vector of length 5, capacity 8 = {"a1", "a2", "a2", "a3", "a4"}</p>

<div class="posttagsblock"><a href="http://technorati.com/tag/Mac" rel="tag">Mac</a>, <a href="http://technorati.com/tag/GDB" rel="tag">GDB</a></div><img src ="http://www.cppblog.com/newclear/aggbug/191889.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2012-09-24 23:15 <a href="http://www.cppblog.com/newclear/archive/2012/09/24/191889.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CoLinux的网络配置</title><link>http://www.cppblog.com/newclear/archive/2009/09/27/97405.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Sun, 27 Sep 2009 14:29:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2009/09/27/97405.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/97405.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2009/09/27/97405.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/97405.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/97405.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 昨天的说到配置CoLinux在Windows下面启动另一个分区里面的Linux，但是网络配置只是使用了最简单的slirp模式。<br><br>CoLinux的网络配置共有3种：<br><br>slirp：最简单的模式，CoLinux内可通过Windows系统访问网络，但外部不能直接访问Linux，如果需要访问，需要做端口映射。 <br>tuntap：在Windows中虚拟一块网卡，Linux与Windows通过该网卡通讯，Linux不能直接访问外部网络，必须在Windows上配置路由和NAT，或者简单使用Windows的Internet连接共享ICS。 <br>pcap-bridge：必须有一块连接网络的网卡才能使用，另外需要安装WinPCap软件。该模式将一块实际网卡模拟出另一块网卡并连接到网络，对外部看来，就好像实际上有两台不同机器一样。 <br>ndis-bridge：与pcap-bridge模式一样，不过不使用WinPCap软件接口而是通过Windows的NDIS接口层模拟网卡。&nbsp;&nbsp;<a href='http://www.cppblog.com/newclear/archive/2009/09/27/97405.html'>阅读全文</a><img src ="http://www.cppblog.com/newclear/aggbug/97405.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2009-09-27 22:29 <a href="http://www.cppblog.com/newclear/archive/2009/09/27/97405.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Windows和Linux双启动，并用在Windows下配置CoLinux启动</title><link>http://www.cppblog.com/newclear/archive/2009/09/27/97327.html</link><dc:creator>Clear</dc:creator><author>Clear</author><pubDate>Sat, 26 Sep 2009 17:11:00 GMT</pubDate><guid>http://www.cppblog.com/newclear/archive/2009/09/27/97327.html</guid><wfw:comment>http://www.cppblog.com/newclear/comments/97327.html</wfw:comment><comments>http://www.cppblog.com/newclear/archive/2009/09/27/97327.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/newclear/comments/commentRss/97327.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/newclear/services/trackbacks/97327.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Windows和Linux都是好东西，配置双启动不难，但是有时候在Windows下面想要临时换到Linux，总是麻烦。<br><br>以前都是用VmWare，配置使用实际硬盘，然后再Windows里面进行启动另一个分区里面的Linux然后操作。<br><br>不过这样实在是麻烦，而且VmWare占用资源也是在太大，如果配置512内存，就要在系统里面直接占用掉512M内存，即使实际上Linux根本不用那么多。<br><br>不过，前段时间发现了CoLinux这个好东西，可以把Linux内核作为Windows的本地进程运行，不错不错。<br>&nbsp;&nbsp;<a href='http://www.cppblog.com/newclear/archive/2009/09/27/97327.html'>阅读全文</a><img src ="http://www.cppblog.com/newclear/aggbug/97327.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/newclear/" target="_blank">Clear</a> 2009-09-27 01:11 <a href="http://www.cppblog.com/newclear/archive/2009/09/27/97327.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>