链接问题 - 尝试构建一个库并使用另一个存档
是否可以构建一个使用另一个已编译库的库?
我有一些通常用于构建可执行文件的 make 文件。制作可执行文件时,我使用 -L ../include/lib1.a 来包含原始库。
现在,我正在构建一个单独的程序,该程序从可执行文件中调用类,该程序从未内置到库中,只是使用类似的链接编译为可执行文件,
${CPP} -c ${INC} ${CFLAGS} MyFile.cpp ${OBJ} ${LIB2} -lm
其中 LIB2 包含对 lib1.a 的引用
现在我想访问该类直接使用 MyFile.cpp,当我将其构建到自己的库 lib2.a 并尝试从新程序中调用它时,我收到一堆错误,表明它引用的类丢失了。尽管事实上在构建新程序时我同时链接了 lib1.a 和 lib2.a
Is it possible to build a library that uses another, already compiled library?
I have some make files that are used to normally build an executable. When making the executable, I use -L ../include/lib1.a to include the original library.
Now, I am building a separate program that is calling the classes from the executable, which was never built into a library, just compiled to the executable with a link like
${CPP} -c ${INC} ${CFLAGS} MyFile.cpp ${OBJ} ${LIB2} -lm
Where LIB2 includes the reference to lib1.a
Now I want to access the class MyFile.cpp directly, and when I build it to its own library lib2.a, and try to call it from the new program, I get a bunch of errors that the classes it references are missing. This is in spite of the fact that when building the new program I am linking in both lib1.a and lib2.a
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该:
不应该:
即 -L 表示库搜索路径,-l 表示存档名称?
Should:
not be:
I.e. -L denotes the library search path and -l the archive name?
是的,你应该能够做到。查看您遇到的确切错误将会很有帮助。
如果您将源代码编译到库中并提供它们在命令行上使用的库,则编译器可能会将其他库放入您的新库中。如果发生这种情况,然后有人尝试针对您的库和其他库构建程序,他们将得到一大堆“双重定义符号”错误。
Yes, you should be able to do it. It would be helpful to see the exact errors you are getting.
If you compile your sources into a library and supply the libraries they use on the command line, the compiler is liable to put the other library(s) into your new one. If that happens, and then someone tries to build a program against your library and those others, they will get a whole mess of "doubly-defined symbol" errors.
当您构建 lib2.a 时,它将不包含 lib1.a 中包含的对象文件。
您的最终可执行文件必须链接到它们两个。
When you build lib2.a it will not contain the objects files contained in lib1.a.
Your final executable has to link in both of them.