hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.64k stars 1.16k forks source link

Makefile and linking libraries #585

Open ryan1117001 opened 6 years ago

ryan1117001 commented 6 years ago

Hello

I'm having a problem with linking the libraries. From what I have, I've linked the libraries to OpenCV correctly, but not the one's for rpi-rgb-led-matrix. How do I link the libraries? Makefile:

led: minimal-example.cc g++ -o led minimal-example.cc -lopencv_core -lopencv_imgproc -lopencv_imgcodecs

Errors:

/tmp/ccYPtyMS.o: In function main': minimal-example.cc:(.text+0x1c0): undefined reference torgb_matrix::RGBMatrix::Options::Options()' minimal-example.cc:(.text+0x204): undefined reference to `rgb_matrix::CreateMatrixFromFlags(int*, char, rgb_matrix::RGBMatrix::Options, rgb_matrix::RuntimeOptions, bool)' collect2: error: ld returned 1 exit status Makefile:2: recipe for target 'led' failed make: [led] Error 1

Code:

include "led-matrix.h"

include

include

include

include

include <opencv2/core.hpp>

include <opencv2/imgproc.hpp>

include <opencv2/imgcodecs.hpp>

using rgb_matrix::GPIO; using rgb_matrix::RGBMatrix; using rgb_matrix::Canvas; using namespace cv;

volatile bool interrupt_received = false; static void InterruptHandler(int signo) { interrupt_received = true; }

static void DrawOnCanvas(Canvas *canvas) { Mat input_image = cv::imread("snapshot.png"); for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { Vec3b color = input_image.at(Point(x,y)); canvas->setPixel(x,y,color[0],color[1],color[2]); } } }

int main(int argc, char argv[]) { RGBMatrix::Options defaults; defaults.hardware_mapping = "regular"; // or e.g. "adafruit-hat" defaults.rows = 32; defaults.chain_length = 1; defaults.parallel = 1; defaults.show_refresh_rate = true; Canvas canvas = rgb_matrix::CreateMatrixFromFlags(&argc, &argv, &defaults); if (canvas == NULL) return 1;

// It is always good to set up a signal handler to cleanly exit when we // receive a CTRL-C for instance. The DrawOnCanvas() routine is looking // for that. signal(SIGTERM, InterruptHandler); signal(SIGINT, InterruptHandler);

DrawOnCanvas(canvas); // Using the canvas.

// Animation finished. Shut down the RGB matrix. canvas->Clear(); delete canvas;

return 0; }

stefandz commented 6 years ago

Have you tried adding these lines to your Makefile (or linker options) and modifying the library path to suit where it is on your system?