I'm very new to programming and I'm trying to make a program to compute the circumference of a circle when you give it the radius, but I keep getting "fatal error LNK1169: one or more multiply defined symbols found" whenever I think I fix it, it just says the same thing. What am I doing wrong?

#include <iostream>
#include <cstdlib>
#include <cmath>


using namespace std;

//////////////////////////////////////////////////////////
double pi = 3.14159265359;
 int main()
{

		float r;
		float circumference;
		float pi;
        

		cout << "What is the radius of the circle: ";
		cin >> r;
 

		circumference = 2 * pi * r;

		cout << "The circumference is " << circumference << '.' << endl;
                           
                            
	system("PAUSE");
	return(0);

} // end main

Dani AI

Generated

LNK1169 means the linker found one or more multiply defined symbols — the real clue is earlier in the build output. Look for LNK2005 (or “already defined” / “multiple definition”) messages; they name the duplicated symbol and the two object files that define it. Typical culprits are: a non-const global defined in a header that’s included by multiple .cpp files, two source files both defining the same variable or function (including multiple mains), accidentally adding the same .cpp twice to the project, or stale .obj files left after edits. As noticed, having two things named pi is one obvious cause; ’s suggestion to remove the duplicate was correct, but removing source text without rebuilding or without checking other files can leave the linker error showing.

Practical diagnostics and fixes (order matters):

  • Inspect the full build output for LNK2005 / “already defined” lines — they tell which symbol and which .obj files are involved.
  • Clean the project (delete intermediate/binary folders) and do a full rebuild to ensure old .obj files aren’t lingering.
  • Search the entire project for definitions of the symbol (for example search for pi =, double pi, float pi, or the literal symbol name shown by the linker). If the symbol appears in a header that’s included by more than one .cpp, that’s likely the problem.

Safe ways to share a constant across files:

/* constants.h */
#pragma once
extern const double PI;

/* constants.cpp */
#include "constants.h"
const double PI = 3.141592653589793;

Or keep the constant local:

/* inside main */
const double PI = 3.141592653589793;

Extra notes: if LNK2005 points to main or another function, check for duplicate source files or accidentally compiled copies. Also avoid leaving a local pi uninitialized — that causes undefined behaviour even after the link error is fixed. Different toolchains show slightly different wording (’s compiler question matters), but the diagnosis technique above applies across MSVC, GCC and MinGW.

Recommended Answers

All 6 Replies

How many variables do you have named "pi"?

you declared two variables named pi, one is double and the other is float. Delete one of the two (preferably the one inside main() because it is uninitialized).

The problem is not with what you are compiling but how you are compiling it. Please tell us how you compiled this code (what OS, what compiler, what compiler command or build configuration, etc.).

EDIT: Oups, sorry, didn't notice the two pi variables. That's probably the problem.

I deleted the double pi but it still says the same thing.

you declared two variables named pi, one is double and the other is float. Delete one of the two (preferably the one inside main() because it is uninitialized).

I did this but it still won't work... anything else I need to change?

What compiler are you using. I just compiled it with VC++ 2010 Express, deleted the duplicate pi variable, and it compiled/linked without any errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.