【发布时间】:2013-04-02 23:17:58
【问题描述】:
我有一个带有源文件的项目(每个 func 也有一个 .h):
- test_functions.c
- func1.c
- func2.c
- func3.c
- func4.c
- func5.c
我在test_functions.c 中得到一个未定义的引用,用于func3.c 中定义的函数。
到目前为止的步骤:
-
make VERBOSE=1显示构建 func3.c 和 func3.c.o 的链接 -
nm func3.c.o表示符号已定义 -
readelf -s func3.c.o显示符号也已定义 -
make VERBOSE=1显示正在使用 gcc,而不是名称修改问题
这就是有趣的地方,我疯狂并删除了重新编译的func3.c,现在我得到了对func3 的未定义引用(显然),现在还有一个对func2 的未定义引用!!然而我之前已经用那个函数编译过!
如果我将func3.c 添加回源代码,注释掉对func3() 的函数调用,我可以调用func2() 就好了……我完全不知所措。
请求编译:
Scanning dependencies of target test_opencl_functions
make[2]: Leaving directory `/home/constantin/workspace/durp/tests/release_arm'
make -f CMakeFiles/test_opencl_functions.dir/build.make CMakeFiles/test_opencl_functions.dir/build
make[2]: Entering directory `/home/constantin/workspace/durp/tests/release_arm'
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 14
[ 53%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclpyramid.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclpyramid.c.o -c /home/constantin/workspace/durp/tests/src/opencl/opencl_functions/openclpyramid.c
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 15
[ 57%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclimagewarp.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclimagewarp.c.o -c /home/constantin/workspace/durp/tests/src/opencl/opencl_functions/openclimagewarp.c
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 16
[ 61%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/opencl_utilities.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/opencl_utilities.c.o -c /home/constantin/workspace/durp/tests/src/opencl/opencl_functions/opencl_utilities.c
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 17
[ 65%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclbackgroundsub.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclbackgroundsub.c.o -c /home/constantin/workspace/durp/tests/src/opencl/opencl_functions/openclbackgroundsub.c
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 18
[ 69%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclconvolution.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclconvolution.c.o -c /home/constantin/workspace/durp/tests/src/opencl/opencl_functions/openclconvolution.c
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 19
[ 73%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclrgbtogray.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclrgbtogray.c.o -c /home/constantin/workspace/durp/tests/src/opencl/opencl_functions/openclrgbtogray.c
/usr/bin/cmake -E cmake_progress_report /home/constantin/workspace/durp/tests/release_arm/CMakeFiles 20
[ 76%] Building C object CMakeFiles/test_opencl_functions.dir/src/opencl/test_functions.c.o
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -I/home/constantin/workspace/durp/tests/../PanasonicCameraLib -I/home/constantin/workspace/durp/tests/../linux_arm_tool/include -o CMakeFiles/test_opencl_functions.dir/src/opencl/test_functions.c.o -c /home/constantin/workspace/durp/tests/src/opencl/test_functions.c
Linking C executable test_opencl_functions
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_opencl_functions.dir/link.txt --verbose=1
/usr/bin/arm-linux-gnueabi-gcc-4.5 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -mfpu=vfpv3-d16 -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,-z,nocopyreloc -Wl,-rpath-link,/home/constantin/workspace/durp/tests/../linux_arm_tool/lib,-rpath-link,/usr/arm-linux-gnueabi/lib,-rpath-link CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclpyramid.c.o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclimagewarp.c.o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/opencl_utilities.c.o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclbackgroundsub.c.o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclconvolution.c.o CMakeFiles/test_opencl_functions.dir/src/opencl/opencl_functions/openclrgbtogray.c.o CMakeFiles/test_opencl_functions.dir/src/opencl/test_functions.c.o -o test_opencl_functions -L/home/constantin/workspace/durp/tests/../linux_arm_tool/lib -L/home/constantin/workspace/durp/CarmaDev/cuda/lib -rdynamic -lPanasonicCameraLib -lm -lOpenCL -lGAL
CMakeFiles/test_opencl_functions.dir/src/opencl/test_functions.c.o: In function `TestPyramid':
test_functions.c:(.text+0x89c): undefined reference to `opencl_pyramid'
【问题讨论】:
-
我的第一个怀疑是你没有干净地重新编译。清洁后,您能否发布 Make 的 exact 输出? (理想情况下,简化测试用例,这样我们就不必在这里考虑 6 个文件!)
-
奥利,我做了一个 rm -rf *,然后重新运行了我的 cmake。用新鲜的做它是一样的。我刚刚转移到另一台计算机(注意我在上面使用了 arm 交叉编译器)并且本地编译(gnu gcc)工作得很好。我会尽力为您提供 make 输出,但我无法分享所有细节。
-
构建订单有可能吗?我注意到
openclpyramid.c.o和openclwarpimage.c.o在opencl_utilities.c.o之前链接并且都依赖它。但是......如果我添加两个目标文件但不调用opencl_pyramid,我可以成功链接openclwarpimage.c.o,无论顺序如何...... -
在另一台计算机上编译没有问题的事实真的让我很恼火。
-
他是交叉编译到 ARM 还是你在本地运行工具链?您提到的另一台计算机是否也在本地编译?编译器版本一样吗?
标签: c compilation linker opencl