I got this problem while trying to build project in VS2010:

fft_test.obj : error LNK2005: "void __cdecl fft(int,double (*)[2],double (*)[2])" (?fft@@YAXHPAY01N0@Z) already defined [b]1>in fft.obj
1>fft_test.obj : error LNK2005: "void __cdecl fft_rec(int,int,int,double (*)[2],double (*)[2],double (*)[2])" (?fft_rec@@YAXHHHPAY01N00@Z) already defined in fft.obj
1>fft_test.obj : error LNK2005: "void __cdecl ifft(int,double (*)[2],double (*)[2])" (?ifft@@YAXHPAY01N0@Z) already defined in fft.obj
1>c:\users\akhtar\documents\visual studio 2010\Projects\fft_rec_given\Debug\fft_rec_given.exe : fatal error LNK1169: one or more multiply defined symbols found[/b]

and I tried following suggestion given at a forum (in my VS2010):
Solution based on VS2005:
go to project>properties>configuration properties>linker>input
add to "Additional dependency" -> Nafxcwd.lib Libcmtd.lib
add to "ignore specific library" -> Nafxcwd.lib;Libcmtd.lib
order of libraries is important( Nafxcwd.lib;Libcmtd.lib).

But now I got the following error:
1>LINK : fatal error LNK1104: cannot open file 'Nafxcwd.lib Libcmtd.lib'

Please help me what should I do now? Thanks

5 Years
Discussion Span
Last Post by akhal

Where are the fft and fft_rec function declared and defined? How are you compiling fft_test?

Possible solution: mark the fft and fft_rec functions as 'inline' if they are defined in a header file.


I have two files "fft.cpp" and "fft_test.cpp". The latter includes first one in its code as

#include "fft.cpp"

So I have no header files, just two files and the testing file includes the other one...


That's the wrong way to do things in C++.

Here is an example of the "normal" way to write code in C++. Say you have a function called Foo() and a main() function to test it. Then, this is the way you split it:

In Foo.h, declare the function Foo(), without implementing it (just a declaration):

//first, you need some "header-guards" to avoid multiple inclusions.
#ifndef FOO_H
#define FOO_H

//declaration of the function:
void Foo();

#endif //end of header-guard

Then, in the Foo.cpp file, you need:

#include "Foo.h" //include the header for the function declarations.

#include <iostream> //include whatever other thing you need.

//here is the function definition (or implementation):
void Foo() {
  std::cout << "Hello World!" << std::endl;

And finally, in the Foo_test.cpp, you have a test program with a main() function:

#include "Foo.h" //include the header, not the .cpp

int main() {
  Foo();  //call the function
  return 0;

Then, you compile both cpp files and link them together to create the executable. With GCC, it is:

$ g++ -Wall Foo.cpp Foo_test.cpp -o Foo_test

Oh thanks, that's the basics I missed :( .................

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.