Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to Compile Multiple CPP Files with Main Function

Gwan1900Gwan1900 Member Posts: 3
Hello Friends
Actually My Friend has Borland Developer Studio 2006 installed on his machine and he wants to compile and Build Console C++ Application.
The problem what we don't know is that how to have more than one cpp file containing main function in a single project group and how to compile that specific file using BDS 2006.
Suppose i created a blank new C++ Console project and be default it added only one cpp file containing main function and whatever i write suppose i write cout<<"Hello World";.
it will work fine and it will build easily using F9 but when i add another cpp file containing main function and i only want the second file to build and see the output, i am unable to do that? because BDS 2006 is only compiling and building the first file only which it added by default.
now i want to know how to Build and Compile Multiple CPP Files Containing Main Function?
Because we people are unable to figure it out and unable to achieve because we don't want to create a new project for a single file containing the main function.

looking for a favorable reply.

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Hello Friends
    : Actually My Friend has Borland Developer Studio 2006 installed on
    : his machine and he wants to compile and Build Console C++
    : Application.
    : The problem what we don't know is that how to have more than one cpp
    : file containing main function in a single project group and how to
    : compile that specific file using BDS 2006.
    : Suppose i created a blank new C++ Console project and be default it
    : added only one cpp file containing main function and whatever i
    : write suppose i write cout<<"Hello World";.
    : it will work fine and it will build easily using F9 but when i add
    : another cpp file containing main function and i only want the second
    : file to build and see the output, i am unable to do that? because
    : BDS 2006 is only compiling and building the first file only which it
    : added by default.
    : now i want to know how to Build and Compile Multiple CPP Files
    : Containing Main Function?
    : Because we people are unable to figure it out and unable to achieve
    : because we don't want to create a new project for a single file
    : containing the main function.
    :
    : looking for a favorable reply.

    I don't know if there is a function in the IDE but you could use preprocessor symbols to only include one main function.
    Or more practially, change all the main's to main0, main1, main2, etc and whichever you want to use change to main.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • Gwan1900Gwan1900 Member Posts: 3
    : : Hello Friends
    : : Actually My Friend has Borland Developer Studio 2006 installed on
    : : his machine and he wants to compile and Build Console C++
    : : Application.
    : : The problem what we don't know is that how to have more than one cpp
    : : file containing main function in a single project group and how to
    : : compile that specific file using BDS 2006.
    : : Suppose i created a blank new C++ Console project and be default it
    : : added only one cpp file containing main function and whatever i
    : : write suppose i write cout<<"Hello World";.
    : : it will work fine and it will build easily using F9 but when i add
    : : another cpp file containing main function and i only want the second
    : : file to build and see the output, i am unable to do that? because
    : : BDS 2006 is only compiling and building the first file only which it
    : : added by default.
    : : now i want to know how to Build and Compile Multiple CPP Files
    : : Containing Main Function?
    : : Because we people are unable to figure it out and unable to achieve
    : : because we don't want to create a new project for a single file
    : : containing the main function.
    : :
    : : looking for a favorable reply.
    :
    : I don't know if there is a function in the IDE but you could use
    : preprocessor symbols to only include one main function.
    : Or more practially, change all the main's to main0, main1, main2,
    : etc and whichever you want to use change to main.
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry


    Thank you for your time
    But i also think that i only have this option available to me in the IDE.
    My friend also told me that he is doing it by adding and removing each cpp file which he wants to compile and etc.
    But Still Thanks for you suggestion.
  • bilderbikkelbilderbikkel Member Posts: 754
    : Hello Friends
    : Actually My Friend has Borland Developer Studio 2006 installed on
    : his machine and he wants to compile and Build Console C++
    : Application.
    : The problem what we don't know is that how to have more than one cpp
    : file containing main function in a single project group and how to
    : compile that specific file using BDS 2006.
    : Suppose i created a blank new C++ Console project and be default it
    : added only one cpp file containing main function and whatever i
    : write suppose i write cout<<"Hello World";.
    : it will work fine and it will build easily using F9 but when i add
    : another cpp file containing main function and i only want the second
    : file to build and see the output, i am unable to do that? because
    : BDS 2006 is only compiling and building the first file only which it
    : added by default.
    : now i want to know how to Build and Compile Multiple CPP Files
    : Containing Main Function?
    : Because we people are unable to figure it out and unable to achieve
    : because we don't want to create a new project for a single file
    : containing the main function.

    For every executable you'll need to make a ('C++ Console Application') Project File. Every project is allowed to have only one main() function.

    Use 'Project | Add to Project' to add all .cpp files needed to your project. The .h files will be #included the .cpp's code.

    You will get an error like 'main() can only be defined once' if there are two main() functions added to your project. You will get 'Unresolved external errors' if you have added to few .cpp files to your project.

    Good luck!



    bilderbikkel
  • pierrecarlypierrecarly Member Posts: 1
    I do not recommend more than one main. Instead use the save as option to save the additional .cpp file to the solution. Then make sure that it is linked. You can usually right click and the option "Add to solution", or something similar, should appear. In your main .cpp file you need to include the document

    #include "othercppfile.cpp"

    At that point you can call the functions within the .cpp file. Be sure to add the headers to that additional cpp file for portability. You can even create generic header (.h) files and a generic main (.cpp) that later calls the functions you need. This is also more efficient for the stage of programming it looks like you are on.

    We are all still learning. I know I sure am.
Sign In or Register to comment.