• 0

[C] Nasty Error: Duplicate Symbol


Question

I encountered this error a couple of days ago:

nastyError.png

I have not been able to fix it. I've tried the suggestions on this page at stack overflow, but to no avail. There are no duplicate files in my project, and there are no duplicate function definitions in my program. Does anyone have any ideas where the source of the error may be, or could be?

The developer tool returning the error is Xcode. Thanks in advance :)

Link to comment
https://www.neowin.net/forum/topic/1078449-c-nasty-error-duplicate-symbol/
Share on other sites

12 answers to this question

Recommended Posts

  • 0

This is difficult to solve without seeing the entire sourcecode, all I can suggest is that you check all the import/includes. Also, Xcode can sometimes forget to recompile some objects, try doing Product -> Clean and rebuild

Also, what is updateStudents? I assume it's a function

  • 0

Yes, updateStudents is a function. I tried the product clean, and it still fails.

Update students is only mentioned twice in my program. Once as the declaration, secondly as the definition, so there is definitely no repeat that i can find:


void updateStudents(Game g, int diceRolled);
void updateStudents(Game g, int diceRolled){
int i = 0;
int j = 0;
int numConverted = 0;
if (diceRolled != 7){
while (i < NUM_REGIONS){
if (g->regions[i].diceValue == diceRolled){
for (j = 0;j < g->campusesOwned;j++){
if ( (g->campuses[j].vertexID == regionToVertex(i) ) ||
(g->campuses[j].vertexID == regionToVertex(i) + 1) ||
(g->campuses[j].vertexID == regionToVertex(i) + 6) ||
(g->campuses[j].vertexID == regionToVertex(i) + 7) ||
(g->campuses[j].vertexID == regionToVertex(i) + 12)||
(g->campuses[j].vertexID == regionToVertex(i) + 13) ){ // if a campus lies on either one of the six veritces
if ( (g->campuses[j].campusType > VACANT_VERTEX) && (g->campuses[j].campusType <= CAMPUS_C) ){
// if it is a normal campus
g->players[g->campuses[j].campusType].students[g->regions[i].discipline] ++;
} else if ( (g->campuses[j].campusType > CAMPUS_C) && (g->campuses[j].campusType <= GO8_C) ){
// if it is a group of eight campus
g->players[g->campuses[j].campusType - 3].students[g->regions[i].discipline] += 2;
}
}
}
}
i++;
}
} else{
i = 1;
while (i <= NUM_UNIS){
numConverted = g->players[i].students[STUDENT_MTV] + g->players[i].students[STUDENT_MMONEY];
g->players[i].students[STUDENT_MTV] = 0;
g->players[i].students[STUDENT_MMONEY] = 0;
g->players[i].students[STUDENT_THD] += numConverted;
i++;
}
}
}
[/CODE]

updateStudents is not mentioned or even hinted anywhere else in my program

  • 0

I remove the function declaration then it complains:

'no previos prototype for function 'updateStudents'

AND the error still remains:

nastError2.png

'tis making me tear my hair out!

Can you remove the function declaration and see what happens? It is not invoked anywhere right?

@ surrealvortex: What do you mean by "is it invoked somewhere?"

  • 0

Yeah the no previous prototype thing is OK. Now do the reverse. Let the declaration remain and comment out the definition. What I am trying to find out is if the code surrounding the function is somehow causing a problem. What I meant was, are you calling it anywhere?

  • 0

From the error message the function is defined in both runGame and Game .o files, so is probably also defined in the .c files as well.

Is updateStudents defined in a header file like that then included into both .c files?

If the function definition is in the header it will need an "inline" added to the declaration.

Also do you have include guards in your headers?

Could you give more information on which files the updateStudents prototype and declaration are in.

  • 0
Yeah the no previous prototype thing is OK. Now do the reverse. Let the declaration remain and comment out the definition. What I am trying to find out is if the code surrounding the function is somehow causing a problem. What I meant was, are you calling it anywhere?

At the moment the function is not being called. When I comment out the definition the error disappears. But yeah, then my function won't perform the action that I want it to haha.

You aren't including it twice are you? Also, have you tried GCC? I know it says a linker error, but still, it's worth a shot.

The file which contains the definition and declaration of the file has not been included twice. It comes up with the same error in gcc:


ld: duplicate symbol _updateStudents in /var/folders/wr/4xt1cmpd68x3r6n157qz6rnc0000gn/T//cc7FczcU.o and /var/folders/wr/4xt1cmpd68x3r6n157qz6rnc0000gn/T//ccC6zt9h.o for architecture x86_64
collect2: ld returned 1 exit status
[/CODE]

From the error message the function is defined in both runGame and Game .o files, so is probably also defined in the .c files as well. Is updateStudents defined in a header file like that then included into both .c files? If the function definition is in the header it will need an "inline" added to the declaration. Also do you have include guards in your headers? Could you give more information on which files the updateStudents prototype and declaration are in.

So far my project consists of three files. These are Game.c, Game.h and runGame.c

the runGame.c only includes the Game.c file and contains a main function which returns EXIT_SUCCESS; straight away

the Game.c contains a #include "Game.h", the definitions of the functions in Game.h. The updateStudents function is declared underneath the #include and also defined underneath the declaration. The updateStudents function is not declared in the Game.h file.

Yeah, there is probably duplication in the project hierarchy.

@Sith:What do you mean by duplication in the project hierachy? I have looked at all the files for the project and do not see any duplicate files as show below:

projectFiles.png

  • 0

The .h file should not contain the implementation, and if it does, then it does not need the prototype. If you remove the prototype, then add a semicolon to the end of the implementation.


void method(int param)
{
/* ... */
};
[/CODE]

The more that I think about it, you're almost certainly double-including the code. Put this at the top of all of your *.h files:

[CODE]#pragma once[/CODE]

In older compilers (not your XCode compiler, remotely recent versions of GCC or even Visual Studio), you would use:

[CODE]#ifndef __Game_h__
#define __Game_h__

/* ... all code ... */

#endif[/CODE]

You can use both, but there really is almost no need to use #ifndef for this purpose anymore.

So far my project consists of three files. These are Game.c, Game.h and runGame.c

the runGame.c only includes the Game.c file and contains a main function which returns EXIT_SUCCESS; straight away

the Game.c contains a #include "Game.h", the definitions of the functions in Game.h.

You should never #include a *.c file from another *.c file. Only #include *.h files. The linker will combine the code.

  • 0

You should never #include a *.c file from another *.c file. Only #include *.h files. The linker will combine the code.

THAT has solved the problem!!!!! Thanks so much guys.

Oh and I meant to say that i included the declaration in game.h and the definition in game.c :p Got them mixed up.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Couple years ago I got a brand new 4TB Samsung 990 Pro for $250 during Black Friday
    • Thanks
    • Can confirm, I've built stuff for others and no complaints using their products.
    • Yes I agree, it's annoying. You can now miss tabs unless you point low enough.
    • Sysinternals Suite 2026.17.06 by Razvan Serea The Sysinternals Suite is a comprehensive package of advanced Windows utilities created by Mark Russinovich, who launched the Sysinternals website in 1996 to share his system tools and technical resources. This suite combines a wide range of troubleshooting and diagnostic tools, including Process Explorer, Process Monitor, Sysmon, Autoruns, ProcDump, the PsTools collection, and many others. It provides everything IT professionals and developers need to manage, monitor, and troubleshoot Windows systems and applications. The Suite bundles all of the core troubleshooting utilities along with their help files. Non-troubleshooting extras—such as the BSOD Screen Saver or NotMyFault—are excluded. In addition to the well-known tools, it also includes AccessChk, Autologon, Ctrl2Cap, DiskView, Disk Usage (DU), LogonSessions, PageDefrag, PsLogList, PsPasswd, RegMon, RootkitRevealer, TCPView, VMMap, ZoomIt, and more. Sysinternals Suite 2026.17.06 changelog: Autoruns v14.3 - This update to Autoruns, a utility for monitoring startup items, adds bug fixes and improves the command-line application autorunsc. ZoomIt v12.1 - This update to ZoomIt, a screen magnification and annotation tool, adds image backgrounds, webcam background blur and microphone noise cancellation support. Coreinfo v4.01 - This update to Coreinfo, a tool that reports processor, socket, NUMA memory, and cache topology of a system, as well as processor features supported, adds support for new processor features. DebugView v5.02 - This update to DebugView, a tool for displaying both kernel-mode and Win32 debug output, adds Ctrl-Shift-A support for selecting all output, and agent skills support for the CLI utility. LiveKd v5.64 - This update to LiveKd, a utility that allows running the kernel debugger on a live system, fixes a debugging privileges issue. ProcDump 3.5.2 for Linux - This update to ProcDump for Linux, a tool for capturing process dumps, adds .NET counters and a custom core dumper. Process Monitor v4.04 - This update to Process Monitor, a utility for observing real-time file system, Registry, and process or thread activity, adds some bug fixes Sysmon v15.21 - This update to Sysmon, an advanced host security monitoring tool, adds some bug fixes. Download: Sysinternals Suite 2026.17.06 | 168.0 MB (Freeware) Download: Sysinternals Suite for ARM64 | 15.4 MB Link: Sysinternals Suite Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      eurospharma62 earned a badge
      One Month Later
    • Week One Done
      With What earned a badge
      Week One Done
    • Week One Done
      Harris Gilbert earned a badge
      Week One Done
    • One Month Later
      Vincian earned a badge
      One Month Later
    • First Post
      Jocimo earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      542
    2. 2
      +Edouard
      167
    3. 3
      PsYcHoKiLLa
      85
    4. 4
      ATLien_0
      64
    5. 5
      neufuse
      64
  • Tell a friend

    Love Neowin? Tell a friend!