Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic "multiple definition of" (Read 287 times)
m_404
Newbies
*
Offline


Posts: 6
Location: belgium
Joined: Sep 16th, 2026
"multiple definition of"
Sep 16th, 2026 at 4:44pm
Print Post  
Hi,

In VS2026, latest version, valid and activated license, I create a new project and each files were created from the solution explorer.

Whenever I create a global variable or define a global function in a header file that also contains a class definition, and the implementation of that class is in the corresponding cpp, that global variable or function trigger a "multiple implementation of" error on build.

That error doesn't occur if all the code is in the header...

If I exclude the files from the project, the project build correctly.

If I place them in a non-root, or non-src directory, the error still occurs if the files are included in the project. 

The project build if the files are not included (but then I wonder how they're found, as they're not in an "auto include" directory anymore...)

For the past 2 hours I tried toggling off/on different options, can't have the build pass if the files are included in the project... what am I missing?

I searched the forum and the web without success...

I'm starting to loose my mind... send help...

thank you a lot in advance for the help!
« Last Edit: Sep 16th, 2026 at 5:08pm by m_404 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12240
Location: United Kingdom
Joined: Apr 10th, 2010
Re: "multiple implementation of"
Reply #1 - Sep 16th, 2026 at 4:52pm
Print Post  
did you wrap the .h code in run once or like this? C++ will try to create the object for each file unless you protect it for one "time only"

// gggg.h

#ifndef _GGGG_h
#define _GGGG_h

/// code here

#endif
  
Back to top
IP Logged
 
m_404
Newbies
*
Offline


Posts: 6
Location: belgium
Joined: Sep 16th, 2026
Re: "multiple definition of"
Reply #2 - Sep 16th, 2026 at 5:06pm
Print Post  
Tim@Visual Micro wrote on Sep 16th, 2026 at 4:52pm:
did you wrap the .h code in run once or like this? C++ will try to create the object for each file unless you protect it for one "time only"

// gggg.h

#ifndef _GGGG_h
#define _GGGG_h

/// code here

#endif


Thanks for the quick reply, yes I use preprocessor directives to include only once the headers, there's no clash in the names, I can zip you the project If you desire, it's quite small

I've written initially a "dirty C" version with all the code in headers and I'm refactoring to classes, as of right now the problem occur in the first header I try to refactor.

As of right now, if that header contains also the class implementation, everything works. 

As soon as I keep the signature in the header and move the implementation in the cpp, I get the "multiple definition of" error.  Sad

edit: I'm at my local hackerspace, I discussed the issue with a friend as I'm maybe a bit rusty in C++ (no pun intended), but there seems to be something going on with the build itself. To me, that it works depending on whether the sources are included in the vcxproj or not when the declaration and definition are separated is a sign of something, but couldn't figure the solution in the litany of project options... meanwhile I just keep everything in the header as it's working while in the vcxproj and allows to progress on the refactorings...
« Last Edit: Sep 16th, 2026 at 7:18pm by m_404 »  
Back to top
 
IP Logged
 
m_404
Newbies
*
Offline


Posts: 6
Location: belgium
Joined: Sep 16th, 2026
Re: "multiple definition of"
Reply #3 - Sep 16th, 2026 at 9:57pm
Print Post  
nvm, it was a me problem...

once back home I loaded up a project I made a few months ago with the visualmicro demo that was cleaner than this one (and activated on that machine the second licence I purchased yesterday), on that project I had no global variables flying around, compiled fine with h/cpp, but could reproduce the problem once trying to create instances in the header.

This syntax creates the problem when instanciating in the header: class Test { } test;

but using extern instead solves the issue... my bad...
« Last Edit: Sep 16th, 2026 at 9:59pm by m_404 »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint