LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   linux c++ compile error (https://www.linuxquestions.org/questions/programming-9/linux-c-compile-error-35107/)

Chaucer 11-10-2002 10:34 PM

linux c++ compile error
 
This is my first time programming in linux and when I compile a simple c++ program like this:

g++ simple.cpp

I get this error:

/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function `_start':
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): undefined reference to `main'
collect2: ls returned 1 exit status

Am I unable to compile classes and their methods without some main included somewhere?

Thanks.

obashir 11-11-2002 03:26 AM

Hello

To compile your code try

g++ -c sample.cpp

If there are no errors then link using

g++ sample.o -o sample

this links the sample.o produced by step 1 and then generates a linux executable "sample" in the same directory.
To execute the program type

./sample

OMAR

obashir 11-11-2002 03:40 AM

Hello Again

Previous message assumed that you had a main function in sample.cpp. For multi-file programs, e.g., sample1.cpp and sample2.cpp, where one has main function in it, do the following

g++ -c sample1.cpp
g++ -c sample2.cpp
g++ sample1.o sample2.o -o sample

To execute
./sample

It might be a good idea to read the man page on g++. On the console type

man g++

This should open the help for g++. To move forward line by line press ENTER. To exit press Q.

OMAR.

M3xican 11-11-2002 04:55 PM

Idea...
 
I think that u have to public your code to obtain a best help...


All times are GMT -5. The time now is 03:38 PM.