Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

c++ - [UNIX] : Do I need to add all libraries in my project's makefile, that are used from a library, used in my project?

Ha, this sounds more complicated, than it actually is. Here's what I mean:

Suppose I write an application, that uses threads. In this application, I don't use the pthreads directly, but I use a wrapper, that uses pthreads. So, in this wrapper's makefile, -lpthread must be included. And the question - do I need to include -lpthread in my project, or it's not necessary? Or it depends? If so, on what?

I'm asking this, because I've seen this a lot and I don't think it's necessary.. The same for -std=c++0x?


Also, I had a problem with the Informix C++ interface, as it relies on lib, called DMI, which is built on the top of ESQL/C. When I removed these libraries and use only the real one, I got linker problems(problems with finding the libs). When I added dmi and esql/c, everything was fine.

Does this answers my question (with "YES"), or I could've done something wrong, other than this (I'm newbie with makefiles (: )


source: "Makefiles are something of an arcane topic--one joke goes that there is only one makefile in the world and that all other makefiles are merely extensions of it. I assure you, however, that this is not true; I have written my own makefiles from time to time."

This made me think if all included libraries in the makefiles (of my company's projects) are necessary, or this is for "historical reasons"


EDIT: The wrapper around pthread is linked static, and the Informix lib was dynamically linked, if this matters.
Also, the OS is RHEL (4 and 5), but I need to know if this depends on the OS and on the way of linking (dynamic or static)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unless the libraries are somehow included in the wrapper you are using, the answer is YES you will need to include them in the makefile of the program that uses the wrapper.

For instance if the wrapper is a .o, it hasn't been linked to anything yet. However, if the wrapper is a .so or .a, it may include the libraries depending on how you constructed it. I think ar is responsible for this kind of things.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...