Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple definition linker error after adding a function to a previously linking file
    text
    copied!<p>So my program is working fine. Compiling, linking, running, the works. Then, I decide to add a simple function to one of my files, like this:</p> <pre><code>#ifndef UTILITY_HPP #define UTILITY_HPP /* #includes here. There's no circular include, I've checked. */ namespace yarl { namespace utility { (several function declarations and definitions) bool isVowel(const char c) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; else return false; } } } #endif </code></pre> <p>That function definition is the only change I've made to my code. Everything else is exactly the same as it was. Nothing calls it yet. I compile, and it fails to link, with g++ giving one of these errors for every file that #includes this one:</p> <pre><code>./obj/Feature.o: In function `yarl::utility::isVowel(char)': /home/max/Desktop/Development/Yarl Backup/yarl v0.27/src/Utility.hpp:130: multiple definition of `yarl::utility::isVowel(char)' ./obj/Events.o:/home/max/Desktop/Development/Yarl Backup/yarl v0.27/src /Utility.hpp:130: first defined here ./obj/GameData.o: In function `yarl::utility::isVowel(char)': </code></pre> <p>If I comment out <code>isVowel</code>, it works again. I've tried renaming it, still doesn't work. I've tried replacing it with just <code>void randomFunctionName() {}</code>, still doesn't work. I've tried making it non-inline and putting the function body in Utility.cpp, still doesn't work. I am extremely confused. Why would adding one simple function screw up the linker?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload