﻿<?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++博客-Error-随笔分类-linux</title><link>http://www.cppblog.com/Error/category/21141.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 10 Mar 2017 20:05:11 GMT</lastBuildDate><pubDate>Fri, 10 Mar 2017 20:05:11 GMT</pubDate><ttl>60</ttl><item><title>ubuntu-16.4 php5 phpmyadmin wordpress</title><link>http://www.cppblog.com/Error/archive/2017/03/10/214745.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Fri, 10 Mar 2017 06:13:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2017/03/10/214745.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/214745.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2017/03/10/214745.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/214745.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/214745.html</trackback:ping><description><![CDATA[<div>apt-get install mysql-server</div><div>apt-get install apache2</div><div>apt-get install php5</div><div>apt-get install php5-mysql</div><div>apt-get install php5-gd</div><div>apt-search php5</div><div>apt-get install libapache2-mod-php5.6</div><div>apt-get install libapache2-mod-auth-mysql</div><div>apt-get install openjdk</div><div></div><div>sudo apt-get purge openjdk/openjdk</div><div></div><div>apt-get install python-software-properties</div><div>apt-get install software-properties-common</div><div>apt-get install -y language-pack-en-base</div><div>LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php</div><div>add-apt-repository ppa:ondrej/php</div><div>apt-get update</div><div>apt-cache search php5</div><div>apt-get install php5.5-common</div><div></div><div>apt-get install libapache2-mod-php5.5</div><div></div><div>apt-get install php5.6</div><div>apt-get install php5.6-mysql</div><div>apt-get install php5.6-gd</div><div>apt-get install php7.1-mcrypt</div><div>apt-get install php-mbstring</div><div>apt-get install php7.1-mbstring</div><div></div><div>lsof -i:80 &nbsp; 权限查询</div><div>/etc/init.d/apache2 restart</div><div>netstat -tupln</div><div>/etc/apache2/ports.conf</div><div>vi /etc/apache2/sites-enabled/000-default.conf &nbsp;修改默认站点的root路径</div><div>sudo apt-get install phpmyadmin</div><div>ln -s /usr/share/phpmyadmin</div><div>sudo apt-get install wordpress</div><div>ln -s /usr/share/wordpress</div><div>cp wp-config-sample.php wp-config.php</div><div>vi wp-config.php</div><div>mysql: create database WordPress</div><div></div><div></div><div>ls /usr/share</div><div>ls /var/www/</div><div></div><div>WordPress</div><div></div><img src ="http://www.cppblog.com/Error/aggbug/214745.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2017-03-10 14:13 <a href="http://www.cppblog.com/Error/archive/2017/03/10/214745.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用CMake GCC和Clang的/ LLVM之间切换（转）</title><link>http://www.cppblog.com/Error/archive/2015/08/20/211618.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Thu, 20 Aug 2015 03:52:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2015/08/20/211618.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/211618.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2015/08/20/211618.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/211618.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/211618.html</trackback:ping><description><![CDATA[<h1>使用CMake GCC和Clang的/ LLVM之间切换</h1><div bdshare-button-style0-16"="" data-bd-bind="1440042635441" style="zoom: 1; color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;"><a href="http://codego.net/340772/#" data-cmd="more" style="color: #333333; text-decoration: none; float: left; padding-left: 17px; line-height: 16px; height: 16px; cursor: pointer; margin: 6px 6px 6px 0px; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png); background-position: 0px 0px; background-repeat: no-repeat;"></a><a href="http://codego.net/340772/#" data-cmd="qzone" title="分享到QQ空间" style="color: #3e62a6; text-decoration: none; float: left; padding-left: 17px; line-height: 16px; height: 16px; cursor: pointer; margin: 6px 6px 6px 0px; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png); background-position: 0px -52px; background-repeat: no-repeat;"></a><a href="http://codego.net/340772/#" data-cmd="tsina" title="分享到新浪微博" style="color: #3e62a6; text-decoration: none; float: left; padding-left: 17px; line-height: 16px; height: 16px; cursor: pointer; margin: 6px 6px 6px 0px; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png); background-position: 0px -104px; background-repeat: no-repeat;"></a><a href="http://codego.net/340772/#" data-cmd="tqq" title="分享到腾讯微博" style="color: #3e62a6; text-decoration: none; float: left; padding-left: 17px; line-height: 16px; height: 16px; cursor: pointer; margin: 6px 6px 6px 0px; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png); background-position: 0px -260px; background-repeat: no-repeat;"></a><a href="http://codego.net/340772/#" data-cmd="renren" title="分享到人人网" style="color: #3e62a6; text-decoration: none; float: left; padding-left: 17px; line-height: 16px; height: 16px; cursor: pointer; margin: 6px 6px 6px 0px; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png); background-position: 0px -208px; background-repeat: no-repeat;"></a></div><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;"><a href="http://codego.net/717/1/58/" style="color: #3e62a6; text-decoration: none; line-height: 2; font-size: 8pt; margin: 2px 2px 2px 0px; padding: 2px 4px; white-space: nowrap; background-color: #d9ecff;">cmake</a>&nbsp;<a href="http://codego.net/1339/1/28/" style="color: #3e62a6; text-decoration: none; line-height: 2; font-size: 8pt; margin: 2px 2px 2px 0px; padding: 2px 4px; white-space: nowrap; background-color: #d9ecff;">llvm</a>&nbsp;<a href="http://codego.net/1226/1/33/" style="color: #3e62a6; text-decoration: none; line-height: 2; font-size: 8pt; margin: 2px 2px 2px 0px; padding: 2px 4px; white-space: nowrap; background-color: #d9ecff;">clang</a></span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">我公司拥有一批项目的CMake的，我希望能够方便地切换GCC或铛/ LLVM他们。我相信（请如果我错了！）表示锵我需要进行如下设置：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code> SET (CMAKE_C_COMPILER    "/usr/bin/clang")  SET (CMAKE_C_FLAGS    "-Wall -std=c99")  SET (CMAKE_C_FLAGS_DEBUG   "-g")  SET (CMAKE_C_FLAGS_MINSIZEREL  "-Os -DNDEBUG")  SET (CMAKE_C_FLAGS_RELEASE  "-O4 -DNDEBUG")  SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")  SET (CMAKE_CXX_COMPILER    "/usr/bin/clang++")  SET (CMAKE_CXX_FLAGS    "-Wall")  SET (CMAKE_CXX_FLAGS_DEBUG   "-g")  SET (CMAKE_CXX_FLAGS_MINSIZEREL  "-Os -DNDEBUG")  SET (CMAKE_CXX_FLAGS_RELEASE  "-O4 -DNDEBUG")  SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")  SET (CMAKE_AR  "/usr/bin/llvm-ar")  SET (CMAKE_LINKER "/usr/bin/llvm-ld")  SET (CMAKE_NM  "/usr/bin/llvm-nm")  SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")  SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib") </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">是否有这些和默认的GCC变量之间的切换，最好是全系统的变化，而不是具体的项目（即不只是将它们添加到项目的的CMakeLists.txt）一个简单的方法？ 另外，是否有必要的</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">llvm-*</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">节目铛的gcc时代替，而不是系统默认值？有什么区别？</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">本文地址 ：CodeGo.net/340772/&nbsp;</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><div id="BAIDU_DUP_wrapper_972677_0" style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;"><iframe id="cproIframe_972677_3" width="640" height="60" src="http://cb.baidu.com/ecom?adn=3&amp;at=38&amp;aurl=&amp;cad=1&amp;ccd=24&amp;cec=UTF-8&amp;cfv=18&amp;ch=0&amp;col=zh-CN&amp;conOP=0&amp;cpa=1&amp;dai=3&amp;dis=0&amp;ltr=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D-65vOIyEPEyN6wGVGEOvcqiNgIbj9PcX6iS3msA-T7lu9s4joaHjBn_LYCAapVos%26wd%3D%26eqid%3Dd613164b000165fe0000000355d54e88&amp;ltu=http%3A%2F%2Fcodego.net%2F340772%2F&amp;lunum=6&amp;n=binfenkeji2010_cpr&amp;pcs=1920x969&amp;pis=10000x10000&amp;ps=-1x-1&amp;psr=1920x1080&amp;pss=1920x0&amp;qn=79827666056fed76&amp;rad=&amp;rs=301&amp;rsi0=640&amp;rsi1=60&amp;rsi5=4&amp;rss0=%23FFFFFF&amp;rss1=%23FFFFFF&amp;rss2=%230000ff&amp;rss3=%23444444&amp;rss4=%23008000&amp;rss5=&amp;rss6=%23e10900&amp;rss7=&amp;scale=&amp;skin=&amp;td_id=9223372032564535439&amp;tn=text_default_640_60&amp;tpr=1440042634669&amp;ts=1&amp;version=2.0&amp;xuanting=0&amp;dtm=BAIDU_DUP2_SETJSONADSLOT&amp;dc=2&amp;di=972677&amp;ti=%E4%BD%BF%E7%94%A8CMake%20GCC%E5%92%8CClang%E7%9A%84%2F%20LLVM%E4%B9%8B%E9%97%B4%E5%88%87%E6%8D%A2-cmake%2Cllvm%2Cclang-CodeGo.net&amp;tt=1440042634652.18.-1440042634652.409" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true"></iframe></div><span style="color: #bbddff; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">-------------------------------------------------------------------------------------------------------------------------&nbsp;</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-size: 12px; font-style: italic; font-weight: bold; margin-right: 5px; color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 24px; background-color: #ffffff;">1.&nbsp;</span><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">CMake的荣誉的变量</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CC</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">和</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CXX</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">在检测到C和C ++编译器</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>$ export CC=/usr/bin/clang $ export CXX=/usr/bin/clang++ $ cmake .. -- The C compiler identification is Clang -- The CXX compiler identification is Clang </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">具体标志可以通过将它们放入一个系统范围的CMake文件并指向CMAKE_USER_MAKE_RULES_OVERRIDE变量，它被覆盖。创建一个文件</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">~/ClangOverrides.txt</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">其内容如下：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>SET (CMAKE_C_FLAGS_INIT    "-Wall -std=c99") SET (CMAKE_C_FLAGS_DEBUG_INIT   "-g") SET (CMAKE_C_FLAGS_MINSIZEREL_INIT  "-Os -DNDEBUG") SET (CMAKE_C_FLAGS_RELEASE_INIT  "-O4 -DNDEBUG") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g") SET (CMAKE_CXX_FLAGS_INIT    "-Wall") SET (CMAKE_CXX_FLAGS_DEBUG_INIT   "-g") SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT  "-Os -DNDEBUG") SET (CMAKE_CXX_FLAGS_RELEASE_INIT  "-O4 -DNDEBUG") SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g") </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">后缀_init会让CMake的初始化相应的</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">*_FLAGS</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">变量与给定的值。然后调用cmake的以下面的方式：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>$ cmake -DCMAKE_USER_MAKE_RULES_OVERRIDE=~/ClangOverrides.txt .. </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">终于到了LLVM的binutils力，设置内部变量</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">_CMAKE_TOOLCHAIN_PREFIX</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">。这个变量是由荣幸</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CMakeFindBinUtils</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">模块：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>$ cmake -D_CMAKE_TOOLCHAIN_PREFIX=llvm- .. </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">把这个放在一起你可以写一个shell包装它设置了变量</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CC</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">和</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CXX</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">然后调用cmake的可变覆盖。&nbsp;</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-size: 12px; font-style: italic; font-weight: bold; margin-right: 5px; color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 24px; background-color: #ffffff;">2.&nbsp;</span><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">全系统的C ++的变化对Ubuntu的： sudo用update-alternatives-配置C ++ 将打印是这样的：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code> Selection Path    Priority Status ------------------------------------------------------------ * 0   /usr/bin/g++  20  auto mode  1   /usr/bin/clang++ 10  manual mode  2   /usr/bin/g++  20  manual mode </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">然后，只需选择铛++。&nbsp;</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-size: 12px; font-style: italic; font-weight: bold; margin-right: 5px; color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 24px; background-color: #ffffff;">3.&nbsp;</span><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">你的</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>option(USE_CLANG "build application with clang" OFF) # OFF is the default </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">然后在包裹如果（）S中的设置：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>if(USE_CLANG)  SET (...)  .... endif(USE_CLANG) </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">这样，它会显示为在GUI配置工具的cmake的选项。 为了让您在整个系统可以在变量的默认值或保持与答案。&nbsp;</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-size: 12px; font-style: italic; font-weight: bold; margin-right: 5px; color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 24px; background-color: #ffffff;">4.&nbsp;</span><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">你绝对不需要不同的LLVM-AR等程序：</span><pre style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;"><code>SET (CMAKE_AR  "/usr/bin/llvm-ar") SET (CMAKE_LINKER "/usr/bin/llvm-ld") SET (CMAKE_NM  "/usr/bin/llvm-nm") SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump") SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib") </code></pre><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">这些都是为了工作，对LLVM内部格式，因此阿仁'到您的应用程序的生成。 作为一个说明 CodeGo.net，O4将在你的程序调用的LTO，你可能不希望（这样会大大）和铛默认为C99模式，使标志不是必需的两种。&nbsp;</span><br style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-size: 12px; font-style: italic; font-weight: bold; margin-right: 5px; color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 24px; background-color: #ffffff;">5.&nbsp;</span><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">你的语法：</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">$ENV{environment-variable}</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">在你的</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CMakeLists.txt</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">访问变量。你可以适当地创建一个初始化的变量集的脚本，只是在引用这些变量的</span><code style="color: #666666; font-size: 12px; line-height: 24px; background-color: #ffffff;">CMakeLists.txt</code><span style="color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">文件。</span><img src ="http://www.cppblog.com/Error/aggbug/211618.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2015-08-20 11:52 <a href="http://www.cppblog.com/Error/archive/2015/08/20/211618.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux so 加载 编译 路径 顺序 等（转+汇总）</title><link>http://www.cppblog.com/Error/archive/2015/08/18/211596.html</link><dc:creator>Enic</dc:creator><author>Enic</author><pubDate>Tue, 18 Aug 2015 09:42:00 GMT</pubDate><guid>http://www.cppblog.com/Error/archive/2015/08/18/211596.html</guid><wfw:comment>http://www.cppblog.com/Error/comments/211596.html</wfw:comment><comments>http://www.cppblog.com/Error/archive/2015/08/18/211596.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Error/comments/commentRss/211596.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Error/services/trackbacks/211596.html</trackback:ping><description><![CDATA[<h2><span style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; word-wrap: normal; word-break: normal; background-color: #ffffff;"><strong>运行时使用非标准位置/usr/lib和/lib下的库的方式有三种：</strong></span><br style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;" /><span style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;">(1) 设置$LD_LIBRARY_PATH=库所在目录（多个目录用:分隔），系统加载工具ld.so/ld-linux.so将顺序搜索变量指定的目录。例如#$LD_LIBRARY_PATH=/usr/local/mysql/lib ./test_mysql</span><br style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;" /><span style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;">(2) 以root身份把库路径加入/etc/ld.so.conf或在/etc/ld.so.conf.d中创建特定的.conf文件，然后运行ldconfig更新/etc/ld.so.cache。例如：在/etc/ld.so.conf.d下创建文件mysql.conf写入/usr/local/mysql/lib</span><br style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;" /><span style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;">(3) 另一种办法就是把需要的库copy到/usr/lib或/lib，但这不是建议的方法，特别是尽量避免copy发到/lib。但这种方法可以在编译时免去用-L选项。<br /><br /><br /><br /></span></h2><h2 id="t_5ac88b350100bdd8" class="titName SG_txta" style="margin: 0px; padding: 0px; border: 0px; list-style: none; color: #464646; font-size: 18px; font-family: 微软雅黑, 黑体; font-weight: 300; display: inline;">linux中动态链接库的搜索顺序</h2><h2><div class="articalTitle" style="clear: both; line-height: 20px; padding-bottom: 10px; color: #464646; font-family: Verdana, 宋体, sans-serif; font-size: 12px; font-weight: normal; background-color: #f8ecd8;">&nbsp;<span class="time SG_txtc" style="color: #909090; white-space: nowrap; font-family: Arial; font-size: 10px; margin-left: 5px; margin-right: 13px;">(2008-12-23 10:03:20)</span><div class="turnBoxzz" style="float: right;"><a class="SG_aBtn SG_aBtn_ico SG_turn" action-type="reblog" action-data="{srcBlog:1, blogId:'5ac88b350100bdd8'}" style="cursor: pointer; padding: 0px 0px 0px 3px; overflow: hidden; white-space: nowrap; display: inline-block; margin-right: 6px; position: relative; letter-spacing: 5px; width: 86px; zoom: 1; background-image: url(http://simg.sinajs.cn/blog7newtpl/image/1/1_2/images/sg_newsp.png); background-position: 0px 0px; background-repeat: no-repeat;"><cite style="font-style: normal; line-height: 23px; padding: 0px 20px 0px 32px; height: 23px; min-width: 1px; overflow-x: visible; width: 34px; display: inline-block !important; background-image: url(http://simg.sinajs.cn/blog7newtpl/image/1/1_2/images/sg_newsp.png); background-position: 100% -28px; background-repeat: no-repeat;"><img class="SG_icon SG_icon111" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="15" height="15" align="absmiddle" style="margin: 0px; padding: 0px; border: 0px; list-style: none; position: absolute; left: 11px; top: 4px; background-image: url(http://simg.sinajs.cn/blog7style/images/common/sg_icon.png?20131218); background-position: 495px -60px;"  alt="" />转载<span class="arrow" style="font-size: 7px; position: absolute; right: 5px; top: 2px;">&#9660;</span></cite></a></div></div><div class="articalTag" id="sina_keyword_ad_area" style="width: 690px; clear: both; word-break: break-all; line-height: 20px; color: #464646; font-family: Verdana, 宋体, sans-serif; font-size: 12px; font-weight: normal; background-color: #f8ecd8;"><table style="margin: 0px; padding: 0px;"><tbody><tr><td class="blog_tag" style="margin: 0px; padding: 0px 10px 0px 0px; font-size: 12px; font-family: 宋体; vertical-align: top;"><span class="SG_txtb" style="color: #909090;">标签：</span>&nbsp;</td></tr></tbody></table></div></h2><h3 style="margin: 0px 5px 0px 0px; padding: 0px; border: 0px; list-style: none; display: inline; font-size: 12px; font-weight: normal;"><a href="http://search.sina.com.cn/?c=blog&amp;q=%D4%D3%CC%B8&amp;by=tag" target="_blank" style="text-decoration: none; color: #765f47; font-family: 宋体; white-space: nowrap;">杂谈</a></h3><h2><div class="articalTag" style="width: 690px; clear: both; word-break: break-all; line-height: 20px; color: #464646; font-family: Verdana, 宋体, sans-serif; font-size: 12px; font-weight: normal; background-color: #f8ecd8;"><table style="margin: 0px; padding: 0px;"><tbody><tr><td class="blog_tag" style="margin: 0px; padding: 0px 10px 0px 0px; font-size: 12px; font-family: 宋体; vertical-align: top;"></td><td class="blog_class" style="margin: 0px; padding: 0px; font-size: 12px; font-family: 宋体; vertical-align: top; width: 220px; white-space: nowrap;"></td></tr></tbody></table></div><div id="sina_keyword_ad_area2" class="articalContent   " style="width: 690px; clear: both; padding-top: 18px; font-size: 14px; padding-bottom: 30px; overflow: hidden; font-family: simsun; word-wrap: normal; word-break: normal; color: #464646; font-weight: normal; background-color: #f8ecd8;"><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">linux中动态链接库的搜索顺序&nbsp;<wbr><br />//<br />// by kirk,2008.11.21,文中有bug请搞紧与我联系:-)<br />//&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><br />&nbsp;<wbr>&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;在接手一个很古老的程序时，发现其所使用的动态库都实在是太陈旧了，正式运行环境中部署的库都是相适应的，而目前的开发测试环境中均是部署的新的升级版本。为了能在这些环境下开发测试，程序得能在自定义的路径里来搜索。因此在这里复习一下linux中程序对动态链接库的搜索顺序，如下所述：</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;1.首先查看程序文件的.dynamic 段是否包含了一个叫DT_RPATH的项（它是一个以冒号分隔的库文件搜索目录列表）。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">　　　怎么设置这个选项？</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">　　　需要在编译连接程序的时候使用-Wl,-rpath选项，假设一个程序test需要使用liblib.so库，如下所示进行编译连接：</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">g++ -o test -L. -llib -Wl,rpath=./ test.cpp<br />&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;这样在执行test程序时，test便会先到./即当前目录下查找所需要的动态库liblib.so</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;2.查找是否存在环境变量 LD_LIBRARY_PATH（它是一个以冒号分隔的库文件搜索目录列表）。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">　　　怎么设置这个选项？当然是设置linux下的环境变量就可以了。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./<br />&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;当然，这种方法是对当前登录生效的。如果想开机即有效，跟其它环境变量的设置也是一样，需要修改一些配置文件。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;3.查看库高速缓存文件 /etc/ld.so.conf ，它包含了库名和路径的一个对应列表，如果库名存在，连接器就使用它对应的路径，用这个查找方法能够找到大部分的库。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">　　　怎么设置这个选项？可以直接编辑ld.so.conf加入需要查找的路径，也可以在/etc/ld.so.conf.d目录下的己有文件中加入路径，或者在该目录下新建一个文件（名字为*.conf即可），再把需要的路径加入到该文件中。最后执行ldconfig即可生效。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;4.查找默认路径/lib和/usr/lib,</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;如果经过了以上的步骤仍然查找失败，则将报错并退出相关程序。</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;对于前三个步骤来说，我们均是可以进行设置调整的，其中第三个步骤中的设置需要root权限才能进行，且会影响所有的程序。当使用第一、第二中的方法进行了设置调整后，我们便可以使多种版本的库共存在同一环境下进行测试，同名也无所谓。<br />&nbsp;<wbr>*********************************************************************</p><p style="margin-top: 0px; margin-right: 0px; margin-left: 0px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">环境变量<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>用来指定查找共享库时除了默认路径之外的其他路径。(该路径在默认路径之前查找)<br />移植程序时的经常碰到需要使用一些特定的动态库，而这些编译好的动态库放在我们自己建立的目录里，这时我们可以设置<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>。<br />例：export&nbsp;<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>=$<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>:/work/lib/<br />这样就可以使用/work/lib/下的库文件了,运行程序后系统会自动到环境变量<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>指定的路径中查找其所需的库。<br /><strong>系统查找动态库的顺序<br /></strong>系统先找<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>下的库再找/lib and /usr/lib等路径下的库,还有/etc/ld.so.conf里指定的路径(如果ld.so.conf存在),man ldconfig for more information<br />[url=http://infomax/bbs/misc.php?action=viewratings&amp;tid=111&amp;pid=228][/url]<br /><strong>使Linux启动之后就加载<font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>的路径</strong><br />/etc/rc.d/rc.local文件中加入export&nbsp;<wbr>&nbsp;&nbsp;<wbr><font color="#C60A00" style="word-wrap: normal; word-break: normal;">LD_LIBRARY_PATH</font>="xxxxx"&nbsp;<wbr>&nbsp;<wbr>即可<br />如果在链接时使用了"-R"和"-L"选项，则相关动态库的路径将保存在ELF文件中，于<br />是以后的运行中不再需要设置环境变量去定位动态库。比如，有一个<br />/usr/local/lib/libfoo.so，而你的bar程序需要这个libfoo.so，编译、链接时最好<br />这样 ：gcc -Wall -pipe -O3 -o bar -R/usr/local/lib -L/usr/local/lib bar.c -lfoo<br /><font color="#FF0000" style="word-wrap: normal; word-break: normal;">（#man gcc ，没发现-R或-rpath选项，待查）</font></p></div><span style="color: #333333; font-family: Arial; font-size: 14px; font-weight: normal; line-height: 26px; background-color: #ffffff;"><br /></span></h2><img src ="http://www.cppblog.com/Error/aggbug/211596.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Error/" target="_blank">Enic</a> 2015-08-18 17:42 <a href="http://www.cppblog.com/Error/archive/2015/08/18/211596.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>