如何运行这个C代码 [英] how to run this C code

查看:108
本文介绍了如何运行这个C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我破坏了代码时,为mqueue.h输出了一个错误我该如何运行这个程序

  #include  <跨度类= 代码预处理器> <跨度类= 代码关键字><  <跨度类= 代码leadattribute> stdlib.h中 <跨度类= code-keyword>>  
#include < stdio.h >
#include < string.h >
#include < sys / stat.h >
#include < sys / types.h >
#include < <跨度类= 代码leadattribute > mqueue.h <跨度类= 代码关键字>>
#include < unistd.h >

#include ../../ src / UUGear.h

int main( int argc , char ** argv)
{
setupUUGear();

setShowLogs( 1 );

UUGearDevice dev的= attachUUGearDevice(<跨度类= 代码串> <跨度类= 代码串 > UUGear-Arduino的7853-2668 );

if (dev.fd!= - 1
{
int pin = 3 ; // 模拟输入引脚3

int i, value ;
float 电压;
for (i = 0 ; i< 100 ; i ++){
value = analogRead(& dev,pin);

voltage =( float )( value * 5 )/ 1024 ;

printf( %。2fV \ n,电压);

usleep( 200000 );
}

detachUUGearDevice(& dev);
}
else
{
printf( 无法打开UUGear设备。\ n);
}

cleanupUUGear();

return 0 ;
}

解决方案

返回到获取代码的位置,并查找所需的头文件和库文件work:看起来你刚刚抓了一些代码并希望它能单独工作。



mqueue.h是一个头文件,可能是一个必需的库。
看起来就像你从这里代码: https://github.com/shawnu/UUGear [ ^ ]



如果是这样,代码应该在运行某些Linux发行版的Raspberry PI上运行。如果你在其他操作系统或平台上试用它可能无法正常工作。



如果你实际上试图在Raspberry PI上运行它Linux,它仍然不起作用,那么也许你错过了一个包含路径。在这种情况下,搜索文件并将文件位置添加到包含路径。



否则您可以尝试联系作者:他在主页上留下了链接上面张贴的网站底部。


When i runthis code igot an error for mqueue.h how can i run this program

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <mqueue.h>
#include <unistd.h>

#include "../../src/UUGear.h"

int main(int argc, char **argv)
{
    setupUUGear();

    setShowLogs(1);

    UUGearDevice dev = attachUUGearDevice ("UUGear-Arduino-7853-2668");

    if (dev.fd != -1)
    {
        int pin = 3;    // analog input pin 3

        int i, value;
        float voltage;
        for (i = 0; i < 100; i ++) {
            value = analogRead(&dev, pin);

            voltage = (float)(value * 5) / 1024;

            printf("%.2fV\n", voltage);

            usleep(200000);
        }

        detachUUGearDevice (&dev);
    }
    else
    {
        printf("Can not open UUGear device.\n");
    }

    cleanupUUGear();

    return 0;
}

解决方案

Go back to where you got the code from, and look for the headers and library files it need to work: it looks like you have just grabbed a bit of code and expect it to work in isolation.

mqueue.h is a header file, probably for a required library.


Looks like you got that code from here: https://github.com/shawnu/UUGear[^]

If so, the code is supposed to run on a Raspberry PI sporting some Linux distro. If you're trying it on some other OS or platform it probably won't work.

If you are in fact trying to make this run on a Raspberry PI using Linux, and it still doesn't work, then maybe you're missing an include path. In that case search the file and add the file location to your include path.

Otherwise you can try and contact the author: he left a link to his homepage at the bottom of the site posted above.


这篇关于如何运行这个C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆