Cole1717
Posts: 29
Joined: Mon Mar 16, 2015 10:44 pm

Installing Third Party C Library

Sun Mar 06, 2016 8:39 pm

I am attempting to install the library for controlling a adafruit rgb matrix located here: https://github.com/hzeller/rpi-rgb-led-matrix. I am unfamiliar with how to install third party libs and the readme doesn't directly address it (i'm guessing it is common knowledge).

When you write a c program you direct it to include libs at the top (ie. #include <string.h>) and it will know where it is no matter where your program is being compiled. How do I make third party libraries cloned from github be accessible "globally" like the default installed libraries? Do i need to add something to the Makefile or call make with specific commands when compiling the library?

Thanks!

User avatar
PeterO
Posts: 4941
Joined: Sun Jul 22, 2012 4:14 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 8:47 pm

It looks like it comes with a makefile. Have you tried "make" ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Cole1717
Posts: 29
Joined: Mon Mar 16, 2015 10:44 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 8:52 pm

Yea, it works and i can run the compiled demos. But I am then trying to make my own program that uses the same libraries but in a different location. #include <led-matrix.h> at the top of my new file doesn't compile because it doesn't know where it is. Do i need to copy the .h file to /usr/include/ and something similar with the lib files?

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Installing Third Party C Library

Sun Mar 06, 2016 9:16 pm

Cole1717 wrote:Yea, it works and i can run the compiled demos. But I am then trying to make my own program that uses the same libraries but in a different location. #include <led-matrix.h> at the top of my new file doesn't compile because it doesn't know where it is. Do i need to copy the .h file to /usr/include/ and something similar with the lib files?
See if there is a make install with the library. That might put it in /usr/local/include for example. Then to compile, you might need

gcc -I/usr/local/include -omyprob myprog.c -lnameOfLib

sort of thing. Most systems will include /usr/local/include in the include search path, but you can use this to tell it that it's elsewhere. Same for -L (capital L, not the lower case l in -llibName) as in: -L/path/to/library -lnameOfLib

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
PeterO
Posts: 4941
Joined: Sun Jul 22, 2012 4:14 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 9:22 pm

gordon@drogon.net wrote: See if there is a make install with the library.
It doesn't look like the author has considered doing anything other than building his examples :-(

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Cole1717
Posts: 29
Joined: Mon Mar 16, 2015 10:44 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 9:25 pm

Thanks for the reply. Running 'make install' returns "No rule to make target 'install'. Stop." Does this mean the rest of your solution is inapplicable? Is there a way to do this manually?

Cole1717
Posts: 29
Joined: Mon Mar 16, 2015 10:44 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 9:30 pm

PeterO wrote: It doesn't look like the author has considered doing anything other than building his examples :-(
I'm not very familiar with the workings of c/c++. I have only ever done basic projects using the standard libraries. I would think getting basic code running would be the first thing to try if you know the provided samples work. What would you suggest?

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Installing Third Party C Library

Sun Mar 06, 2016 9:33 pm

Cole1717 wrote:Thanks for the reply. Running 'make install' returns "No rule to make target 'install'. Stop." Does this mean the rest of your solution is inapplicable? Is there a way to do this manually?
You can still use the rest of my solution. You just need to work out where the header & library files are.

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
PeterO
Posts: 4941
Joined: Sun Jul 22, 2012 4:14 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 10:51 pm

Cole1717 wrote: What would you suggest?
The supplied makefile has the examples in it as targets. You could model your application after one of the examples and modify the makefile ti build it in the same way that the examples are built.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Cole1717
Posts: 29
Joined: Mon Mar 16, 2015 10:44 pm

Re: Installing Third Party C Library

Sun Mar 06, 2016 11:04 pm

PeterO wrote:
The supplied makefile has the examples in it as targets. You could model your application after one of the examples and modify the makefile ti build it in the same way that the examples are built.
Yea, i didn't really understand how Make works, so I did some reading. After looking through the Makefile i realized something very silly I got wrong. This library is for c++ not c. :oops: I had been trying to write and compile a c program, not c++. :oops: :o :lol:

Whoops...Thanks for the help! I learned a thing or two.

Return to “C/C++”