1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Please Help! Trying to write program and getting compile errors

Discussion in 'Software Development' started by afost86, Dec 4, 2010.

Thread Status:
Not open for further replies.
  1. afost86

    afost86 Thread Starter

    Joined:
    Dec 4, 2010
    Messages:
    1
    This is my computer information:
    Tech Support Guy System Info Utility version 1.0.0.1
    OS Version: Microsoft Windows XP Professional, Service Pack 3, 32 bit
    Processor: Genuine Intel(R) CPU T2130 @ 1.86GHz, x86 Family 6 Model 14 Stepping 12
    Processor Count: 2
    RAM: 1013 Mb
    Graphics Card: Mobile Intel(R) 945GM Express Chipset Family, 128 Mb
    Hard Drives: C: Total - 103504 MB, Free - 42504 MB; D: Total - 9911 MB, Free - 1539 MB;
    Motherboard: Quanta, 30BB, 66.3E, None
    Antivirus: AVG Anti-Virus Free, Updated: Yes, On-Demand Scanner: Enabled

    Here is my question:
    I'm trying to write a program that includes a .h file I put together and the main function (Project8.c) calls in functions from three other source codes. These source codes are readData.c, printAveForHW.c, and printHighest.c. When I compile it using gcc -o myProg Project8.c, it comes up with:

    /tmp/ccK2D86L.o: In function `main':
    Project8.c:(.text+0x70): undefined reference to `readData'
    Project8.c:(.text+0x81): undefined reference to `printAveForHW'
    Project8.c:(.text+0x92): undefined reference to `printHighest'
    collect2: ld returned 1 exit status

    Is there anybody that might be able to help me figure out what I need to change? I'm new to programming and am not sure what the error message needs. I've been looking all over the internet and can't find what might be wrong. If you can help, it would be greatly appreciated!!!!!!!


    My .h file looks like this:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    // put your typedef struct here
    typedef struct {
    char firstName[20];
    char lastName[20];
    int hw1;
    int hw2;
    int hw3;
    }student;

    // put your function declarations here
    void readData (char *filename, student arr[], int len);
    void printAveForHW (int hw, student arr[], int len);
    void printHighest (int hw, student arr[], int len);

    My main file (Project8.c) is:
    #include "Project8.h"

    int main() {
    int length = 20;
    student grades[length];
    readData( "scores.txt", grades, length );
    printAveForHW( 2, grades, length );
    printHighest( 3, grades, length );
    return 0;
    }
     
  2. peterh40

    peterh40

    Joined:
    Apr 15, 2007
    Messages:
    1,437
    First Name:
    Peter
    You main project file needs to have the code for your functions as well for it to compile. The minimum you can get away with is:

    /* Main file */
    ..
    void readData (char *filename, student arr[], int len) {
    }
    void printAveForHW (int hw, student arr[], int len) {
    }
    void printHighest (int hw, student arr[], int len) {
    }
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/966551

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice