LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-10-2002, 10:34 PM   #1
Chaucer
LQ Newbie
 
Registered: Oct 2002
Posts: 3

Rep: Reputation: 0
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.
 
Old 11-11-2002, 03:26 AM   #2
obashir
LQ Newbie
 
Registered: Nov 2002
Location: Loughborough, UK
Distribution: Redhat 9, Fedora, Yellow Dog
Posts: 29

Rep: Reputation: 15
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
 
Old 11-11-2002, 03:40 AM   #3
obashir
LQ Newbie
 
Registered: Nov 2002
Location: Loughborough, UK
Distribution: Redhat 9, Fedora, Yellow Dog
Posts: 29

Rep: Reputation: 15
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.
 
Old 11-11-2002, 04:55 PM   #4
M3xican
LQ Newbie
 
Registered: Nov 2002
Location: Naples, Italy
Distribution: Slackware
Posts: 14

Rep: Reputation: 0
Wink Idea...

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error zali Programming 3 09-22-2005 09:35 PM
Linux Kernel 2.6.11 Compile Error Jacky Quah Linux - General 1 05-30-2005 04:41 PM
compile error archish Programming 2 05-10-2004 10:38 PM
compile error: #error unknown processor family kmack2001 Linux - Newbie 0 02-14-2004 11:52 AM
Alsa compile error, and a WINE error scheidel21 Linux - Software 1 12-08-2003 08:16 PM


All times are GMT -5. The time now is 09:08 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration