{"id":16558446,"url":"https://github.com/leaking/compileandlink","last_synced_at":"2026-05-11T15:07:51.948Z","repository":{"id":79790243,"uuid":"470923515","full_name":"Leaking/CompileAndLink","owner":"Leaking","description":null,"archived":false,"fork":false,"pushed_at":"2022-03-18T07:32:25.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T00:47:53.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/Leaking.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-17T09:17:29.000Z","updated_at":"2022-03-17T13:01:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"41fc6471-a81b-4d2a-80cc-bb4bcec70bfc","html_url":"https://github.com/Leaking/CompileAndLink","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Leaking/CompileAndLink","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leaking%2FCompileAndLink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leaking%2FCompileAndLink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leaking%2FCompileAndLink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leaking%2FCompileAndLink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Leaking","download_url":"https://codeload.github.com/Leaking/CompileAndLink/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leaking%2FCompileAndLink/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32900158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"online","status_checked_at":"2026-05-11T02:00:05.975Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11T20:10:45.259Z","updated_at":"2026-05-11T15:07:51.932Z","avatar_url":"https://github.com/Leaking.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CompileAndLink\n\n## create static lib \nar rc libmain.a main.o work.o\n\n## create dylib\ng++ -shared layer.o conflict.o -o libconflict.so\n\ng++ -s -L. -o main -lmain -lconflict\ng++ -Wl,--version-script=export.txt -shared layer.o conflict.o -o libconflict.so\n\n\n## hidden\n\n\ng++ -fvisibility=hidden -c ../conflict.cc  -o conflict.o\n\n\nhidde之后，符号类型为t\n\n```\n➜  build git:(main) ✗ nm libconflict.so                                \n0000000000003f60 t __Z7DoLayerv\n0000000000003f80 t __Z7DoThingv\n                 U _printf\n```\n\n\ngcc -Wl, --version-script export.txt -shared layer.o conflict.o -o libconflict.so\n\n\nclang 不支持 --version-script\n\n\n\nnm中\nT是公开而且实现的函数\nt则是hide的接口\n\n\n执行以下命令\n```\n➜  build git:(main) ✗ g++ -c ../main.cc -o main.o\n➜  build git:(main) ✗ g++ -c ../work.cc -o work.o \n➜  build git:(main) ✗ g++ -c ../conflict.cc -o conflict.o\n➜  build git:(main) ✗ g++ -c ../layer.cc -o layer.o    \n➜  build git:(main) ✗ ar rc libmain.a main.o work.o\n➜  build git:(main) ✗ g++ -shared layer.o conflict.o -o libconflict.so\n➜  build git:(main) ✗ g++ -s -L. -o main -lmain -lconflict\n\n```\n\n## linux的表现\n\n\n```\nstart\nwork\nlayer\nwork\nfinished\n```\n\n\n```\n// 隐藏符号后\nubuntu@VM-0-2-ubuntu:~/workspace/CompileAndLink/sample1/build$ g++ -fPIC -fvisibility=hidden -c ../conflict.cc -o conflict.o\nubuntu@VM-0-2-ubuntu:~/workspace/CompileAndLink/sample1/build$ g++ -shared layer.o conflict.o -o libconflict.so\nubuntu@VM-0-2-ubuntu:~/workspace/CompileAndLink/sample1/build$ g++ -s -L. -o main -lmain -lconflict\nubuntu@VM-0-2-ubuntu:~/workspace/CompileAndLink/sample1/build$ ./main\nstart\nwork\nlayer\nconflict\nfinished\n\n```\n\n\n```\n// linux 先修改main和conflict的链接顺序，会报错，Mac则不会\n\nubuntu@VM-0-2-ubuntu:~/workspace/CompileAndLink/sample1/build$ g++ -s -L. -o main  -lconflict -lmain\n./libmain.a(main.o): In function `main':\nmain.cc:(.text+0x14): undefined reference to `DoLayer()'\ncollect2: error: ld returned 1 exit status\n\n```\n\n\n\n\n## mac的表现\n\n```\n➜  build git:(main) ✗ g++ -s -L. -o main -lmain -lconflict\n➜  build git:(main) ✗ ./main\nstart \nwork \nlayer \nconflict \nfinished \n\n```\n\n```\n➜  build git:(main) ✗ g++ -s -L. -o main -lconflict -lmain\n➜  build git:(main) ✗ ./main\nstart\nconflict\nlayer\nconflict\nfinished\n```\n\n\n```\n➜  build git:(main) ✗ g++ -fvisibility=hidden -c ../conflict.cc -o conflict.o\n➜  build git:(main) ✗ g++ -shared layer.o conflict.o -o libconflict.so\n➜  build git:(main) ✗ g++ -s -L. -o main -lconflict -lmain\nld: warning: option -s is obsolete and being ignored\n➜  build git:(main) ✗ ./main\nstart\nwork\nlayer\nconflict\nfinished\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleaking%2Fcompileandlink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleaking%2Fcompileandlink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleaking%2Fcompileandlink/lists"}