Felipe Cortez
Felipe Cortez

Reputation: 257

Adding a library to a makefile

I just installed RtMidi for a project and compiled it. The examples in the tests folder work and so does my code if I put it in the folder and include it in the Makefile that compiles all the examples. How can I use RtMidi in a project with #include <RtMidi.h> instead of having my code in the tests folder? More specifically, what should I put in my Makefile? I've read a bit about dynamic and static libraries but I have no idea what I should be looking for. I've tried adding -llibrtmidi and /usr/local/lib/librtmidi.a without success.

Upvotes: 1

Views: 9656

Answers (2)

therealneil
therealneil

Reputation: 5300

Based on your description of your environment, you may require something like

CPPFLAGS += -I/usr/local/include

LDFLAGS += -L/usr/local/lib

LDLIBS += -lrtmidi

in your Makefile. make uses a lot of these implicit variables.

Upvotes: 2

pcarter
pcarter

Reputation: 1618

In a standard Makefile, the CXXFLAGS macro defines flags for the C++ compiler. You will need to add -I<path to header directory> to this macro for the compiler to find the RtMidi header files.

Then you will need to add -L<path to lib directory> to the link step of the Makefile so that -lrtmidi will find the library file. (Note that you omit the lib prefix for the -l command)

Upvotes: 2

Related Questions