Page 1 of 1

C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 4:16 pm
by swhite
Hi

I have been using the following with the PB 6.20 asm compiler without any issues:

Code: Select all

ProcedureCDLL.i main(argc.l, argv.i)
However when I use the "C" compiler I get the following error:
Error: Assembler
error: conflicting types for ‘main’
int main(int argc, char* argv[]) {
^~~~
purebasic.c:11227:5: note: previous definition of ‘main’ was here
int main(int v_argc,int v_argv) {
^~~~
purebasic.c: In function ‘main’:
Does anyone know how this should be fixed?

Sometimes the error says the following where the "int" is changed to "integer" which I believe is incorrect.
Error: Assembler
error: conflicting types for ‘main’
int main(int argc, char* argv[]) {
^~~~
purebasic.c:11227:9: note: previous definition of ‘main’ was here
integer main(int v_argc,integer v_argv) {
Thanks,
Simon

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 4:35 pm
by Quin
I don't have the answer, but you did post this topic twice, just FYI :)

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 4:37 pm
by mk-soft
This is normal, since the c function "main" is already created and used by the c compiler.

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 4:43 pm
by swhite
If it is normal why did the compilation fail?

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 4:51 pm
by Fred
Yes main() is already defined in the C backend as it's the program entry point. You can't redefine it.

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 5:03 pm
by mk-soft
Show commented c output

Code: Select all

...
int main(int argc, char* argv[]) {
PB_ArgC = argc;
PB_ArgV = argv;
SYS_InitPureBasic();
PB_InitProcess();
// cArgs = CountProgramParameters()
integer r0=PB_CountProgramParameters();
v_cargs=r0;
// If cArgs
if (!(v_cargs)) { goto no2; }
// 
// 
// EndIf
no2:;
// 
SYS_Quit();
}
...

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 7:07 pm
by swhite
Fred wrote: Fri Mar 07, 2025 4:51 pm Yes main() is already defined in the C backend as it's the program entry point. You can't redefine it.
So does that mean I have to change

Code: Select all

ProcedureCDLL.i main(argc.l, argv.i)
to make it compile? I am creating a Linux "so" that is used by another web server which is expecting "main" as the entry point.

Simon

Re: C Compiler Error: Conflicting Types for Main.

Posted: Fri Mar 07, 2025 8:48 pm
by mk-soft
In a library there is no entry point "main".
So you can use it as a library and compile it, but not as a program.

Re: C Compiler Error: Conflicting Types for Main.

Posted: Sat Mar 08, 2025 4:10 am
by swhite
Hi

So I will have to keep using the ASM compiler because it works and that is the way the third party tool expects. Just out of curiosity how would I write the code so that the code that is currently contained in ProcedureCDLL.i main(argc.l, argv.i) would work with the C compiler?

Simon

Re: C Compiler Error: Conflicting Types for Main.

Posted: Sat Mar 08, 2025 10:30 am
by Fred
If you create an .so it shouldn't have a main() generated. I will check that

Re: C Compiler Error: Conflicting Types for Main.

Posted: Sat Mar 08, 2025 1:20 pm
by swhite
Hi Fred

I think I may have missed a compiler directive so I will check that.

Simon

Re: C Compiler Error: Conflicting Types for Main.

Posted: Sat Mar 08, 2025 1:32 pm
by swhite
Hi Fred

I checked and I had missed the compiler directive -so. So it is working now.

Simon

Re: C Compiler Error: Conflicting Types for Main.

Posted: Sat Mar 08, 2025 1:54 pm
by mk-soft
Fred wrote: Sat Mar 08, 2025 10:30 am If you create an .so it shouldn't have a main() generated. I will check that
When a library is created in Linux, no main() is created internally by pb.
This means that the own created ProcedureCDLL main(argc.l, arg.i) works in ASM and C-Backend.
So the application can call the main function in the library.

Tested under Mint Linux LMDE 6 and PB v6.20 as ASM library and C backend library.