Can I implement C code using libpixyusb library?

Added by Munkh D about 1 month ago

I have a tool that only supports C language. Can I use libpixyusb library without changing the source code of libpixyusb library?


Replies (6)

RE: Can I implement C code using libpixyusb library? - Added by Edward Getz about 1 month ago

You'll need to give us more details about what you are trying to do.

libpixyusb is supported in Linux using GCC. Some users have ported libpixyusb to Windows .NET, but in general, we wouldn't expect libpixyusb to work for any other compiler "out of the box" without some porting/debugging.

RE: Can I implement C code using libpixyusb library? - Added by Munkh D about 1 month ago

Thank you for the reply.
My environment is Linux. I installed G++ compiler.
What I'm trying to do is that:
  • I created "test.c" file.
  • In the "test.c" I included header file "pixy.h".
  • Before that I followed the instruction to build and install libpixyusb library on my Linux machine: http://cmucam.org/projects/cmucam5/wiki/Building_the_libpixyusb_example_on_Linux
  • When I'm trying to compile test.c code, I got error saying:
    $ gcc test.c -o test
    In file included from test.c:22:0:
    /usr/local/include/pixy.h:50:5: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘
    _attribute__’ before ‘{’ token{_

I tried another approach. I changed test.c into test.cpp.
Then I compiled. This time I got another error.

$ gcc test.cpp -o test
/tmp/ccFkAJXO.o: In function `main':
test.cpp:(.text+0x53): undefined reference to `pixy_init'
test.cpp:(.text+0x79): undefined reference to `pixy_error'
test.cpp:(.text+0xa1): undefined reference to `pixy_get_firmware_version'
test.cpp:(.text+0xca): undefined reference to `pixy_error'
test.cpp:(.text+0x12b): undefined reference to `pixy_blocks_are_new'
test.cpp:(.text+0x15d): undefined reference to `pixy_get_blocks'
test.cpp:(.text+0x186): undefined reference to `pixy_error'
test.cpp:(.text+0x1fb): undefined reference to `pixy_close'
collect2: error: ld returned 1 exit status

I don't know what's the problem.
My aim is to call pixy.h inside test.c, but not test.cpp
I'm new at c/c++.

Capture.JPG (33.4 kB)

RE: Can I implement C code using libpixyusb library? - Added by Edward Getz about 1 month ago

Hello,
If you're getting started with C, I would stick to the example programs like hello_pixy. It compiles and give you an idea of what you can and can't do. Once you feel like you understand what hello_pixy is doing, you can try to edit its source code (hello_pixy.cpp)

Hope this helps.

Edward

RE: Can I implement C code using libpixyusb library? - Added by Munkh D about 1 month ago

Hello,
I played with hello_pixy example.It works fine and I understand how it works and what it is doing.
I think I need to explain my problem again.
I have a simulation tool that supports C language.This tool builds system in C automatically.
How can I tell the tool that I am linking to libpixyusb library without making make file?
Can I just copy .h and .cpp files in my project folder, then include pixy.h in the header?
Thank you.

RE: Can I implement C code using libpixyusb library? - Added by Geert van Wissen about 1 month ago

I had kind of the same questions. My programming skills are enough to understand everything within the cpp and header files, but I just can't get my head around the cmake procedures. So I compile everything 'by hand'. I know it's not efficient, but for most of my work it's perfectly doable. I had some trouble with pixy though, because I couldn't find the right library to link. But finally I got my project compiled on a Raspberry Pi zero W using the following command:

g++ -o walter walter_pixy.cpp -I/usr/include/libusb-1.0/ -lwiringPi -lncurses -std=c++11 -rdynamic -lpixyusb -lboost_thread -lboost_system -lboost_chrono -lboost_date_time -lboost_atomic -lpthread -lusb-1.0

Before my project used the pixy.h lib I already used: -lwiringPi -lncurses -std=c++11
The rest of the linked files I found in the link.txt file in the build dir of hello_pixy
The -I/usr/include/libusb-1.0/ was needed to find the libusb.h file

I thought I'd share this, since I've been busy with it for so long :-)

RE: Can I implement C code using libpixyusb library? - Added by Edward Getz about 1 month ago

Hello Geert,
Agreed that Cmake can be hard to understand. We use it to help find the right dependencies on a given platform. It generates a makefile, which you can use/modify on your system after it's generated.

Thanks for sharing!

Edward

(1-6/6)