0

I have been programming for 7 hours by now and I really can't see the problem due to exhaustion. I need some extra eyes.

Why this code doesn't compile???

bool readFromFile(const char*, Graph[5]);
bool writeToFile(Graph[5]);

int main(int argc, char* argv[]) {
    .
    .
    .

    Graph graph[5];
    if(readFromFile(argv[1], graph) == false){    //read and error check
        cout << "Returning from main(). . ." << endl;
        return -1;
    }

    if(writeToFile(graph) == false){
        cout << "Returning from main(). . ." << endl;
        return -1;
    }

    return 0;
}

bool writetoFile(Graph graph[5]){
    FILE* fp;
    fp = fopen("output2.txt","w");
    if(fp == NULL){
        cout << "Error opening file: output2.txt" << endl;
        return false;
    }

    //count pairs
    int pairCount[5] = {0};


    fclose(fp);
    return true;
}

Using NetBeans, actually when I press F9 (compile) it compiles, but when I try to run:

g++     -o dist/Debug/GNU-Linux-x86/algorithm_hw1_task2 build/Debug/GNU-Linux-x86/Graph.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/Node.o  
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/varaquilex/NetBeansProjects/algorithm_hw1_task2/main.cpp:40: undefined reference to `writeToFile(Graph*)'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/algorithm_hw1_task2] Error 1
make[2]: Leaving directory `/home/varaquilex/NetBeansProjects/algorithm_hw1_task2'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/varaquilex/NetBeansProjects/algorithm_hw1_task2'
make: *** [.build-impl] Error 2

also when I try to compile using g++

/tmp/ccM7A6te.o: In function `main':
main.cpp:(.text+0x187): undefined reference to `writeToFile(Graph*)'
collect2: error: ld returned 1 exit status

Note: I'll remove the question asap, thanks for your attention.

Preet Kukreti
  • 8,417
  • 28
  • 36
Varaquilex
  • 3,447
  • 7
  • 40
  • 60

2 Answers2

1

You named your function writeToGraph() in your prototype and in your code when you called it, but you named it writetoGraph() when you defined it (note difference in capitalization).

As a result, it doesn't link.

FatalError
  • 52,695
  • 14
  • 99
  • 116
  • okay, can you delete your answer so that i can delete the post? and thank you very much... – Varaquilex Mar 24 '13 at 00:57
  • 4
    Why delete it? Camel-case catches lots of tired programmers out, myself included. Leave it for someone else who's searching for 'undefined netbeans compile'. – Mere Development Mar 24 '13 at 01:03
  • That is right... I did not think it that way, I mean I'm sure there are many instances like this one out there so I wanted to delete it. It doesn't matter, it can stay anyway. I think I'll switch to using underscores again, after experiencing such an error:) – Varaquilex Mar 24 '13 at 01:08
1

You have done a typo: writetoFile instead of writeToFile in the function definition.

jacek.ciach
  • 904
  • 11
  • 20