I am trying to build a C++ project in Xcode 4.6.3.
In my project (the beginnings of a very simple OpenGL game) I have two files:
textures.h:
#pragma once
#include <GLUT/GLUT.h>
void load(); // load textures
GLuint dirt, water; // variables to store texture handles
textures.cpp:
#include "textures.h"
#include "util.h"
void textures::load() {
dirt = util::loadTexture("/Some/Path/Soil.png");
water = util::loadTexture("/Some/Path/Water_fresh.png");
}
Here util.h defines the util::loadTexture function.
There are two files that include textures.h. The first (main.cpp) calls the load() function as part of initialization and accesses the dirt variable to bind the Soil.png texture. The second (Chunk.cpp) includes textures.h, but doesn't actually access anything from it yet.
When I try to build the project, it gives me the following error:
duplicate symbol _dirt in:
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/main.o
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/Chunk.o
duplicate symbol _water in:
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/main.o
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/Chunk.o
duplicate symbol _dirt in:
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/main.o
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/textures.o
duplicate symbol _water in:
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/main.o
/Users/me/Library/Developer/Xcode/DerivedData/OpenGL_Testing-epporrdukapbwzawfhiwnlztzdns/Build/Intermediates/OpenGL Testing.build/Debug/OpenGL Testing.build/Objects-normal/x86_64/textures.o
ld: 4 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I understand that this means there is a duplicate somewhere, or a header is included multiple times. But all of my headers use #pragma once
, and I have done search in workspace for "dirt" and such, and there are no other definitions. My other headers work fine, even the ones that are included multiple times. I have googled this problem many times with different keywords, and have taken a look at other similar questions, but all I found was this SO question.
I have encountered other "random" errors before in Xcode - for example, one project kept trying to use a dynamic library that I had deleted and replaced with a static one. The error stayed, even when I created a brand new project. It worked when compiled manually from Terminal.
What am I missing?