Please try your test on a project that DOES NOT have this error when building one of the Targets!
multiple definition of `main'
Tim S.
Please try your test on a project that DOES NOT have this error when building one of the Targets!
multiple definition of `main'
Tim S.
I have a sample c::b project (attached) with 4 c files, each with a main() & foo1() functions. If I go to one of these files (e.g. b.c), select management->symbols, set view = current file's symbols, select "Global functions" and then click "foo1", it will go to foo1() in another file (sometimes it's a.c::foo1 or d.c::foo1). This sounds like a bug.If the same function body is added, the later one will replace the former one. Why do we need to have two records for different functions.
Erez
I have a sample c::b project (attached) with 4 c files, each with a main() & foo1() functions. If I go to one of these files (e.g. b.c), select management->symbols, set view = current file's symbols, select "Global functions" and then click "foo1", it will go to foo1() in another file (sometimes it's a.c::foo1 or d.c::foo1). This sounds like a bug.If the same function body is added, the later one will replace the former one. Why do we need to have two records for different functions.
Erez
If you have four header files which all have a same function declaration, and you have four source have the same function definition, how many records do you think CC need? You may expect there need 8 (this is a bit mass), but in fact, there is only ONE. CodeCompletion plugin's parser just merge all the function declaration and definition to only one record. So, you can switch from declaration and information very quickly, also keep the record database as small as it can.
BTW: CC just ignore your makefile, because it does not have the ability to parse and analysis the makefile structure and dependency rules. Anyway, if you want this feature, patches are welcome, I just don't have motion to do this. :)
#ifndef header_h_
#define header_h_
/* function prototype */
void demo(void);
#endif
#include "header.h"
#include <stdio.h>
void demo(void) {
printf("this is our demo() function.\n";
}
#include "header.h"
int main(void)
{
demo();
return 0;
}
erezz, please try to understand that in a C or C++ project, only one file has to use [define] main() and not in multiple sources. It's like trying to link two negative or positive sides of a magnet and wait them to merge.
If you are new to programming, I would suggest to read some good manual first and then experiment with IDEs.
What you are trying to test here will not work as it finds multiple definitions of main() function.
Always have in mind the following series of events: header file, implementation, definition [where your main() is located].
For brevity:
header fileCode: header.h#ifndef header_h_
#define header_h_
/* function prototype */
void demo(void);
#endif
Implementation fileCode: implementation.c#include "header.h"
#include <stdio.h>
void demo(void) {
printf("this is our demo() function.\n";
}
Use file where main() is located.Code: main.c#include "header.h"
int main(void)
{
demo();
return 0;
}
Any constructive criticism is always welcome, but please try to understand; this is not a forum for teaching the fundamentals of programming in any language.
Well, I'm writing C code for ~14 years already. This thread/bug report has nothing to do with teaching the fundamentals of programming.Well, for someone with approximately 14 years of experience in C, I would have expected you patching it in no time and then report it to Dev team lol.
If you take a look at the project that I attached, you will see that the custom Makefile generates 4 binaries, hence 4 main() functions are perfectly fine.
Erez
Well, I'm writing C code for ~14 years already. This thread/bug report has nothing to do with teaching the fundamentals of programming.Well, for someone with approximately 14 years of experience in C, I would have expected you patching it in no time and then report it to Dev team lol.
If you take a look at the project that I attached, you will see that the custom Makefile generates 4 binaries, hence 4 main() functions are perfectly fine.
Erez
Sorry Erez, but that response of yours sounded like troll.
I rest my case.
cheers
Not sure that I understand your explanation. Note that I am a c::b user, not a developer, so I don't understand the internals of CodeCompletion plugin.
I think that it's legit to have a project that its output is multiple binaries where each binary is originated from a C file, and those C files may have functions with the same name. For a user that clicks b.c::foo1() and the IDE jump to d.c::foo1(), this is very not intuitive and strange. Still, sounds like a bug to me.
Erez
well, he said that a entry in the cc database will be overwritten from a other with the same name. This is legit, because C::B isn't made to generate multiple exe in one project (the makefile feature is simply a compatibility feature , i don't think it is thought to be used on daily use, because you won't need a IDE if you use makefiles), and there won't be multiple entries with the same name, because it won't compile.
Not sure that I understand your explanation. Note that I am a c::b user, not a developer, so I don't understand the internals of CodeCompletion plugin.
I think that it's legit to have a project that its output is multiple binaries where each binary is originated from a C file, and those C files may have functions with the same name. For a user that clicks b.c::foo1() and the IDE jump to d.c::foo1(), this is very not intuitive and strange. Still, sounds like a bug to me.
Erez
well, he said that a entry in the cc database will be overwritten from a other with the same name. This is legit, because C::B isn't made to generate multiple exe in one project (the makefile feature is simply a compatibility feature , i don't think it is thought to be used on daily use, because you won't need a IDE if you use makefiles), and there won't be multiple entries with the same name, because it won't compile.
The right way to build multiple exe is to use the workspace feature: One workspace and multiple project files, for every exe one... Probably in the future it will be possible to use multiple workspaces at the same time..
But anyway C::B is open source so you can modify and contribute if you want.
greetings
Thanks for the answer. I didn't know that c::b is limited to 1 binary per project. I hope this will be fixed in the future.
I guess that many programmers have a project with one big binary and many unit tests (each unit test is a stand-alone binary), so creating a project per unit test is problematic. In my case, I will need to have ~50 projects in my workspace.
BTW - even people that use custom Makefiles need an IDE...
Thanks,
Erez
I didn't know that c::b is limited to 1 binary per project. I hope this will be fixed in the future.It is not, it is limited to 1 binary per target and anyone telling you something else hasn't tried to open the codeblocks*.cbp projects in our repo.
Thanks for the answer. I didn't know that c::b is limited to 1 binary per project. I hope this will be fixed in the future.
I guess that many programmers have a project with one big binary and many unit tests (each unit test is a stand-alone binary), so creating a project per unit test is problematic. In my case, I will need to have ~50 projects in my workspace.
BTW - even people that use custom Makefiles need an IDE...
Thanks,
Erez
Did you try to use targets (which are like different builds under the same project) to accomplish what you are trying to do? That would be a better option imo.