Makefile for shared library

T

Travis

I'm not a Makefile expert. I have a real small program (just a
main.cpp) that needs to tie into an existing library. Now other
programs I've seen that use the library just do #include "Library.h"
but and that works. Of course that doesn't work for me because when I
do g++ main.cpp -o prog, it has no idea what to do with Library.h. I
take a look at the other people's make files and it's absolute voodoo
to me.

So is there an easy way to write my makefile to use that library? so
doing #include "Library.h" compiles? Thanks.
 
T

Travis

I'm not a Makefile expert. I have a real small program (just a
main.cpp) that needs to tie into an existing library. Now other
programs I've seen that use the library just do #include "Library.h"
but and that works. Of course that doesn't work for me because when I
do g++ main.cpp -o prog, it has no idea what to do with Library.h. I
take a look at the other people's make files and it's absolute voodoo
to me.

So is there an easy way to write my makefile to use that library? so
doing #include "Library.h" compiles? Thanks.

Also. I noticed that in the directory for the library that other
people wrote, there is a MyLibrary.a file. Is that all I need to tie
into? Not sure what the compile line is.
 
V

Victor Bazarov

Travis said:
[..]
Also. I noticed that in the directory for the library that other
people wrote, there is a MyLibrary.a file. Is that all I need to tie
into? Not sure what the compile line is.

RTFM Linking with static libraries is well documented. And it's
not part of C++ language specification, BTW.

V
 
J

James Kanze

Travis said:
I'm not a Makefile expert. [..]
Makefiles are offtopic. See the -l (that's a lowercase L)
compilation switch for your compiler.

That depends on the compiler. -l is traditionally the option
under Unix (where it also involves special naming conventions,
and other things), but I don't think it works with VC++.

Normally, a "component" will be delivered as a library and a set
of header files. You install it somewhere; you then have to
inform the compiler where to look for the headers (-I or /I are
frequently the option for this) and to use the library when it
links---specifying the full path to the library will generally
work. (Even under Unix, I find that I only use -l for system
libraries.)

You might also have to use different options according to
whether you want to link the library statically or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top