Linux下Qt For ARM开发环境

OS: ubuntu 12.1 gcc: 4.6.3 arm gcc: 4.5.1 QT: qt-x11-opensource-src-4.5.3 QT-embedded: qt-embedded-linux-opensource-src-4.5.3

编译qt-x11-opensource-src-4.5.3

./configure –qvfb
make
cd tools/qvfb //进入此目录,准备对它进行编译
make
sudo  make install

编译过程中出现的错误: error: ‘ppd_file_t’ does not name a type 解决方法: 打开src/gui/painting/qcups_p.h做如下修改:

#ifndef QT_NO_CUPS
#include    //加入ppd头文件
QT_BEGIN_NAMESPACE

安装 arm-linux-gcc

(略)

编译qt-embedded-linux-opensource-src-4.5.3

./configure   -embedded  arm -qt-libpng
make
sudo   make install

编译时间会很长,可以使用下面的配置来减少编译时间:

./configure -embedded  arm -qt-libpng \
-release \
-shared \
-fast \
-no-largefile \
-qt-sql-sqlite \
-no-qt3support \
-no-xmlpatterns \
-no-mmx \
-no-3dnow \
-no-sse \
-no-sse2 \
-no-svg \
-no-webkit \
-qt-zlib \
-qt-gif \
-qt-libtiff \
-qt-libpng \
-qt-libmng \
-qt-libjpeg \
-make libs \
-xplatform qws/linux-arm-g++ \
-nomake tools \
-nomake examples \
-nomake docs \
-nomake demo \
-no-nis \
-no-cups \
-no-iconv \
-no-dbus \
-no-openssl \
-embedded arm \
-little-endian \
-qt-freetype \
-depths 16,18 \
-qt-gfx-linuxfb \
-no-gfx-transformed \
-no-gfx-multiscreen \
-no-gfx-vnc \
-no-gfx-qvfb \
-qt-kbd-usb \
-no-glib

Ubuntu下设置FTP

OS: ubuntu 12.04

安装vsftpd

apt-get install vsftpd

编辑 /etc/vsftpd.conf

listen=YES
#anonymous_enable=YES
local_enable=YES
write_enable=YES
#anon_upload_enable=YES

anonymous_enable=NO  #默认是允许
dirmessage_enable=YES  # 允许进入文件夹
xferlog_enable=YES   # 允许 ftp 日志记录允许
connect_from_port_20=YES     # 允许使用20号端口作为数据传送端口
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/private/vsftpd.pem

设置ftp文件夹

mkdir -p /home/ftp/upload
mkdir -p /home/ftp/download
chmod 755 /home/ftp
chmod 777 /home/ftp/upload
chmod 755 /home/ftp/download

设置ftp用户

  • 增加ftp组:groupadd ftpgroup

  • 编辑 /etc/vsftpd.conf:

    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd.chroot_list
    
  • 增加ftp用户: useradd -g ftpgroup -d /home/ftp -M upload ftpuser

  • 设置ftp用户密码: passwd ftpuser

  • 编辑 /etc/vsftpd.chroot_list:

    ftpuser
    
  • 重启vsftp服务: service vsftpd restart

ARM平台下iptables编译

target: arm device: FriendlyARM tiny210

./configure  --prefix=/home/iptables-arm  
                 --host=arm-linux 
                 --with kernel=/opt/FriendlyARM/tiny210/linux/linux-2.6.35.7/
make
make install

Ubuntu 下编译 qtopia

qtopia: 2.2.0 OS: ubuntu 12.1

安装必要软件

sudo apt-get -y install x-dev libx11-dev x11proto-xext-dev  libxext-dev libqt3-mt-dev uuid uuid-dev 
sudo apt-get install libv4l-dev

遇到的问题

问题1
安装libv4l-dev后还是会提示缺少 linux/videodev.h

解决
原因是 3.2.0 已经移除了对 v4l1 的支持,可以在linux/目录下建立软链接:
 ln -s /usr/include/lib4l1.h        /usr/include/linux/videodev.h
问题2
error: ‘ptrdiff_t’ does not name a type

解决
这个错误应该是libc的版本造成的,解决的方法是在每个报错的头文件中加入
 include  <stddef>
问题3
undefined reference to `uuid_generate'

解决
 git  clone  git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git  或者网络下载e2fsprogs源码包
 编译e2fsprogs:
./configure --enable-elf-shlibs
sudo cp -av libuuid.so*        /usr/lib

接下来正常编译qtopia,Done !

Linux C获取系统网卡信息

OS:ubuntu 12.04

int getNetCardCount()
{
    int nCount = 0;
    FILE *file = fopen("/proc/net/dev", "r");
    if(!file)
    {   
        debug("Open /proc/net/dev failed by %s !\n", strerror(errno));
        return nCount;
    }   

    char szLine[512];
    fgets(szLine, sizeof(szLine), file);
    fgets(szLine, sizeof(szLine), file);

    while(fgets(szLine, sizeof(szLine), file))
    {   
        char szName[128] = {0};
        sscanf(szLine, "%s", szName);
        int nLen = strlen(szName);
        if(nLen <= 0)
            continue;
        if(szName[nLen - 1] == ':')
            szName[nLen - 1] = 0;
        if(strcmp(szName, "lo") == 0)
            continue;
        nCount++;
    }   

    fclose(file);
    file = NULL;
    return nCount;
}

void dispNetInfo(const char *szDevName, struct netCardInfo *netCardInfo)
{
    int s = socket(AF_INET, SOCK_DGRAM, 0);
    if(s < 0)
    {
        debug("Create socket failed by %s!\n", strerror(errno));
        return;
    }
    struct ifreq ifr;
    unsigned char mac[6];
    unsigned long nIP, nNetmask, nBroadIP;

    strcpy(netCardInfo->devName, szDevName);
    printf("%s\n", szDevName);

    strcpy(ifr.ifr_name, szDevName);
    if(ioctl(s, SIOCGIFHWADDR, &ifr) < 0)
    {
        return;
    }
    memcpy(netCardInfo->mac, ifr.ifr_hwaddr.sa_data, sizeof(mac));
    //fprintf(stderr, "\tMAC:%02x-%02x-%02x-%02x-%02x-%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

    strcpy(ifr.ifr_name, szDevName);
    if(ioctl(s, SIOCGIFADDR, &ifr) < 0)
        nIP = 0;
    else
        nIP = *(unsigned long*)&ifr.ifr_broadaddr.sa_data[2];

    strcpy(netCardInfo->IP,  inet_ntoa(*(struct in_addr*)&nIP));

    //fprintf(stderr, "\tIP:%s\n", inet_ntoa(*(struct in_addr*)&nIP));

    strcpy(ifr.ifr_name, szDevName);
    if(ioctl(s, SIOCGIFBRDADDR, &ifr) < 0)
        nBroadIP = 0;
    else
        nBroadIP = *(unsigned long*)&ifr.ifr_broadaddr.sa_data[2];
    strcpy(netCardInfo->broadIp, inet_ntoa(*(struct in_addr*)&nBroadIP));
    //fprintf(stderr, "\tBroadIP:%s\n", inet_ntoa(*(struct in_addr*)&nBroadIP));

   strcpy(ifr.ifr_name, szDevName);
    if(ioctl(s, SIOCGIFNETMASK, &ifr) < 0)
        nNetmask = 0;
    else
        nNetmask = *(unsigned long*)&ifr.ifr_netmask.sa_data[2];
    strcpy(netCardInfo->netMask, inet_ntoa(*(struct in_addr*)&nNetmask));
    //fprintf(stderr, "\tNetmask:%s\n", inet_ntoa(*(struct in_addr*)&nNetmask));

    strcpy(ifr.ifr_name, szDevName);
    if(ioctl(s, SIOCGIFMTU, &ifr) < 0)
        netCardInfo->mtu = 0;
    else
        netCardInfo->mtu = ifr.ifr_mtu;
        //fprintf(stderr, "\tMTU:%d", ifr.ifr_mtu);

    close(s);
}

void dispActiveAdap(struct netInfo *netInfo)
{
    int fd;
    int count;
    struct ifconf ifc;
    struct ifreq ifr[512];

    if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        debug("socket error by %s\n", strerror(errno));
        return;
    }
    bzero(&ifc, sizeof(ifc));
    bzero(ifr, sizeof(ifr));
    ifc.ifc_len = sizeof(ifr);
    ifc.ifc_req = ifr;
    if(ioctl(fd, SIOCGIFCONF, &ifc) < 0)
    {
        debug("ioctl error by %s\n", strerror(errno));
        return;
    }
    count = ifc.ifc_len / sizeof(struct ifreq);
    int i;
    for(i = 0; i < count; i++)
    {
        struct ifreq *req = &ifr[i];
        if ((strcmp(req->ifr_name, "lo") != 0))
        {
            dispNetInfo(req->ifr_name, &(netInfo->cardInfo[i]));
        }
    }
    close(fd);
    return ;
}

void getDNS(struct netInfo *netInfo)
{
    int i;
    if(res_init() < 0)
    {
        debug("res_init error by %s\n", strerror(errno));
        return;
    }
    for(i = 0; i < _res.nscount; i++)
    {
        struct sockaddr *server = (struct sockaddr*)&_res.nsaddr_list[i];
        strcpy(netInfo->dns[i], inet_ntoa(*(struct in_addr*)&(server->sa_data[2])));
        //fprintf(stderr, "DNS%d:%s\n",i+1, inet_ntoa(*(struct in_addr*)&(server->sa_data[2])));
    }
}