This topic is 4462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, community! I don't understand why the following won't work. I have a global namespace SkepWorks. Everything that is about my engine is in this namespace. In one of my modules, I have a namespace SkepWorks::Asm, which is where all my assembly routines are. But for some reason, I keep getting duplicate functions errors from a module that is only including this module. In other words:
//SWMAngle.cpp
#include "SWMMath.h"
#include "SWMAngle.h"

//SWMMath.h
#include "SWMAngle.h"

namespace SkepWorks
{
namespace Asm
{
//functions
}
}


I get twelve errors like this one: 1>SWMMath.obj : error LNK2005: "float __cdecl SkepWorks::Asm::asm_arccos(float)" (?asm_arccos@Asm@SkepWorks@@YAMM@Z) already defined in SWMAngle.obj I believe that there is a circular dependency going on here, but what is the easiest way to fix it. Thanks for any assistance, exorcist_bob

##### Share on other sites
You probably have something like this:

// header.hint foo;// file1.cpp#include "header.h"// file2.cpp#include "header.h"

Which results in the global variable foo being defined in two different translation units, which causes the linker to spit out an error that it is already defined in another object file when it encounters the second definition. The solution is to define foo in a source file, not a header file, and include an extern declaration like so:

// header.hextern int foo;// file1.cpp#include "header.h"int foo; // Only do this in one .cpp file// file2.cpp#include "header.h"

The extern statement says to the compiler "this variable exists, but I don't know where it is yet." References to it are resolved at link time, and the linker will only find in definition, in file1's object file.

##### Share on other sites
Functions defined in header files suffer the same problem, which is (I'm guessing) an issue more specific to the OP's problem.

Given that the functions are defined in the headers and since they are written in assembly you are presumably attemping to be "fast," you can mark the function definitions as "inline." The general case solution is to move the definitions into a source file, but making them inline might be a better option in this specific case.

It looks like this in case you are not familiar with it:
inline float asm_arccos(float v){  /* whatever */}

##### Share on other sites
Thanks. I forgot that I have to inline all modules that are in a .h file. And yes, I do know what inlining is[smile].

Thanks,
exorcist_bob

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5
gaxio
12

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631724
• Total Posts
3001897
×