1

I'm not much of a C/C++ programmer myself, but I've been tasked with building a Deconvolution program used in my lab.

Here is the complaint I've been getting:

 [ 10%] Building (Device) NVCC /home/chris/Desktop/Clarity-1.0/src/WienerDeconvolveGPU.cu: /home/chris/Desktop/Clarbuild/src/cuda/src/WienerDeconvolveGPU.cu_Clarity_generated.cpp
[ 13%] Building CXX object CMakeFiles/Clarity.dir/src/WienerDeconvolve.o
/home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx: In function ‘ClarityResult_t Clarity_WienerDeconvolve(float*, Clarity_Dim3, float*, Clarity_Dim3, float*, float)’:
/home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx:211: error: ‘malloc’ was not declared in this scope
/home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx:246: error: ‘free’ was not declared in this scope
make[2]: *** [CMakeFiles/Clarity.dir/src/WienerDeconvolve.o] Error 1
make[1]: *** [CMakeFiles/Clarity.dir/all] Error 2
make: *** [all] Error 2

The normal solution I've found is to insert #include cstlib in the code, WienerDeconvolve.cxx, but when I do that, this happens:

        [  2%] Building CXX object CMakeFiles/Clarity.dir/src/WienerDeconvolve.o
Linking CXX static library libClarity.a
[ 89%] Built target Clarity
Linking CXX executable ConvolutionTest
[ 92%] Built target ConvolutionTest
Linking CXX executable JansenVanCittertTest
[ 94%] Built target JansenVanCittertTest
Linking CXX executable MaximumLikelihoodTest
[ 97%] Built target MaximumLikelihoodTest
Linking CXX executable WienerFilterTest
../../libClarity.a(WienerDeconvolve.o): In function `ComplexConjugate(float2)':
WienerDeconvolve.cxx:(.text+0x2a0): multiple definition of `ComplexConjugate(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x0): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexAdd(float2, float2)':
WienerDeconvolve.cxx:(.text+0x2c6): multiple definition of `ComplexAdd(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x24): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexMultiply(float2, float2)':
WienerDeconvolve.cxx:(.text+0x300): multiple definition of `ComplexMultiply(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x54): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexScale(float2, float)':
WienerDeconvolve.cxx:(.text+0x34e): multiple definition of `ComplexScale(float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x84): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexMultiplyAndScale(float2, float2, float)':
WienerDeconvolve.cxx:(.text+0x378): multiple definition of `ComplexMultiplyAndScale(float2, float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xa8): first defined here
../../libClarity.a(WienerDeconvolve.o): In function `ComplexMagnitudeSquared(float2)':
WienerDeconvolve.cxx:(.text+0x3ed): multiple definition of `ComplexMagnitudeSquared(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xd8): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexConjugate(float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x0): multiple definition of `ComplexConjugate(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x0): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexAdd(float2, float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x24): multiple definition of `ComplexAdd(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x24): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMultiply(float2, float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x54): multiple definition of `ComplexMultiply(float2, float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x54): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexScale(float2, float)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x84): multiple definition of `ComplexScale(float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x84): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMultiplyAndScale(float2, float2, float)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0xa8): multiple definition of `ComplexMultiplyAndScale(float2, float2, float)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xa8): first defined here
../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMagnitudeSquared(float2)':
WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0xd8): multiple definition of `ComplexMagnitudeSquared(float2)'
../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xd8): first defined here
collect2: ld returned 1 exit status
make[2]: *** [tests/WienerFilterTest/WienerFilterTest] Error 1
make[1]: *** [tests/WienerFilterTest/CMakeFiles/WienerFilterTest.dir/all] Error 2
make: *** [all] Error 2

This is a pretty large project, and thus these are some intimidating errors for me. Does anyone have any idea what the problem could be? Many people have compiled this, and it's been tested on RedHat. After messing with it a few days I'm out of ideas, but I'll be happy to provide any information that might help.

Chris
  • 11
  • 1
  • 2
  • Small nitpick: The compiler complains about `malloc` and `free`, not about `std::malloc` and `std::free`. So you should have included ``, not ``. The latter declares `std::malloc` and might (but does not have to) also declare `malloc`. – Sjoerd Aug 06 '11 at 15:03

2 Answers2

3

Looking at the error messages posted, I would say that the #include<cstdlib> is unrelated to the second set of errors. Including cstdlib solved some compilation errors, allowing the compilation stage to complete and the linking stage to start.

The second set of errors is raised during the link stage because some functions have been defined in more than one compilation unit.

The error messages indicate that the files with the names WienerDeconvolve.cxx, WienerDeconvolveGPU.cu_Clarity_generated.cpp, and FFTGPU.cu_Clarity_generated.cpp all contain definitions for functions with the same signature: ComplexConjugate(float2), ComplexAdd(float2, float2), etc.

Bascially, when the linker finds multiple functions with the same signature, it is unsure which one to use and generates these errors. There are a number of reasons that these errors could occur, such as:

The intent was for the functions to be local to the compilation unit, but it was forgotten to declare them as static or to place them in an anonymous namespace.

The functions were defined in a header file that was included by multiple source files. See this post for more information: Link error with really simple functions C++ on .h file

What you will need to do is look through your code to find the location(s) where these multiply defined functions are being defined to determine exactly how they are being defined more than once. That information will let you determine the solution to the problem.

Community
  • 1
  • 1
dgraves
  • 351
  • 1
  • 2
  • 4
  • 1
    Also, it may be that some files that define CUDA functions are being included in multiple places. If that is the case, try making a header file that declares the CUDA functions and include that instead. – dgraves Aug 06 '11 at 15:38
0

The normal solution I've found is to insert #include cstlib in the code, WienerDeconvolve.cxx

That part scares me. Weird wording aside, are you #includeing .cxx files? The only other way you get that error is if you have function definitions in your header, as opposed to only declarations.

Well, you could also be linking an object multiple times I guess, but I haven't yet seen someone do that :)

Blindy
  • 65,249
  • 10
  • 91
  • 131