<< return to Pixycam.com

[Beginner] Compiling pixy code C++

TL;DR Can someone provide me a sample compile code for a pixy C++ script. I can’t seem to link pixy.h to my script

Long version:

I’ve asked this on a few other forums and haven’t gotten a great answer yet so I figured I should have asked here first and so now I am.

I have been trying to connect the Pixy Cam to a raspberry pi and am using C++ to allow the two to communicate. However, trying to write scripts for them doesn’t seem to work for me, even though my basic knowledge tells me it should be working so I’m assuming I’m missing something obvious.

Here is the simplest code I wrote that should work, as, if I understand headers correctly, I can call functions from any of the header files as if I were calling a function within the script itself, yes?

This script should just establish a connection with the camera, however the compiler still tells me that the function is undefined.

#include "stdio.h"
#include "stddef.h"
#include "stdint.h"
#include "unistd.h"
#include "pixy.h"
#include "pixydefs.h"

     int main(int argc, char* argv[])
     {
      pixy_init();
     }

I am using g++ to compile it using the following (shortened directory files to save space)

g++ code.cpp -oCode -I/"folder including libusb-1.0 and pixy.h"

So what am I missing? Everything I’ve learned so far says that this should work?

Do I have to include

     -Llibusb

and whatever the relevant one for pixy.h is to the g++ command to link libraries? I’ve seen some people adding the -libusb to the end of it, however I haven’t been able to find what that does.

Hello,
Have you been able to get the libpixyusb “hello_pixy” example compiled and working?

http://cmucam.org/projects/cmucam5/wiki/Building_the_libpixyusb_example_on_Linux

After you build hello_pixy, it will create a makefile in the same directory ~build/hello_pixy. The makefile is auto-generated. It goes through your machine and tries to find the location of all the relevant libraries, such as libusb, libboost, etc. These libraries will be located in different locations depending on your Linux distribution. So it is sometimes challenging to type in your own compile/link command like you are trying. Take a look at the makefile. This is probably the best way to determine how to compile and link in the libraries on your system so that the required libraries are grabbed.

Or you can try to modify the hello_pixy source directly. This is the easiest option because the makefile is already written for you :slight_smile:

Edward