Go Down

Topic: Example of Native GCC for Yun (Read 13950 times) previous topic - next topic


@sonnyyu- you mark the grep download as for testing

Download latest Grep here For testing purpose only
What is the reason? Why is it not for general use?


I don't recall what stopped me to compile grep by Native GCC for Yun, but the link of package is cross compile.  I guess every one find it working then for general use.


To complete example, here is hello world C example.

Code: [Select]
nano hello.c

Code: [Select]

//C hello world example
#include <stdio.h>
int main()
  printf("Hello world\n");
  return 0;

Code: [Select]
gcc -Wall hello.c -o hello


Code: [Select]
Hello world


These are great examples, thank you! Between these and noblepepper's blog on the subject, I had no problems getting things going (once I got over my hesitation and actually tried!)

What's missing from these examples is accessing the Yun's bridge from C or C++. Is it possible to get/put bridge values or access the bridge mailbox mechanism from C or C++? (lots of Python and PHP examples, but I can't find any in C.)


Dec 16, 2014, 04:56 am Last Edit: Dec 16, 2014, 04:57 am by sonnyyu
Since UART's speed is only 0.5Mb/s and will be bottleneck, compiled programming languages assembly/c/c++ has no  advantage than script languages php/python/lua.
UART is interface between Yun and Arduino.

Profile bridge speed:

Arduino Yun Bridge example from IDE.

ab - Apache HTTP server benchmarking tool


Code: [Select]
ab -n 20 -c 1

Concurrency Level:      1
Time taken for tests:   3.425 seconds
Complete requests:      20
Failed requests:        0
Write errors:           0
Non-2xx responses:      20
Total transferred:      2100 bytes
HTML transferred:       0 bytes
Requests per second:    5.84 [#/sec] (mean)
Time per request:       171.275 [ms] (mean)
Time per request:       171.275 [ms] (mean, across all concurrent requests)
Transfer rate:          0.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   164  171   7.9    169     192
Waiting:      153  159   6.2    156     171
Total:        164  171   7.9    169     192

171.275 [ms] (0.17 s) is average speed of bridge speed, and should meet average application's requirement.

0.17 samples/s  and  0.5Mb/s make  compiled programming languages assembly/c/c++ is not good candidates.


Dec 16, 2014, 08:19 am Last Edit: Dec 16, 2014, 03:11 pm by ShapeShifter
0.17 samples/s  and  0.5Mb/s make  compiled programming languages assembly/c/c++ is not good candidates.
Understood that the bridge is a bottleneck, and the increased speed of C over Python is not necessarily an advantage. But that doesn't mean that there is no place for C or C++. Perhaps there are other things that must be done at a high speed, and the Bridge portion of it is a minor percentage. Or an existing application is being ported to the Yun, and rewriting it in Python is a large effort. Or the code uses a library with a C interface that is not available (or too cumbersome) to use in Python. Or the coder is just more comfortable with C and would prefer using it. Or...

There are many valid reasons for wanting to use C or C++ that go beyond speed.

Edit: I recently posted the same basic question in another thread, where I stated that I had a C application that needed to post to the Bridge mailbox, and which wasn't practical to rewrite in Python. After spending way too much time researching libraries and rewriting code, I was able to get it working in Python, but it would've been a much more elegant solution if it stayed in C. And the next project might be much more work to translate, just to get around the lack of a C Bridge interface.



Jan 12, 2015, 07:51 am Last Edit: Feb 18, 2015, 10:12 pm by sonnyyu
SQLite3 compilation:

Install libsqlite3-dev file

Code: [Select]
cd /usr/lib/
wget -O  libsqlite3.a https://www.dropbox.com/s/bdbtxyhpbkor2zi/libsqlite3.a?dl=0 --no-check-certificate

Code: [Select]
cd /usr/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/include/
wget -O sqlite3.h https://www.dropbox.com/s/naatzfv04x5e63h/sqlite3.h?dl=0  --no-check-certificate

Install libsqlite3 and userspace file

Code: [Select]
opkg update
opkg install sqlite3-cli
opkg install libsqlite3

Code: [Select]
nano /mnt/sda1/opendb.c

Code: [Select]
#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>

int main(int argc, char* argv[])
   sqlite3 *db;
   char *zErrMsg = 0;
   int rc;

   rc = sqlite3_open("test.db", &db);

   if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      fprintf(stderr, "Opened database successfully\n");

Code: [Select]
cd /mnt/sda1
gcc -o opendb opendb.c -lsqlite3 -ldl -lpthread

Code: [Select]
root@Arduino:/mnt/sda1# ./opendb
Opened database successfully



Jan 21, 2015, 01:53 am Last Edit: Jan 21, 2015, 06:10 am by sonnyyu
Reset USB compilation:

Code: [Select]
nano  /mnt/sda1/usbreset3.c

Code: [Select]
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>

int main(int argc, char **argv)
const char *filename;
int fd;
int rc;

if (argc != 2) {
fprintf(stderr, "Usage: usbreset device-filename\n");
return 1;
filename = argv[1];

fd = open(filename, O_WRONLY);
if (fd < 0) {
perror("Error opening output file");
return 1;

printf("Resetting USB device %s\n", filename);
rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0) {
perror("Error in ioctl");
return 1;
printf("Reset successful\n");

return 0;

Code from:


Code: [Select]
gcc -o usbreset3  /mnt/sda1/usbreset3.c

Code: [Select]
root@Arduino:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 058f:6254 Alcor Micro Corp. USB Hub
Bus 001 Device 003: ID 0424:2507 Standard Microsystems Corp. hub
Bus 001 Device 004: ID 058f:6366 Alcor Micro Corp. Multi Flash Reader
Bus 001 Device 005: ID 046d:0829 Logitech, Inc.

reset Logitech camera:

Code: [Select]
root@Arduino:~# /mnt/sda1/usbreset3 /dev/bus/usb/001/005
Resetting USB device /dev/bus/usb/001/005
Reset successful

If reset root hub will crash machine!

Download pre-compile usbreset3:

Code: [Select]
wget -O usbreset3 https://www.dropbox.com/s/xlnkut2jpcy7evj/usbreset3?dl=0 --no-check-certificate

Code: [Select]
chmod 755 usbreset3


Nov 21, 2019, 10:39 am Last Edit: Nov 21, 2019, 02:26 pm by e2sence Reason: correction
Install driver, library, application for Yun.

The freetds-dev  is open source library for Sybase  and Microsoft SQL server.

Code: [Select]
wget ftp://ftp.freetds.org/pub/freetds/current/freetds-dev.0.92.812.tar.gz
tar -zxvf freetds-dev.0.92.812.tar.gz

Code: [Select]
cd  freetds-dev.0.92.812

Code: [Select]
make install

Here you need take very long coffee break at stage "make"!

Testing connect to MS SQL Server

Code: [Select]
tsql -H192.168.0.111 -p 1433  -U sa -P password
locale is "C"
locale charset is "ASCII"
using default charset "ISO-8859-1"
1> use AdventureWorks2008
2> go
1> SELECT * FROM Person.Address where AddressID=1
2> go
AddressID       AddressLine1    AddressLine2    City    StateProvinceID PostalCode      SpatialLocation rowguid ModifiedDate
1       1970 Napa Ct.   NULL    Bothell 79      98011   e6100000010cae8bfc28bce4474067a89189898a5ec0    9AADCB0D-36CF-483F-84D8-585C2D4EC6E9    Jan  4 1998 12:00:00:000AM
(1 row affected)

Now Yun is able to directly talk to Sybase  and Microsoft SQL server.

Community help please, I need step-by-step instructions for installing current FREETDS version on Yun2

Go Up