Search code examples
c++eclipsebuildgit-submodules

Selecting C++ main function to build in eclipse


I've a C++ project in eclipse which is version managed with git. I've a git submodule, which is another project I've written in C++. The submodule has its main function and my project has its own.

Eclipse chooses other main (from the submodule) to compile when I press build. Is there a way to choose which main to build in eclipse?

Update: I'm still working on the issue. Excluding resources from the project didn't help either. Will answer the question when I solve it.

Update 2: Solved at last. See my answer.


Solution

  • I have solved the problem, at last. The solution is not a simple and straightforward one, so I'm writing step by step:

    1. First set your toolchain correctly from Properties -> C/C++ Build -> Tool Chain Editor -> Current toolchain. It's MacOSX GCCor Linux GCC for me.

    2. Set your correct project source path. I've symlinked the files from projects I imported as submodules to my project, so setting the correct source directory didn't exclude any required files from my project. Setting is at Properties -> C/C++ General -> Paths & Symbols -> Source Location. Make sure you exclude the other submodules and symlink the required files to your project.

    3. Change the name of the artifact (binary, library, etc.) to something different than the ${projName}, because when you have submodules, you will have a directory named as ${projName} inside your build folder. Setting is at Properties -> C/C++ Build -> Settings -> Build Artifact -> Artifact name.

    After making these changes, your project should build automatically. Looks like eclipse makes all necessary checks during build, but doesn't warn you about the problems. I had to see all these problems with running make --always-build inside the Debug folder.