开发者

CMake: Building a Static Binary

I'm trying to build a static binary w开发者_开发技巧ith CMake.

I've looked around and found a number of non descriptive solutions(e.g add the linker flag "-static"), but I'm not sure how to test them.

How do I know if a certain library (e.g Threading) has been statically built into my binary?


As trenki says, use ldd to get the list of dynamically linked libraries that your executable depends on, and check it to be sure that the code you wanted statically linked is not there.

You can also use the nm and strings commands to get a dump of the programmatic symbols and human-readable text, respectively, in your executable. Use grep to filter that output for identifiers in your static library that you reference in your code, like function names.

Lastly, you can use the objdump command to get a disassembly listing of your program. Static library functions should appear in it.

The first approach, coupled with an executable that compiles, links, and runs well enough to demonstrate the functionality that the static library helps provide is probably a sufficient test. Use the second or third approaches only if you want to dig deep.


Not CMake-related, but if you're on a UNIX system the file utility can at least tell you whether your binary is using shared libs or not.


Under Linux you can also use the ldd command which shows which libraries your binary links to dynamically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜