{"id":16509329,"url":"https://github.com/calebmadrigal/static-shared-lib","last_synced_at":"2025-06-15T19:08:26.472Z","repository":{"id":145270659,"uuid":"51407195","full_name":"calebmadrigal/static-shared-lib","owner":"calebmadrigal","description":"An example of how to statically compile a shared linux library (.so).","archived":false,"fork":false,"pushed_at":"2016-02-10T17:37:30.000Z","size":150,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T18:33:59.397Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/calebmadrigal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-09T23:03:18.000Z","updated_at":"2024-11-23T04:43:16.000Z","dependencies_parsed_at":"2023-04-30T08:25:31.631Z","dependency_job_id":null,"html_url":"https://github.com/calebmadrigal/static-shared-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebmadrigal%2Fstatic-shared-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebmadrigal%2Fstatic-shared-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebmadrigal%2Fstatic-shared-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebmadrigal%2Fstatic-shared-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calebmadrigal","download_url":"https://codeload.github.com/calebmadrigal/static-shared-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241465113,"owners_count":19967243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T15:50:00.327Z","updated_at":"2025-03-02T06:14:16.242Z","avatar_url":"https://github.com/calebmadrigal.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# static-shared-lib-example\n\nAn example of how to build a statically-linked shared (dynamic) linux library (.so).\n\nThings to note:\n\n* `do_test.main()` calls `libtestlib.do_test()` which calls `testlib2.square()`.\n* `libtestlib.so` is statically compiled. It relies on `testlib2.o` for the `square()` function.\n* Since `testlib.so` is statically compiled, we can delete `testlib2.o` and `do_test` still runs.\n\nMy goal was to have `testlib2` be a normal dynamic library (`.so`), however, I was unable to statically compile it into `libtestlib.so` without changing how testlib2 was compiled, so that it is just an unlinked object file.\n\n### Usage\n\nBuild it:\n\n    make\n\nRun it:\n\n    make test\n\nThis deletes `testlib2.o` and runs `do_test`.\n\n### Seeing the static linking\n\nYou can see that `libtestlib.so` is statically linked against `testlib2.o` by running `ldd`:\n\n    $ ldd libtestlib.so\n        linux-vdso.so.1 =\u003e  (0x00007fffa2ffc000)\n        libc.so.6 =\u003e /lib/x86_64-linux-gnu/libc.so.6 (0x00007f23e0a52000)\n        /lib64/ld-linux-x86-64.so.2 (0x00007f23e1034000)\n\nAlso, note, however, that `testlib.so` is dynamically linked against glibc and a couple other libraries.\n\n### Disassembly\n\nI opened `libtestlib.so` in [Hopper disassembler](http://www.hopperapp.com/), and was able to see the `square` function from `testlib2.o` in it (along side `do_test`):\n\n![libtestlib.so disassembled](https://raw.githubusercontent.com/calebmadrigal/static-shared-lib/master/testlib-so-disassembled.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebmadrigal%2Fstatic-shared-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalebmadrigal%2Fstatic-shared-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebmadrigal%2Fstatic-shared-lib/lists"}