{"id":733,"date":"2020-01-13T14:23:25","date_gmt":"2020-01-13T22:23:25","guid":{"rendered":"http:\/\/209.126.2.187\/?page_id=733"},"modified":"2020-03-22T10:35:39","modified_gmt":"2020-03-22T17:35:39","slug":"c-compiling-related","status":"publish","type":"page","link":"https:\/\/nanzhou.cc\/index.php\/snippets\/c-compiling-related\/","title":{"rendered":"C++ Compiling"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">List Objects of Binary<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">objdump -T xxx.bin -C | grep \"mynamespace::MyClass\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Shared Libraries Dependencies<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ldd xxx.so<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">RPath<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">objdump -x xxx.bin | grep RPATH\nreadelf -d run_inferencer |head -20<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Static Libraries<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ar -t xxx.a<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Static Libraries Dependencies<\/h2>\n\n\n\n<p><code>A &lt;- B &lt;- C <\/code>(B uses A), when you build A, B, and C as static libraries, and another target uses A, B, C. In the <code>target_link_libraries()<\/code>, the order should be <code>target_link_libraries(C, B, A)<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Compile Static Libs<\/h2>\n\n\n\n<p>We want to provide our C++ application as a shared library and support the old version of GCC like 4.x.x. <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Thus, we need to build all static libraries with -fPIC.  <\/li><li>We should add <code>-D_GLIBCXX_USE_CXX11_ABI=0<\/code>.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><em>Protocol Buffers 3.5.1<\/em><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">.\/configure CFLAGS='-fPIC -D_GLIBCXX_USE_CXX11_ABI=0' CXXFLAGS='-fPIC -D_GLIBCXX_USE_CXX11_ABI=0'\n make\n make install DESTDIR=\/home\/zhoun14\/Downloads\/protobuf-3.5.1\/build<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>JsonCPP 1.8.4<\/em><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">cmake -DCMAKE_CXX_FLAGS='-fPIC -D_GLIBCXX_USE_CXX11_ABI=0' \\\n      -DCMAKE_C_FLAGS='-fPIC -D_GLIBCXX_USE_CXX11_ABI=0' \\\n      -DCMAKE_BUILD_TYPE=Release ..\nmake\nmake install DESTDIR=\/home\/zhoun14\/Downloads\/jsoncpp-master\/build<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><em>GTest 1.10.0<\/em><br><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">cmake -DCMAKE_CXX_FLAGS='-fPIC -D_GLIBCXX_USE_CXX11_ABI=0' \\\n      -DCMAKE_C_FLAGS='-fPIC -D_GLIBCXX_USE_CXX11_ABI=0' \\\n      -DCMAKE_BUILD_TYPE=Release ..\nmake\nmake install DESTDIR=\/home\/zhoun14\/Downloads\/googletest-release-1.10.0\/build<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>List Objects of Binary Shared Libraries Dependencies RPath Static Libraries Static Libraries Dependencies A &lt;- B &lt;- C (B uses A), when you build A, B, and C as static libraries, and another target uses A, B, C. In the target_link_libraries(), the order should be target_link_libraries(C, B, A). Compile Static Libs We want to provide&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":452,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-733","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/pages\/733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/comments?post=733"}],"version-history":[{"count":10,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/pages\/733\/revisions"}],"predecessor-version":[{"id":827,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/pages\/733\/revisions\/827"}],"up":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/pages\/452"}],"wp:attachment":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/media?parent=733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}