cancel
Showing results for 
Search instead for 
Did you mean: 

C++ compile multiple definition

IVent.1
Associate III

Hi,

I have a C project, it compiles perfectly.

I changed the extension of main from main.c to main.cpp.

I use the function "Convert to C++", I did "Clean project"

but when I compile the project, I have a bulk of compiling error of this type:

C:/myproject/Debug/../Src/filex.c:62: multiple definition of `Function1'; ./Src/app_filex.o:C:/myproject/Debug/../Src/filex.c:62: first defined here

 

and this for every functions, I suppose.

Any suggestion?thank you

1 ACCEPTED SOLUTION

Accepted Solutions

At the end, I did the project from the beginning, starting directly as a C++ project, adding files by files starting from main, because no way to find the problem in the original project. Thank you.

View solution in original post

6 REPLIES 6
Andrew Neil
Evangelist III

So take a look at those errors: they tell you where each of the multiple definitions is - look at those definitions.

I don't have more than one definition.

The errors say you do!

Post the full errors, and the source code to which they relate.

In both cases, use this button to post the text:

AndrewNeil_0-1712939865741.png

Copy & paste the errors from the 'Console' window.

Doesn't matter, the compiler thinks you do.

So either an include file is being pulled in recursively, and is not guarded against doing so, or you have actual definitions of code or variable in an include file.

Start with the first error, and understand why the compiler might be seeing things twice.

Get the tools to output a "Preprocessor Pass", and perhaps reviews that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@Tesla DeLorean wrote:

Doesn't matter, the compiler thinks you do.


Indeed.

 


@Tesla DeLorean wrote:

or you have actual definitions of code or variable in an include file.


@IVent.1 for example, see:

https://community.st.com/t5/stm32cubeide-mcus/build-issue-as-variable-defined-once-more-however-it-is-only/m-p/657254/highlight/true#M25815

 


@Tesla DeLorean wrote:

Start with the first error, .


Absolulutely.

@IVent.1 for this, you need to look in the 'Console' window - don't use the 'Problems' view, because that re-orders things.

Note that, when you have very many errors, the console view might "lose" the early ones. 

See:

https://community.st.com/t5/stm32cubeide-mcus/sudden-error/m-p/658411/highlight/true#M25944

and:

https://community.st.com/t5/stm32cubeide-mcus/sudden-error/m-p/658427/highlight/true#M25950

and, for the location of the full log:

https://community.st.com/t5/stm32cubeide-mcus/sudden-error/m-p/658438/highlight/true#M25953

 

At the end, I did the project from the beginning, starting directly as a C++ project, adding files by files starting from main, because no way to find the problem in the original project. Thank you.