C ++代码和带有.cpp文件的bcm2835

时间:2015-05-06 07:06:20

标签: c++

您好我正在使用带有代码的raspberry pi 2直接从Microsoft visual c ++ 2010中取出,我试图将它与bcm2835一起用于GPIO的输出但是我在编译和构建之后得到了

/tmp/ccGucgzr.o: In function `main':
Geany2.cpp:(.text+0x14): undefined reference to `bcm2835_init'
Geany2.cpp:(.text+0x3c): undefined reference to `bcm2835_gpio_fsel'
Geany2.cpp:(.text+0x48): undefined reference to `bcm2835_gpio_delayMicroseconds'
Geany2.cpp:(.text+0x50): undefined reference to `bcm2835_write'
Geany2.cpp:(.text+0x5c): undefined reference to `bcm2835_gpio_delayMicroseconds'
Geany2.cpp:(.text+0x64): undefined reference to `bcm2835_write'
Geany2.cpp:(.text+0x64): undefined reference to `bcm2835_close
Compliation failed
collect2: ld returned 1 exit status

当我在LX终端编译和构建它时,这是不同的,因为我没有错误,但是当我这样做g ++ -o Geany2 Geany2.cpp -l bcm2835并且我正在使用的引脚时代码似乎不起作用下面没有看到的是我的代码副本。

#include <iostream>
#include <ostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "stdint.h"
#include "bcm2835.h"

#define MODE_READ 0
#define MODE_SET 1
#define MODE_CLR 2
#define MODE_INPUT_READ 3
#define PULL_UP 0
#define PULL_DOWN 1
#define NO_PULL 2
#define GPIO_BEGIN 0
#define GPIO_END 1
#define NO_ACTION 2
#define NO_PIN 40 
// Some big number that's beyond the connector's pin count
#define DEBUG_OFF 0
#define DEBUG_ON 1
#define PIN RPI_GPIO_P1_11
int main (int argc, char **argv)
{
    std::vector<int> d1,d2;
    int e,f,i=1,lines;
    std::ifstream read("Design2 - Drill Data.txt");
    while(read>>e>>f)
    {
        d1.push_back(e);
        d2.push_back(f);
        i++;
    }
    lines=d1.size();
    float X1;
    float Y1;
    float X2;
    float Y2;
    int trackx;
    int tracky;
    float CordinateX;
    float CordinateY;
    trackx = 1;
    tracky = 1;
    //std::cout << d1[trackx] << '\n';
    //std::cout << d2[tracky] << '\n';
    X1 = d1[trackx - 1];
    Y1 = d2[tracky - 1];
    std::cout << X1 << '\n';
    //std::cout << Y1 << '\n';
    if (!bcm2835_init()) return 1;
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
    if (X1 > 0)
    {
        //X1 = X1/1000;
        //X1 = X1*25.4;
        std::cout << X1 << '\n';
        //float CordinateX;
        //commands for x raspberry pi
        float temp1;
        temp1 = X1;
        while (temp1 >= 0)
        {
            bcm2835_delayMicroseconds(100);
            bcm2835_gpio_write(PIN, HIGH);
            bcm2835_delayMicroseconds(10);
            bcm2835_gpio_write(PIN, LOW);
            temp1 = temp1 - 1;
            std::cout << temp1 << '\n';
        }
    }
    if (Y1 > 0)
    {
        Y1 = Y1/1000;
        Y1 = Y1*25.4;
        //std::cout << Y1 << '\n';
        //float cordinatey;
        //commands for y raspberry pi
    }
    trackx = -1;
    tracky = -1;
    while (1)
    {
    while (trackx > 0 && tracky > 0)
    {
        float actualX;
        float actualY;
   //*********************************
    X1 = d1[trackx - 1];
        //X1 = X1/1000;
        //X1 = X1*25.4;
        std::cout << X1 << '\n';
   //*********************************
        Y1 = d2[tracky - 1];
        //Y1 = Y1/1000;
        //Y1 = Y1*25.4;
        std::cout << Y1 << '\n';
   //*********************************
        X2 = d1[trackx];
        //X2 = X2/1000;
        //X2 = X2*25.4;
        std::cout << X2 << '\n';
   //*********************************
        Y2 = d2[tracky];
        //Y2 = Y2/1000;
        //Y2 = Y2*25.4;
        std::cout << Y2 << '\n';
   //*********************************
        if (X2 > X1)
        {
            actualX = X2 - X1;
            //float CordinateX;
            CordinateX = /*X1+*/actualX;
    // if starting from 0,0 if not just pulse out actualx
            std::cout << CordinateX << '\n';
        }
        if (X1 > X2)
        {
            actualX = X1 - X2;
            //float CordinateX;
            CordinateX = /*X1-*/actualX;
    // if starting from 0,0 if not just pulse out actualx
            std::cout << -CordinateX << '\n';
        }
   if (X1 == X2)
        {
                    actualX = X2 - X1;
            //float CordinateX;
            CordinateX = actualX;
            std::cout << CordinateX << '\n';
        }
//*********************************
if (Y1 < Y2)
{
    actualY = Y2 - Y1;
    //float CordinateY;
    CordinateY = /*Y1+*/actualY;
    // if starting from 0,0 if not just pulse out actualx
    std::cout << CordinateY << '\n';
}   
if (Y1 > Y2)
{
    actualY = Y1 - Y2;
    //float CordinateY;
    CordinateY = /*Y1-*/actualY;
    // if starting from 0,0 if not just pulse out actualx
    std::cout << -CordinateY << '\n';
}
if (Y1 == Y2)
{
    actualY = Y2 - Y1;
    //float CordinateY;
    CordinateY = actualY;
    std::cout << CordinateY << '\n';
}
system("PAUSE");
trackx = trackx + 1;
tracky = tracky + 1;
if (d1[trackx - 1] == 0)
{
    return 0;
}
}
bcm2835_close();
}   //system("PAUSE");
return 0;
}

0 个答案:

没有答案