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

发布于 2024-11-28 00:42:58 字数 5558 浏览 1 评论 0原文

我自己并不是一个 C/C++ 程序员,但我的任务是构建一个在我的实验室中使用的反卷积程序。

这是我收到的抱怨:

 [ 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上进行了测试。经过几天的混乱,我已经没有想法了,但我很乐意提供任何可能有帮助的信息。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨光如昨 2024-12-05 00:42:58

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

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

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

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

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

这些函数是在多个源文件包含的头文件中定义的。有关详细信息,请参阅此帖子:链接错误非常简单.h 文件上的 C++ 函数

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

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.

黯淡〆 2024-12-05 00:42:58

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

这部分让我害怕。抛开奇怪的措辞不谈,您是否正在#include ing .cxx 文件?出现该错误的唯一其他方法是,如果标头中有函数定义,而不是只有声明。

好吧,我猜你也可以多次链接一个对象,但我还没有看到有人这样做:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文