How do I include a .h and .c in my project

Sysprogs forums Forums VisualGDB How do I include a .h and .c in my project

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #600
    theColonel26
    Participant

    I am trying to use the PiFace C library but I get these error when I build

    [attachment=0:33qxjdp3]2013-07-05 09 20 23.png[/attachment:33qxjdp3]

    
    #include 
    #include "pfio.h"

    using namespace std;

    class Inputs
    {
    public:
    bool I [8];

    Inputs()
    {
    //* constructor
    }

    void get()
    {
    for(int i = 0; i < 8; i++)
    {
    I = pfio_digital_read(i);
    }
    }

    };


    class Outputs
    {
    public:
    bool O [8];

    Outputs()
    {
    //* constructor
    }

    void set()
    {
    for(int i = 0; i < 8; i++)
    {
    pfio_digital_write(i, O
    );
    }
    }

    };


    int main(int argc, char *argv[])
    {
    pfio_init();
    Inputs in;
    Outputs out;

    cout << "welcome" << endl;

    bool run = true;
    while (run)
    {
    in.get();
    if(in.I[0])
    {
    cout << "Btn 0 Pressed" << endl;
    if (out.O[0])
    {
    out.O[0] = false;
    }else
    {
    out.O[0] = true;
    }
    }


    if (out.O[4]){
    run == false;
    cout << "Btn 4 Pressed" << endl;
    }
    out.set();
    }//** end while
    cout << "End Run Loop" << endl;

    pfio_deinit();

    cout << "Press Any Key to Exit" << endl;
    getwchar();
    return 0;
    }
    #2503
    ket
    Participant

    Hi,

    The undefined reference errors indicate that the linker does not know about the PiFace library. Add the library names in the flags.mak LIBRARY_NAMES variable. The library names should be separated by spaces and not include the lib prefix or the .so or .a suffixes (in this case probably just piface or piface-1.0).

    As you are using the cross-compiler, the cross-toolchain probably does not include the PiFace library. You need to copy the library and its includes into the sysroot directory of the cross-toolchain from the Rasperry PI if you have not done so already.

    The IntelliSense warnings look harmless in this case, it is only picking up some c code differences between Linux and Windows.

    #2505
    theColonel26
    Participant

    but shouldn’t it compile if I just added the .h and .c into my project? Intelisense has no problem finding them when I do that, but when I compile it can’t find them.

    it’s just one c file and a header I think it’s just easier to add the source files to my project, but that doesn’t even work.

    also where should I put the library files and includes in sysroot? in that directory or one of the it’s sub-dirs? I’ve never worked with library in C or C++ before. so I have no idea what I am doing in regards to those.

    #2506
    ket
    Participant

    Hi,

    Adding header and source files to the project should usually work if you are adding the files into the project directory. If you add existing files from outside the project directory, then you need to include the include directory in the mak file as otherwise make will not find the header. The source file list is updated automatically in the Makefile. IntelliSense is a Visual Studio feature and works separately from the build system.

    The sysroot directory is like the root directory on Raspberry. So, everything there should be placed as it is on the Raspberry e.g. the /usr/include directory should be inside sysroot as C:SysGCCraspberryarm-linux-gnueabihfsysrootusrinclude. In the VisualGDB version 4.0 there is even a way to automatically copy these directories over: In the VisualGDB Project Properties on the Makefile settings page there is button ‘Synchronize sysroot’ next to the toolchain selection. It can copy over the selected directories automatically.

    #2507
    theColonel26
    Participant

    yeah I copied them in to my project folder and then added them as existing items in VS. Intellisense seed them and removes all the red syntax error stuff, but when I try to compile I get the same error.

    As for adding them in the sysroot. The library files were added to /usr/local/* there seems to be duplicate of all the gcc libraries one in /usr/* and then again in the sub dir ./local/

    what is you best advice for handling that?

    #2508
    theColonel26
    Participant

    I Installed 4.0 beta 2 but I don’t see that page in the project properties

    #2509
    ket
    Participant

    Hi,

    The generated makefiles were changed with version 4.0. You will not see the Makefile settings page unless you are using version 4.0 generated makefiles. On the project settings page change the build subsystem to ‘GNU Make’ and generate a new makefile. Then the Makefile settings page will appear. You can of course just make a new project as well.

    #2504
    theColonel26
    Participant

    Alright cool I’ll try that tomorrow at work.

    #2495
    theColonel26
    Participant

    ok I did that, synced my sysroot, and I’m still getting the same errors.

    I can compile using that library just fine on the pi if I do

    gcc -L/user/local/lib/ -lpiface-1.0 -o blah2 ./blah2.c

    but I can’t remote build or cross-compile with VisualGDB.

    I can compile with VisualGDB if I comment out those lines that use that library though

    #2497
    theColonel26
    Participant

    You’re not really making a good case for why I should buy your software when I have to wait all day for a reply. This is starting to get ridiculous I have wasted days of my time on this issue. it’s just a very simple library why is this so difficult to compile.

    not trying to be a jerk, I’m just getting frustrated.

    #2498
    ket
    Participant

    Hi,

    What have you specified in the debug.mak for the libraries? The problem occurs because the library is either not specified or not found. Based on your command line it should contain “LIBRARY_NAMES := piface-1.0”. You can also try to specify the library location in sysroot in the LIBRARY_DIRS variable. Also make sure the library actually exists in sysrootusrlocallib.

    #2499
    theColonel26
    Participant

    [attachment=0:3h8cc75a]2013-07-11 15 06 43.png[/attachment:3h8cc75a]
    [attachment=2:3h8cc75a]2013-07-11 15 06 05.png[/attachment:3h8cc75a]
    [attachment=1:3h8cc75a]2013-07-11 15 06 19.png[/attachment:3h8cc75a]

    #2500
    ket
    Participant

    Hi,

    That looks fine. You could try to use an absolute path for the library, but if the library would not be found the build output would state that.
    Are you using ‘extern “C” { }’ around the piface include statements in your code?

    #2501
    theColonel26
    Participant

    here is my code it’s a C++ project as opposed to a C project. Should still work right?

    
    #include 
    #include

    using namespace std;

    int main(int argc, char *argv[])
    {
    pfio_init();
    pfio_digital_write(0, 1);
    pfio_deinit();

    return 0;
    }
    #2502
    theColonel26
    Participant

    I fail I needed a extern “C” {};

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.