Thread: Please help with compiling a program

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    4

    Please help with compiling a program

    Hi,

    I am totally new to C. I want to run serial commands from a Bealgebone to a 4Dsystems display. Therefore I copied the c library found here:

    https://github.com/4dsystems/Picaso-Serial-C-Library

    into a directory and created a test program main.c:

    Code:
    #include"Picaso_const4D.h" 
    #include"Picaso_Serial_4DLibrary.h"
    
    int main(int argc,char*argv[])
    {
        OpenComm("/dev/ttyUSB0", B115200);// Matches with the display "Comms" rate
        gfx_BGcolour(0xFFFF);
        gfx_Cls();
        gfx_CircleFilled(120,160,80,BLUE);
        while(1){}
    }
    Now when I do
    Code:
    gcc -o main main.c
    its says
    main.c:2:37: fatal error: Picaso_Serial_4DLibrary.h: No such file or directory
    So I try linking it:
    Code:
    gcc main.c  -L.-lPICASO_SERIAL_4DLIBRARY
    which gives me the same error. Then I tried to create a static library:
    Code:
    gcc -Wall-g -c -o PICASO_SERIAL_4DLIBRARY PICASO_SERIAL_4DLIBRARY.C
    which gives me this:
    PICASO_SERIAL_4DLIBRARY.C:1:21: fatal error: windows.h: No such file or directory compilation terminated.

    Same error message when I include

    Code:
    gcc main.c -Wall-L.-lPICASO_SERIAL_4DLIBRARY
    -I/path/to/4Dsystems/C/Include
    What am I doing wrong? the git page clearly says this library is created for people who do not run windows.
    Thanks in advance!
    Last edited by Baxter Stockman; 10-17-2015 at 08:17 PM.

  2. #2
    Guest
    Guest
    You first need to compile the source code into a library (object file). It also looks to me like it's written with Windows in mind, so you'd have to modify the code a little first (which I would assume is beyond you right now). I just did a web search and found a little tutorial on getting started with GCC compilation. Consider giving that a look; GCC can be picky about the order of the arguments you give it and details like that.
    Last edited by Guest; 10-17-2015 at 09:24 PM.

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    First of all thank you so much! I'm really frustrated 'cause I'm stuck for hours now.

    Quote Originally Posted by Guest View Post
    You first need to compile the source code into a library (object file).
    Ok, what does that mean? compile into a library, how do I do that?


    Thanks for the link, does that mean I have to compile it with Windows?

    Thank you so much, that definitely helps a lot !

  4. #4
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    Ok I think I found out what you mean. Like create a shared library?

    I followed these steps here

    Shared libraries with GCC on Linux - Cprogramming.com

    however right after the first compile

    Code:
    gcc -c -Wall -Werror -fpic PICASO_SERIAL_4DLIBRARY.C
    I get this

    PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is pos
    tion independent) [-Werror]
    #include <windows.h>
    ^
    cc1plus.exe: all warnings being treated as errors

    I tried finding the problem but couldn't, since I use windows now I don't now why this happens?
    Last edited by Baxter Stockman; 10-18-2015 at 12:53 AM.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you're not being helped by the fact that filenames are case sensitive, and all the files in the repository are in upper case.

    Code:
    $ find C -type f
    C/Samples/BIGDEMO.PRJ
    C/Samples/BIGDEMO.H
    C/Samples/LCC/BIGDEMO.EXE
    C/Samples/BIGDEMO.C
    C/Lib/PICASO_SERIAL_4DLIBRARY.C
    C/Lib/PICASO_SERIAL_4DLIBRARY.H
    C/Lib/PICASO_SERIAL_4DLIBRARY.PRJ
    C/Include/PICASO_CONST4D.H
    C/Include/PICASO_COMPOUND4DROUTINES.INC
    C/Include/PICASO_TYPES4D.H
    C/Include/PICASO_CONST4DSERIAL.H
    C/Include/PICASO_SERIAL_4DLIBRARY.~H
    C/Include/PICASO_SERIAL_4DLIBRARY.H
    C/Include/PICASO_INTRINSIC4DROUTINES.INC
    
    $ cat main.c
    #include"PICASO_CONST4D.H" 
    #include"PICASO_SERIAL_4DLIBRARY.H"
    
    int main(int argc,char*argv[])
    {
        OpenComm("/dev/ttyUSB0", B115200);// Matches with the display "Comms" rate
        gfx_BGcolour(0xFFFF);
        gfx_Cls();
        gfx_CircleFilled(120,160,80,BLUE);
        while(1){}
    }
    
    $ gcc -c -IC/Include main.c
    In file included from main.c:2:0:
    C/Include/PICASO_SERIAL_4DLIBRARY.H:1:76: fatal error: Picaso_Types4D.h: No such file or directory
    compilation terminated.
    
    $ head C/Include/PICASO_SERIAL_4DLIBRARY.H
    #include "Picaso_Types4D.h"			// defines data types used by the 4D Routines
    
    // SPE Version 1.2 added peekM and pokeM
    // SPE Version 1.1 added bus_ and pin_ functions
    
    #define   Err4D_OK      0
    #define   Err4D_Timeout 1
    #define   Err4D_NAK		2 // other than ACK received
    The library itself can't get it's own naming correct.

    There aren't that many files, so you might consider just renaming them to match the way they're written in the code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Guest
    Guest
    Quote Originally Posted by Baxter Stockman View Post
    I get this

    [@uote]PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is pos
    tion independent) [-Werror]
    #include <windows.h>
    ^
    cc1plus.exe: all warnings being treated as errors

    I tried finding the problem but couldn't, since I use windows now I don't now why this happens?
    Oh you use Windows, I misunderstood. What compiler (what version, downloaded from where) are you using? If you have a Microsoft compiler suite installed as well, maybe that would be less error prone on Windows? Beyond that I can't give much advice. I think someone like Salem knows better how to get things right.

  7. #7
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    Quote Originally Posted by Guest View Post
    Oh you use Windows, I misunderstood. What compiler (what version, downloaded from where) are you using? If you have a Microsoft compiler suite installed as well, maybe that would be less error prone on Windows? Beyond that I can't give much advice. I think someone like Salem knows better how to get things right.

    I tried on both platforms with the same errors, I use this setup for windows How to Compile a C Program Using the GNU Compiler (GCC) - 27 Easy Steps

    and for Linux the preinstalled gcc version

    What would you recommend?

  8. #8
    Guest
    Guest
    Sorry, I don't think I can be of any further help. The whole source code seems archaic to me, but that's probably because it's written with particular hardware in mind, or because I'm a C++ guy. You could try doing what Salem suggested and rename the files to match what the #include directives call them, but even then I'm not sure this code is self-consistent.

    If you're gonna do coding with C in the future anyway, how about learning more C and trying to find a developer manual for the hardware so you can (re)write this little library yourself? Your current approach could lead to prolonged frustration.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program is compiling, but not doing what I want it to
    By charms26 in forum C Programming
    Replies: 3
    Last Post: 10-24-2015, 10:31 AM
  2. Can somebody tell me why this program isn't compiling?
    By caduardo21 in forum Windows Programming
    Replies: 2
    Last Post: 01-25-2005, 08:40 AM
  3. Help compiling a program
    By jjj93421 in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2004, 06:38 PM
  4. compiling qt program
    By rip1968 in forum Linux Programming
    Replies: 3
    Last Post: 04-07-2003, 07:06 PM
  5. Compiling a program in VC++ and run it in DOS
    By Willhunting in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-18-2003, 04:09 AM

Tags for this Thread