Question:
how do i fix this compiler error "undefined symbol main"?
mchstigger04
2006-10-15 20:00:15 UTC
i'm compiling my c++ program in linux and i keep getting this message:
"
> make
g++ -Wall -c -g project2.cpp
g++ -Wall -c -g image.cpp
g++ -o project2.exe /user/cse232/Projects/P2Graphics/color.o\
/user/cse232/Projects/P2Graphics/functions.o image.o
Undefined first referenced
symbol in file
main /soft/sparc/gcc3.4.1/lib/gcc/sparc-sun-solaris2.9/3.4.1/crt1.o
ld: fatal: Symbol referencing errors. No output written to project2.exe
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `project2.exe'
"
i do have a main() function in project2.cpp. i checked it many times and dont know what could be wrong with it. is it something with my makefile? any help would be GREATLY appreciated.
Four answers:
waghdude
2006-10-15 20:37:13 UTC
You said that there's a main() in project2.cpp, so check in your Makefile whether project2.o is being linked together with image.cpp.



On the line:



g++ -o project2.exe /user/cse232/Projects/P2Graphi...



You didn't send the entire command being sent to the linker, but I'm guessing that it must have image.o because that's the module that's referencing main(). Check if project2.o is also in that line.



The -o project2.exe does not implicitly cause project2.o to be included in the linking.
anonymous
2016-05-22 09:24:00 UTC
see first you need to know what is a linker and what is a linker error. After code compilation, that code is linked with all the library functions existent in your turboC directory...Now, that is the job of the linker to find out the body of the functions u have used like printf, scanf etc...Now you have used one function called "symbol_circle" which you have declared and called from the main function but you havent declared the body of it...During linking time, the linker sees that the function is called but it has got no corresponding code to execute...write a body of that function.....then u will find no linker error will occur..
skoog
2017-02-22 13:56:28 UTC
Cse232
iammisc
2006-10-15 20:10:40 UTC
a main function:



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



is the beginning point of a c program. argc is the argument count and argv is an array of arguments passed to the program.



really. i think you should restudy c++.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...