C / C ++详细编译错误,多个定义

时间:2011-08-05 14:32:16

标签: linker makefile compiler-errors cmake

我自己并不是一名C / C ++程序员,但我的任务是构建我实验室中使用的Deconvolution程序。

以下是我得到的投诉:

 [ 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

我发现的正常解决方案是在代码WienerDeconvolve.cxx中插入#include cstlib,但是当我这样做时,会发生这种情况:

        [  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

这是一个非常大的项目,因此这对我来说是一些令人生畏的错误。有谁知道问题可能是什么?很多人编译过这个,并且已经在RedHat上进行了测试。在搞砸了几天后,我没有想法,但我很乐意提供任何可能有用的信息。

2 个答案:

答案 0 :(得分:3)

查看发布的错误消息,我会说#include< cstdlib>与第二组错误无关。包括cstdlib解决了一些编译错误,允许编译阶段完成,链接阶段开始。

在链接阶段引发了第二组错误,因为某些函数已在多个编译单元中定义。

错误消息表明名称为WienerDeconvolve.cxx,WienerDeconvolveGPU.cu_Clarity_generated.cpp和FFTGPU.cu_Clarity_generated.cpp的文件都包含具有相同签名的函数的定义:ComplexConjugate(float2),ComplexAdd(float2,float2)等等。

基本上,当链接器找到具有相同签名的多个函数时,不确定使用哪个函数并生成这些错误。导致这些错误的原因有很多,例如:

目的是使函数对于编译单元是本地的,但是忘记将它们声明为静态或将它们放在匿名命名空间中。

这些函数是在多个源文件包含的头文件中定义的。有关详情,请参阅此帖子:Link error with really simple functions C++ on .h file

您需要做的是查看代码,找到定义这些多重定义函数的位置,以确定如何多次定义它们。该信息将帮助您确定问题的解决方案。

答案 1 :(得分:0)

  

我发现的常规解决方案是在代码中插入#include cstlib,WienerDeconvolve.cxx

那部分吓到我了。除了奇怪的措辞,你是#include .cxx文件吗?获得该错误的唯一另一种方法是,如果您的标头中有函数定义,而不是仅声明。

嗯,你也可以连续多次链接一个对象,但是我还没有看到有人这样做:)