[英]Building a static c++ lib on linux - do I need to link to other libraries?
I have been building a static library on Linux. 我一直在Linux上构建静态库。 So far it is purely self contained and all code inside does not use anything other than the standard library.
到目前为止,它完全是自包含的,并且其中的所有代码均不使用标准库以外的任何东西。 I have recently made a change and now some compilation units are using boost code.
我最近进行了更改,现在一些编译单元正在使用增强代码。 I have been building the library using the following:
我一直在使用以下内容构建库:
g++ -c -Wall -pedantic *.cpp
ar -cvq libbfclass.a *.o
My question is this: is it necessary for me to adapt this method to deal with the use of the new libraries or will I just need to provide the link library when building the executable that uses my own library? 我的问题是:我是否有必要对这种方法进行调整以处理新库的使用,还是在构建使用自己的库的可执行文件时仅需要提供链接库? From what I understand a static library is basically just an archive of object files, but I was wondering if I need to modify my build scripts in order to make everything work as it should, or if it is only necessary when building executables???
据我了解,静态库基本上只是对象文件的存档,但是我想知道是否需要修改构建脚本以使所有内容正常运行,还是仅在构建可执行文件时才需要?
You are correct - a static library is just an archive of object files. 您是正确的-静态库只是目标文件的存档。 Symbols are resolved when you compile the final executable, so that's when you need to provide the references to the other libraries.
编译最终的可执行文件时,符号会被解析,因此需要提供对其他库的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.