gpt4 book ai didi

c++ - "cord"Boehm GC自带库导致 undefined reference 错误

转载 作者:太空狗 更新时间:2023-10-29 21:50:32 26 4
gpt4 key购买 nike

我有一个使用 Boehm GC 的项目,所以我想我可能会使用它自带的 cord 字符串库。问题是我对 cord 函数的所有调用都会导致“ undefined reference ”错误。

我在 /usr/lib 中确实有一个名为 libcord.so 的文件(这是一个 Linux 系统),我告诉 CMake 将目标链接到 gccord


编辑以回应评论 #1:

来自 CMakeLists.txt

target_link_libraries(lang gc)
target_link_libraries(lang cord)

来自错误信息:

../lib/liblang.so: undefined reference to `CORD_substr(char const*, unsigned long, unsigned long)'
../lib/liblang.so: undefined reference to `CORD_len(char const*)'
../lib/liblang.so: undefined reference to `CORD_cat(char const*, char const*)'
../lib/liblang.so: undefined reference to `CORD_cmp(char const*, char const*)'
../lib/liblang.so: undefined reference to `CORD_to_char_star(char const*)'

编辑以回应评论 #2:

$ make -j4 VERBOSE=1
/usr/bin/cmake -H/home/michael/Projects/lang -B/home/michael/Projects/lang/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/michael/Projects/lang/build/CMakeFiles /home/michael/Projects/lang/build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/michael/Projects/lang/build'
/usr/bin/make -f lib/CMakeFiles/lang.dir/build.make lib/CMakeFiles/lang.dir/depend
make[2]: Entering directory `/home/michael/Projects/lang/build'
cd /home/michael/Projects/lang/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/michael/Projects/lang /home/michael/Projects/lang/lib /home/michael/Projects/lang/build /home/michael/Projects/lang/build/lib /home/michael/Projects/lang/build/lib/CMakeFiles/lang.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/michael/Projects/lang/build'
/usr/bin/make -f lib/CMakeFiles/lang.dir/build.make lib/CMakeFiles/lang.dir/build
make[2]: Entering directory `/home/michael/Projects/lang/build'
make[2]: Nothing to be done for `lib/CMakeFiles/lang.dir/build'.
make[2]: Leaving directory `/home/michael/Projects/lang/build'
/usr/bin/cmake -E cmake_progress_report /home/michael/Projects/lang/build/CMakeFiles 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[ 94%] Built target lang
/usr/bin/make -f src/CMakeFiles/main.dir/build.make src/CMakeFiles/main.dir/depend
make[2]: Entering directory `/home/michael/Projects/lang/build'
cd /home/michael/Projects/lang/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/michael/Projects/lang /home/michael/Projects/lang/src /home/michael/Projects/lang/build /home/michael/Projects/lang/build/src /home/michael/Projects/lang/build/src/CMakeFiles/main.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/michael/Projects/lang/build'
/usr/bin/make -f src/CMakeFiles/main.dir/build.make src/CMakeFiles/main.dir/build
make[2]: Entering directory `/home/michael/Projects/lang/build'
Linking CXX executable lang
cd /home/michael/Projects/lang/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/main.dir/main.cpp.o -o lang -rdynamic ../lib/liblang.so -lgc -lcord -lgmp -Wl,-rpath,/home/michael/Projects/lang/build/lib
../lib/liblang.so: undefined reference to `CORD_substr(char const*, unsigned long, unsigned long)'
../lib/liblang.so: undefined reference to `CORD_len(char const*)'
../lib/liblang.so: undefined reference to `CORD_cat(char const*, char const*)'
../lib/liblang.so: undefined reference to `CORD_cmp(char const*, char const*)'
make[2]: Leaving directory `/home/michael/Projects/lang/build'
make[1]: Leaving directory `/home/michael/Projects/lang/build'
../lib/liblang.so: undefined reference to `CORD_to_char_star(char const*)'
collect2: ld returned 1 exit status
make[2]: *** [src/lang] Error 1
make[1]: *** [src/CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2

最佳答案

据我所知,cord.h文件似乎不包含 extern "C"中的语句,因此在您编译时名称修改不正确 liblang.so使用 C++ 编译器。

在源码里你#include <cord.h>你可能需要这样的东西:

extern "C" {
#include "cord.h"
}

关于c++ - "cord"Boehm GC自带库导致 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5930188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com