multiple definition of main error in eclipse using C

前端 未结 2 1175
陌清茗
陌清茗 2021-01-07 00:21

I\'m trying to generate two exes, client and server using a C Project in eclipse. Both have main functions since they are different exes. Both use a common confutils.c file.

相关标签:
2条回答
  • 2021-01-07 00:58

    I think you can set up multiple "Build Configurations" to avoid this. Under "Project" in the menu bar you can choose your active build configuration.

    There are ways to exclude files in different configurations. Under your project properties you go to "C/C++ General", "Paths and Symbols" and here you choose "Source Location". Top most you can now choose your build configuration and then define different sorurce locations for you different build configurations. Here you add folders for your source code, and, here comes the trick, for the folders you choose to include you can put filter to ignore specific files.

    In your case I would make two Build Configurations, one for confclient and for this one I would exclude confserver.c from the scource location, and vice versa.

    You will need to build you project twice, but the utilspart will be left unchanged and hence it wont recompile which is a benefit over having two projects. Also it might be nice to have all the code in the same project since I guess the code on the server side and client side will be connected.

    0 讨论(0)
  • 2021-01-07 01:20

    It's possible to define multiple build configurations - each having different set of files that are built.

    First open Project properties and navigate to Manage Configurations:

    Create a new build configuration:

    And set it active:

    Finally define filter excluding file(s) to ensure that you build a source file with main() you want to use only:

    And that's it:

    Now you can choose target build configuration from Menu > Project > Build Configurations > Set Active.

    0 讨论(0)
提交回复
热议问题