Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » compiling and running c++ functions(how to compile and run c++ functions separte from any main())
compiling and running c++ functions [message #1808881] Wed, 03 July 2019 19:25 Go to next message
Gary Roach is currently offline Gary RoachFriend
Messages: 6
Registered: June 2019
Junior Member
I am trying to get up to speed with C++ and wish to compile and run snippets of code. I created a project and created the .cpp files in the project. If I try to compile, the compiler starts screaming for a main() file. If I head my .cpp files with main instead of function notation I then get a conflict between the different main() files. How do I resolve this? I don't want to have to modify a main() file before each test run.

Debian linux testing (buster)
Eclipse 2019-6
Kde desktop

Gary R
Re: compiling and running c++ functions [message #1808945 is a reply to message #1808881] Thu, 04 July 2019 18:17 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
How did you expect the snippets to run?

The compiler doesn't care about main but the linker does.
A main function is required to run an executable written in C or C++.
It's the entry point of the program.

There are a number of tutorials on how to do this.
Here are two that popped up at the top of google search.
https://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_54.html
https://www.cyberciti.biz/faq/howto-compile-and-run-c-cplusplus-code-in-linux/

Those are calling the compile and link directly.
Eclipse/CDT creates a makefile and runs make to do the same.
Google "gnu make" or "how to use make" or similar for more information.

Eclipse/CDT doesn't support multiple executables in a Managed Build project.
A Managed Build project is one where Eclipse/CDT generates the makefile.
If you want multiple executables you need to write your own makefile
or place each in a separate project.

[Updated on: Thu, 04 July 2019 18:48]

Report message to a moderator

Previous Topic:Need to "refresh" to add new binary
Next Topic:How to Migrate Visual Studio C and C++ projects to Eclipse CDT
Goto Forum:
  


Current Time: Thu Sep 26 17:06:15 GMT 2024

Powered by FUDForum. Page generated in 0.03719 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top