undefined reference to main error

Hello together

I wrote a multifile program and corrected all the compiling errors, now i get an error while linking:


g++ -o Sniffer_v1 Sniffer.cpp SnifferMain.cpp TextUI.cpp
/usr/lib/gcc/i586-suse-linux/4.5/../../../crt1.o: In function `_start':
/usr/src/packages/BUILD/glibc-2.11.3/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status


This is the class with the main-function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * File: SnifferMain.cpp
 *
 * Author: Silas Schlatter
 * Date: 11.08.2011, 21:19
 *
 */
#include "TextUI.h"
#include "Sniffer.h"
#include <net/ethernet.h>

using namespace std;

class SnifferMain: public TextUI{
        Sniffer s;

        void programloop(){
                s.recprintPacket();
        }

        void newkeyevent(char key){}

        int main(){
                s = Sniffer(ETH_P_IP, true);

                this->setqkey('q');
                this->initialize();
                return 0;
        }
};


Just ask if the other files (classes) are also needed to find the error.
I already used google but I couldn't solve the problem, can somebody help me?
Maybe I'm just using the wrong g++ command to compile and link, I don't know?

Don't worry to much about the sense of the program. ;)

Thank you for all help.
This is NOT java.
In C++ you need to write an
int main() function in global scope.
I know that this is NOT java ^^
so the main has to be in global scope in C++?
Yes...consider the following "Hello World"
1
2
3
4
5
6
7
8
#include<iostream>
using namespace std;
int main()
{
    cout<<"C++ isn't Java, though you just said you knew it !";
    cin.get();
    return 0;
}
Last edited on
Thank you very much, I didn't remarked that.
Topic archived. No new replies allowed.