{"id":1534,"date":"2016-01-15T14:33:03","date_gmt":"2016-01-15T19:33:03","guid":{"rendered":"http:\/\/jungwon.kim\/blog\/?p=1534"},"modified":"2016-01-15T14:33:03","modified_gmt":"2016-01-15T19:33:03","slug":"xl-c-for-aix-13-1-0-compiling-a-shared-library","status":"publish","type":"post","link":"https:\/\/blog.jungwon.kim\/?p=1534","title":{"rendered":"XL C for AIX 13.1.0: Compiling a shared library"},"content":{"rendered":"<p><a href=\"https:\/\/www-01.ibm.com\/support\/knowledgecenter\/SSGH2K_13.1.0\/com.ibm.xlc131.aix.doc\/proguide\/compiling_shared_aix.html\">https:\/\/www-01.ibm.com\/support\/knowledgecenter\/SSGH2K_13.1.0\/com.ibm.xlc131.aix.doc\/proguide\/compiling_shared_aix.html<\/a><\/p>\n<p><b><\/b><span class=\"s1\">To compile a shared library that uses dynamic linking:<\/span><\/p>\n<ol class=\"ol1\">\n<li class=\"li3\"><span class=\"s1\">Compile each source file into an object file, with no linking. For example: <\/span><span class=\"s2\">xlc -c test1.c -o test1.o<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Optional: Create an export file listing the global symbols to be exported, by doing one of the following:<\/span>\n<ul class=\"ul1\">\n<li class=\"li3\"><span class=\"s1\">Use the <\/span><span class=\"s3\"><b>CreateExportList<\/b><\/span><span class=\"s1\"> utility, described in <a href=\"https:\/\/www-01.ibm.com\/support\/knowledgecenter\/SSGH2K_13.1.0\/com.ibm.xlc131.aix.doc\/proguide\/rkexplst.html?lang=en-us\"><span class=\"s4\">Exporting symbols with the CreateExportList utility<\/span><\/a>.<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Use the <\/span><span class=\"s3\"><b>-qexpfile<\/b><\/span><span class=\"s1\"> compiler option with the <\/span><span class=\"s3\"><b>-qmkshrobj<\/b><\/span><span class=\"s1\"> option. The <\/span><span class=\"s3\"><b>-qexpfile<\/b><\/span><span class=\"s1\"> option saves all exported symbols from a list of given object files in a designated file. For example: <\/span><span class=\"s2\">xlc -qmkshrobj -qexpfile=exportlist test1.o test2.o<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Manually create an export file using a text editor. You can edit an export file to include or exclude global symbols from the target shared library.<\/span><\/li>\n<\/ul>\n<\/li>\n<li class=\"li3\"><span class=\"s1\">Use the <\/span><span class=\"s3\"><b>-qmkshrobj<\/b><\/span><span class=\"s1\"> option to create a shared library from the generated object files.<\/span>\n<ul class=\"ul1\">\n<li class=\"li3\"><span class=\"s1\">If you created an export file in step 2, use the <\/span><span class=\"s3\"><b>-bE<\/b><\/span><span class=\"s1\"> linker option to use your global symbol export list. If you do not specify a <\/span><span class=\"s3\"><b>-bE<\/b><\/span><span class=\"s1\"> option, all the global symbols are exported except for those symbols that have the hidden or internal visibility attribute.<\/span><\/li>\n<\/ul>\n<\/li>\n<li class=\"li4\"><span class=\"s6\">For example: <\/span><span class=\"s7\">xlc -qmkshrobj -o mySharedObject.o test1.o test2.o -bE:exportlist<\/span><span class=\"s8\"><br \/>\n<\/span><span class=\"s6\"><b>Notes:<\/b><\/span><\/p>\n<ul class=\"ul1\">\n<li class=\"li3\"><span class=\"s1\">The default name of the shared object is <\/span><span class=\"s3\"><b>shr.o<\/b><\/span><span class=\"s1\">, unless you use the <\/span><span class=\"s3\"><b>-o<\/b><\/span><span class=\"s1\"> option to specify another name.<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Exporting some functions (such as <\/span><span class=\"s9\">restf#<\/span><span class=\"s1\"> where <\/span><span class=\"s9\">#<\/span><span class=\"s1\"> is a number) might cause incorrect execution. If any files in the shared library use floating point and are compiled with the <\/span><span class=\"s3\"><b>-qtwolink<\/b><\/span><span class=\"s1\"> option, do not export the <\/span><span class=\"s9\">restf#<\/span><span class=\"s1\"> or equivalent floating-point utility functions.<\/span><\/li>\n<\/ul>\n<\/li>\n<li class=\"li3\"><\/li>\n<li class=\"li3\"><span class=\"s1\">Optional: Use the AIX\u00c2\u00ae <\/span><span class=\"s3\"><b>ar<\/b><\/span><span class=\"s1\"> command to produce an archive library file from multiple shared or static objects. For example: <\/span><span class=\"s2\">ar -rv libtest.a mySharedObject.o myStaticObject.o<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Link the shared library to the main application, as described in <a href=\"https:\/\/www-01.ibm.com\/support\/knowledgecenter\/SSGH2K_13.1.0\/com.ibm.xlc131.aix.doc\/proguide\/link_app.html?lang=en-us#link_app\"><span class=\"s4\">Linking a library to an application<\/span><\/a>.<\/span><\/li>\n<\/ol>\n<p class=\"p2\"><span class=\"s1\"><b>For use with runtime linking<\/b><\/span><\/p>\n<p class=\"p3\"><span class=\"s1\">To create a shared library that uses runtime linking:<\/span><\/p>\n<ol class=\"ol1\">\n<li class=\"li3\"><span class=\"s1\">Follow steps 1 and 2 in the procedure described above.<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Use the <\/span><span class=\"s3\"><b>-G<\/b><\/span><span class=\"s1\"> option to create a shared library from the generated object files, and to enable runtime linking with applications that support it.<\/span>\n<ul class=\"ul1\">\n<li class=\"li3\"><span class=\"s1\">If you created an export file, use the <\/span><span class=\"s3\"><b>-bE<\/b><\/span><span class=\"s1\"> linker option to use your global symbol export list. If you do not specify a <\/span><span class=\"s3\"><b>-bE<\/b><\/span><span class=\"s1\"> option, all the global symbols are exported except for those symbols that have the hidden or internal visibility attribute.<\/span><\/li>\n<\/ul>\n<\/li>\n<li class=\"li4\"><span class=\"s6\">For example: <\/span><span class=\"s7\">xlc -G -o libtest.so test1.o test2.o -bE:exportlist\u00c2\u00a0<\/span><\/li>\n<li class=\"li3\"><span class=\"s1\">Link the shared library to the main application using the <\/span><span class=\"s3\"><b>-brtl<\/b><\/span><span class=\"s1\"> option, as described in <a href=\"https:\/\/www-01.ibm.com\/support\/knowledgecenter\/SSGH2K_13.1.0\/com.ibm.xlc131.aix.doc\/proguide\/link_app.html?lang=en-us#link_app\"><span class=\"s4\">Linking a library to an application<\/span><\/a>.<\/span><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www-01.ibm.com\/support\/knowledgecenter\/SSGH2K_13.1.0\/com.ibm.xlc131.aix.doc\/proguide\/compiling_shared_aix.html To compile a shared library that uses dynamic linking: Compile each source file into an object file, with no linking. For example: xlc -c test1.c -o test1.o Optional: Create an export file listing the global symbols to be exported,<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1534","post","type-post","status-publish","format-standard","hentry","category-cs"],"_links":{"self":[{"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=\/wp\/v2\/posts\/1534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1534"}],"version-history":[{"count":0,"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=\/wp\/v2\/posts\/1534\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jungwon.kim\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}