Sunday, August 2, 2009

How do i fix this compiler error "undefined symbol main"?

i'm compiling my c++ program in linux and i keep getting this message:


"


%26gt; 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/functio... image.o


Undefined first referenced


symbol in file


main /soft/sparc/gcc3.4.1/lib/gcc/sparc-sun-s...


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.

How do i fix this compiler error "undefined symbol main"?
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.
Reply: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++.

love song lyrics

No comments:

Post a Comment