C Compiler Error: Conflicting Types for Main.

Just starting out? Need help? Post your questions and find answers here.
swhite
Addict
Addict
Posts: 805
Joined: Thu May 21, 2009 6:56 pm

C Compiler Error: Conflicting Types for Main.

Post 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
Simon White
dCipher Computing
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: C Compiler Error: Conflicting Types for Main.

Post by Quin »

I don't have the answer, but you did post this topic twice, just FYI :)
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C Compiler Error: Conflicting Types for Main.

Post by mk-soft »

This is normal, since the c function "main" is already created and used by the c compiler.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
swhite
Addict
Addict
Posts: 805
Joined: Thu May 21, 2009 6:56 pm

Re: C Compiler Error: Conflicting Types for Main.

Post by swhite »

If it is normal why did the compilation fail?
Simon White
dCipher Computing
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: C Compiler Error: Conflicting Types for Main.

Post by Fred »

Yes main() is already defined in the C backend as it's the program entry point. You can't redefine it.
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C Compiler Error: Conflicting Types for Main.

Post 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();
}
...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
swhite
Addict
Addict
Posts: 805
Joined: Thu May 21, 2009 6:56 pm

Re: C Compiler Error: Conflicting Types for Main.

Post 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
Simon White
dCipher Computing
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C Compiler Error: Conflicting Types for Main.

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
swhite
Addict
Addict
Posts: 805
Joined: Thu May 21, 2009 6:56 pm

Re: C Compiler Error: Conflicting Types for Main.

Post 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
Simon White
dCipher Computing
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: C Compiler Error: Conflicting Types for Main.

Post by Fred »

If you create an .so it shouldn't have a main() generated. I will check that
swhite
Addict
Addict
Posts: 805
Joined: Thu May 21, 2009 6:56 pm

Re: C Compiler Error: Conflicting Types for Main.

Post by swhite »

Hi Fred

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

Simon
Simon White
dCipher Computing
swhite
Addict
Addict
Posts: 805
Joined: Thu May 21, 2009 6:56 pm

Re: C Compiler Error: Conflicting Types for Main.

Post by swhite »

Hi Fred

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

Simon
Simon White
dCipher Computing
User avatar
mk-soft
Always Here
Always Here
Posts: 6315
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: C Compiler Error: Conflicting Types for Main.

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply