kyvaith
Posts: 1
Joined: Tue Apr 06, 2021 3:39 pm

Please help with compiling simple code

Tue Apr 06, 2021 3:41 pm

Is there any good soul that will compile for me this code https://gist.github.com/zonque/10b7b718 ... 1cb31b6133 for RBPi 2b 32-bit? I was trying to set up build env on macOS all day with without luck. Thank you!

GilGill
Posts: 4
Joined: Mon Jul 06, 2020 12:50 pm

Re: Please help with compiling simple code

Thu Apr 08, 2021 1:52 am

Not sure of the level of your understanding/knowledge of compilers/linkers, but the code file you have - dmx-udp.c - has a number of header files that are not part of the standard Raspberry install. You'll need to get those dependencies sorted out before you can compile.
The header files contain variable definitions and function declarations that do most of the work in the program.
Your job is to be sure that all of the header files and their attendant libraries are installed correctly on the machine you are using for building the code.
Once you have the header files and libraries installed correctly, you should be able to open a terminal in the same directory as your source file (in this case, dmx-udp.c), and run the compile line exactly as the file lists it:
gcc -o dmx-udp dmx-udp.c $(pkg-config --cflags --libs libftdi1) -Wall
Be sure you have gcc installed on your computer or that line won't work.
Here are the header files you'll need to find/install:
#include <assert.h>
#include <arpa/inet.h>
#include <ftdi.h>
#include <netinet/in.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
Remember that 'C' and 'C++' are not like Python or Java; both 'C'/'C++' are compiled and linked into standalone binaries.
What is the make/model of the Raspberry Pi you are using as your build machine? Is it the same machine that you will be running the binary on?
A couple of tips for building 'C' and 'C++' on a Raspberry Pi:
Install devhelp, and add the "cppreference doc" help module.
Install "locate" on your Raspberry Pi and get used to running it regularly so you can quickly find any file on your computer. (Note: any network drive(s) that is/are attached will be indexed, too. Which can take a few minutes.)

Heater
Posts: 17832
Joined: Tue Jul 17, 2012 3:02 pm

Re: Please help with compiling simple code

Thu Apr 08, 2021 2:30 am

All of the header files listed above are standard C, out of the box for a Pi, header files. Except ftdi.h which is special for the FTDI USB devices.

On a Pi you can get the ftdi.h header file by installing the FTDI development package:

Code: Select all

$ sudo apt-get install libftdi-dev
Then that code compiles, on a Pi, with the following:

Code: Select all

$ gcc -o dmx-udp dmx-udp.c  -Wall -lftdi 
I did not get the build command shown in the source itself to work.

Sorry, I have no advice for cross-compiling on a Mac.
Memory in C++ is a leaky abstraction .

Return to “C/C++”