CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004

    Unhappy Need some help compiling a C++ file

    It has been a while since I used C++ and I need some help compiling some source codes.

    I have a program that contains about 21 files some of these files are header files and some are .cpp files.

    When I try to compile the main.cpp file I get a bunch of error saying it cannot find some of the other files that is needed for the main program to run.

    I'm using gcc -o main main.cpp to compile the main program (this is when I get the error).

    I also tried to compile all the files together by using gcc -o main *.cpp but I still get some errors.

    How can I compile the files in the correct order so I can get it to work? I tried to compile some of the other files that has no MAIN in the code, but I cannot get it to compile, I get an error saying undefined reference to main.

    Thank you

  2. #2
    Join Date
    Nov 2006

    Re: Need some help compiling a C++ file

    isn't it

    g++ *.cpp -o main
    You'll need to compile all the files together, If it errors with this then paste the errors you get here.
    Last edited by zeRoau; June 14th, 2009 at 01:24 PM.

  3. #3
    Join Date
    Jan 2004
    Düsseldorf, Germany

    Re: Need some help compiling a C++ file

    First, you need to learn to differentiate compiler and linker errors. Which ones are you getting?

    To compile a cpp file, use g++ -c <filename>. So g++ -c *.cpp should give you a bunch of .o files. If an error occurs during running this command, it's a compiler error and you will have to check for missing include files and possibly include the -I flag in your command.

    To link the files to form an executable use g++ -o <name_of_executable> *.o. If you get errors there, you might be missing some cpp files or you will have to link in a library (-l flag).

    In any case, post the error message to get more help.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth

    Please read Information on posting before posting, especially the info on using [code] tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.