简体   繁体   English

在Linux上构建静态C ++库-我需要链接到其他库吗?

[英]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.

相关问题 如果c ++函数需要其他库,如何编译“ c语言的c ++函数”? - How do I compile “c++ functions from c” if c++ functions need other libraries? 关于在C ++中构建和使用静态库的参考 - References on building and using static libraries in C++ c ++ linux中的静态链接用法:每次更改库时都需要重新编译所有内容吗? - Static linkage usage in c++ linux: do I need to recompile everything each time I change library? 将库链接到 c++ 中的 linux 二进制文件 - Link libraries to linux biinary file in c++ 为什么需要为静态库构建指定运行时库类型? - Why do i need to specify runtime library type for static lib building? 在Visual Studio中构建没有C / C ++运行时的静态库 - Building a static lib without C/C++ runtime in Visual Studio 如何将C ++ MySQL连接器库链接到Cmake? - How do I link C++ MySQL Connector Libraries to Cmake? 如何在VS C ++ 2010 Express中链接库? - How do I link libraries in VS C++ 2010 express? 我有 .lib 和 .dll 文件,但没有 .h - 如何在其他 C++ 项目中使用这些库中的方法? - I have .lib and .dll files, but not .h - how to use methods from those libraries in other C++ project? 使用静态lib和c ++源代码构建库 - Building library with static lib and c++ sourse code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM