由于缺少程序中其他位置使用的符号定义而导致的链接器错误
我正在测试如何在 C 中使用 extern ,因此我为 main.c、test.c、headfile.h 创建了三个文件。我想在 headfile.h 中声明变量和函数,在 test.c 中定义,然后打印出变量...
ld 失败,因为 libselinux 未定义对 gettid@GLIBC_2.30 的引用
我正在尝试从源代码构建 glibc 2.24。主机操作系统是WSL Ubuntu 20.04,编译器是gcc 9。 尝试链接 glibc 的 nss 模块时,ld 实用程序失败: /usr/bin/ld: /usr/lib/gcc/x86_64-
Zig 生成的 C 代码由于缺少函数(软浮点)而在链接阶段失败
我有一个用 Zig 编写的程序,但运行该程序的系统没有 Zig 编译器。 我将程序导出为 C 代码(通过 ofmt = c 功能),然后使用 gcc 或 clang 对其进行编译。 哪个
对 cv::aruco::getPredefinedDictionary(cv::aruco::PredefinedDictionaryType) 的未定义引用
我正在尝试在 Qt 中编写一个程序,该程序从 TCP 接收图像,然后在其中找到 ArUco 标记。 除了 ArUco 库之外,一切正常。一旦我添加了一个简单的线条定义...
我有这样的模板类,其中包含一个friend方法: 模板 类图最终 { 私人的: std::array 顶点; std::数组 我有这样的模板类,其中包含一个friend方法: template<class T1, class T2, int n> class Graph final { private: std::array<T1, n> vertex; std::array<std::array<T2, n>, n> arcs; public: Graph(const std::array<T1, n> & v, const std::array<std::array<T2, n>, n> & a); friend std::ostream & operator<<(std::ostream & os, const Graph<T1, T2, n> & g); }; template<class T1, class T2, int n> Graph<T1, T2, n>::Graph(const std::array<T1, n> & v, const std::array<std::array<T2, n>, n> & a) : vertex(v) { ... } template<class T1, class T2, int n> std::ostream & operator<<(std::ostream & os, const Graph<T1, T2, n> & g) { ... } 该类用于保存图形。 Vertex是一个存储节点的数组,T1是对应的元素类型。 Arcs 是一个 n * n 的二维数组,存储节点之间的路径开销,T2 是对应的元素类型。(注意,n 是模板非类型参数。) 我尝试创建一个Graph并调用这样的朋友方法: void test() { using std::array; array<int, 5> vertex = {100, 200, 300, 400, 500}; array<int, 5> a = {2, 3, 2, 4, 5}; array<array<int, 5>, 5> arcs = {a, a, a, a, a}; Graph<int, int, 5> g(vertex, arcs); std::cout << g << std::endl; } 只得到错误: tree_mst.h:31:87: warning: friend declaration ‘std::ostream& meyok::operator<<(std::ostream&, const Graph<T1, T2, n>&)’ declares a non-template function [-Wnon-template-friend] friend std::ostream & operator<<(std::ostream & os, const Graph<T1, T2, n> & g); ^ tree_mst.h:31:87: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) ../lib/libmtree.so: undefined reference to `operator<<(std::ostream&, Graph<int, int, 5ull> const&)' ../lib/libmtree.so: undefined reference to `Graph<int, int, 5ull>::Graph(std::array<int, 5ul> const&, std::array<std::array<int, 5ul>, 5ul> const&)' 为什么这里会弹出警告和错误。我该如何解决? friend声明为Graph的每个实例声明一个名为operator<<的常规非模板函数,并将此实例化作为参数。例如,您的程序使用 Graph<int, int, 5> - 当编译器第一次看到它时,它会生成一个声明 std::ostream & operator<<(std::ostream & os, const Graph<int, int, 5>& g); 请注意,这与您的 operator<< 函数模板是分开且不同的。 然后编译器会看到 std::cout << g 并执行重载决策来为 operator<< 选择最佳重载。由于非模板函数优于函数模板,因此在其他条件相同的情况下,选择由 friend 声明引入的函数。最后,链接器发现这个函数从未被实际实现过;因此出现错误。 最有可能的是,您的意思是与 operator<< 模板参数匹配的 Graph 函数模板的特化应该是该 Graph 特化的友元。你这样表达: // Forward declaration template<class T1, class T2, int n> class Graph; // Forward declaration template<class T1, class T2, int n> std::ostream & operator<<(std::ostream & os, const Graph<T1, T2, n> & g); template<class T1, class T2, int n> class Graph { public: friend std::ostream & operator<< <T1, T2, n>(std::ostream & os, const Graph<T1, T2, n> & g); }; 但是,完全避免 friend 并将 operator<< 委托给成员函数通常更简单: template<class T1, class T2, int n> class Graph { public: void print(std::ostream& os) const { /* actual output logic here */); }; template<class T1, class T2, int n> std::ostream& operator<<(std::ostream& os, const Graph<T1, T2, n>& g) { g.print(os); return os; }
log4cxx 对 `log4cxx::Logger::getLogger(char const*)' 的未定义引用
据我所知,我在 Ubuntu Netbeans 下有 2 个相同的 cpp 项目。 记录器测试项目 Cpp应用程序2 在两者的主文件中,我集成了以下代码: 编译结果
我正在尝试用 C 显示图形,为此我想链接 SDL 库,但这是我第一次做这样的事情,我发现的一切都没有帮助。 我想...
我正在使用 MultiversX Rust 测试框架编写集成测试。 所以,我正在运行货物测试。但它会抛出这个错误: 注意:/usr/bin/ld:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64...
我使用 sudo apt install qt6-base-dev 命令在 Ubuntu 上安装了 Qt6。我创建了 Clion Qt6 项目并编写了简单的窗口代码: #包括 #包括 #包括<
OpenMP 对 `_CRT_fenv' 和 `_setargv' 的未定义引用
我正在尝试运行这个简单的 OpenMP 示例: #包括 #包括 使用命名空间 std; int main() { 开关(_OPENMP){ 案例200805: 计算<< "Op...
未定义的符号“vtable for ...”和“typeinfo for...”?
快到最后一步了,但仍然出现一些奇怪的错误...... bash-3.2$ 使 g++ -Wall -c -g Myworld.cc g++ -Wall -gsolvePlanningProblem.o Position.o AStarNode.o PRM.o PRMNode.o World.o SingleCircleWorl...
我正在尝试运行其他开发人员的现有代码。它向我展示了这个奇怪的错误: Xcode 的输出: lib/ui/ActHospitalDetail.dart:171:25:错误:没有名为“itemBuilde...
当我在使用 Raylib 库的特定函数时得到未定义的引用时,我试图编译一个不相关的项目。 我能够使用以下 test.c 重现此行为 #
我需要修改linux rdma-core驱动,添加一些cuda相关的功能;首先,cuMemAlloc。 我已更改驱动程序中的 CMake 文件以包含 cuda.h 头文件。但是当我编译
yaml-cpp 的编译器错误 - 对 `YAML::detail::node_data::convert_to_map` 的未定义引用
这是完整的日志: /tmp/ccCvErNZ.o:在函数 `YAML::detail::node& YAML::detail::node_data::get(std::string const&, std::shared_ptr) 这是完整的日志: /tmp/ccCvErNZ.o: In function `YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, std::shared_ptr<YAML::detail::memory_holder>)': cricket.cpp:(.text._ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE[_ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE]+0x94): undefined reference to `YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)' collect2: error: ld returned 1 exit status 我尝试编译的代码很简单 #include <iostream> #include <yaml-cpp/yaml.h> using namespace std; int main() { YAML::Node test = YAML::LoadFile("test.yaml"); if (test["date"]) { cout << "HELLO"; } return 0; } 我使用的 YAML 是来自 http://www.yaml.org/start.html 的示例 如果我只是尝试加载 YAML,它会加载得很好。但如果我尝试访问任何数据,我会得到同样的错误。所以这不是链接问题。 编辑:我可以执行诸如 cout << test 和 cout << test.type() 之类的操作以及其他功能。我认为问题在于使用基于字符串的映射来访问内部节点。 您似乎没有正确链接yaml-cpp库。编译时添加参数-lyaml-cpp。例如: g++ -I/usr/local/include -L/usr/local/lib -lyaml-cpp -o test main.cpp 编辑 另一种选择是将此 cmake 包含到您的 CMakeLists.txt 中: # attempt to find static library first if this is set if(YAMLCPP_STATIC_LIBRARY) set(YAMLCPP_STATIC libyaml-cpp.a) endif() # find the yaml-cpp include directory find_path(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h PATH_SUFFIXES include PATHS ~/Library/Frameworks/yaml-cpp/include/ /Library/Frameworks/yaml-cpp/include/ /usr/local/include/ /usr/include/ /sw/yaml-cpp/ # Fink /opt/local/yaml-cpp/ # DarwinPorts /opt/csw/yaml-cpp/ # Blastwave /opt/yaml-cpp/ ${YAMLCPP_DIR}/include/) # find the yaml-cpp library find_library(YAMLCPP_LIBRARY NAMES ${YAMLCPP_STATIC} yaml-cpp PATH_SUFFIXES lib64 lib PATHS ~/Library/Frameworks /Library/Frameworks /usr/local /usr /sw /opt/local /opt/csw /opt ${YAMLCPP_DIR}/lib) # handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(YAMLCPP DEFAULT_MSG YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY) mark_as_advanced(YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY) 我在 Debian 系统上尝试编译 OpenXcom 时遇到了类似的情况。事实证明,我混合使用了测试包和稳定包,yaml 包来自稳定包,如果初始功能不止几个,那么这种组合会以某种方式导致链接失败。 如果这就是您遇到的情况(并且您也在使用 Debian),请尝试使用 从稳定版编译源代码包 apt-get --build source libyaml-cpp0.5/stable 此命令将为 libyaml 构建 .deb 包,然后您可以使用 dpkg 插入它们,如下所示: dpkg -i libyaml-cpp0.5*.deb 作为根。 从源代码编译 libyaml 将使其链接到您已有的测试库,而不是期望稳定的库,因此应该可以解决上述问题。至少对我来说是这样。 即使您不使用 Debian,出于类似的原因,从源代码(例如 tarball)编译 yaml-cpp 也可能有效。 确保这两个文件存在: /usr/local/lib/libyaml-cpp.a /usr/local/include/yaml-cpp/yaml.h 我的CMakeLists.txt: CMAKE_MINIMUM_REQUIRED(VERSION 3.4) FIND_PACKAGE(yaml-cpp REQUIRED) ADD_EXECUTABLE(yaml_cpp_test yaml_cpp_test.cpp) TARGET_LINK_LIBRARIES(yaml_cpp_test yaml-cpp) yaml_cpp_test.cpp 的内容与问题中提到的相同。 我尝试在 vps 上重现该问题(Ubuntu 14.04.1 LTS) wget -c https://github.com/jbeder/yaml-cpp/archive/release-0.5.1.tar.gz tar xvf release-0.5.1.tar.gz yaml-cpp-release-0.5.1/ cd yaml-cpp-release-0.5.1/ sudo apt-get install cmake sudo apt-get install libboost-dev cmake . make make install 之后,yaml-cpp 安装到 /usr/local/lib 和 /usr/local/include 我的工作目录中的文件: fqlgy@li407-86:~/yaml-cpp$ ll total 12 -rw-r--r-- 1 fqlgy fqlgy 162 May 8 03:29 CMakeLists.txt -rw-r--r-- 1 fqlgy fqlgy 10 May 8 03:11 test.yaml -rw-r--r-- 1 fqlgy fqlgy 240 May 8 03:11 yaml_cpp_test.cpp 当我尝试运行“cmake .”时,出现一些错误,所以我删除了行CMakeFiles/CMakeOutput.log,CMakeLists.txt的内容是: CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ADD_EXECUTABLE(yaml_cpp_test yaml_cpp_test.cpp) TARGET_LINK_LIBRARIES(yaml_cpp_test yaml-cpp) 以下输出符合预期: fqlgy@li407-86:~/yaml-cpp$ cmake . -- Configuring done -- Generating done -- Build files have been written to: /home/fqlgy/yaml-cpp fqlgy@li407-86:~/yaml-cpp$ make Scanning dependencies of target yaml_cpp_test [100%] Building CXX object CMakeFiles/yaml_cpp_test.dir/yaml_cpp_test.cpp.o Linking CXX executable yaml_cpp_test [100%] Built target yaml_cpp_test fqlgy@li407-86:~/yaml-cpp$ ./yaml_cpp_test HELLO 我确认某些版本的 yaml-cpp 库包含此问题(并且与不正确的链接无关)。 它相当脏,但我已经通过在代码中定义空函数来解决它,它看起来像 YAML::BadConversion::~BadConversion() { } void YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>) { } 该方法并不完美(例如,因为如果使用另一个库版本,它会导致重复)。 就我而言,我在两台计算机上运行完全相同的代码,但仅在其中一台计算机上出现错误,这几乎让我发疯。这不是编译错误、链接错误什么的,我认为代码很脏或者其他什么。 我尝试了所有选项: 从源代码常规构建并使用 cmake .. => make => make install 安装 与 1 相同,带有 CC=$(which gcc) CXX=$(which g++) cmake -DBUILD_SHARED_LIBS=ON .. 从 apt 卸载默认包(我使用 ubuntu 16.04) 全部失败,直到我找到 Ilya Golshtein 的答案,然后在我将使用 yaml-cpp 的代码中,我在YAML::LoadFIle行之前添加了这段代码 YAML::BadConversion::~BadConversion() { } void YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>) { } 这是唯一有效的解决方案 我来晚了,不知道我在做什么,但对于 Windows 上的用户,请确保您的 IDE 喜欢您的 mingw-g++。我的自动默认为草莓 Perl(?),当我将其更改为 mingw-g++ 时,一切都开始工作。我想这与版本控制有关? 这也困扰着我。我在 yaml-cpp 版本为“0.7.0”时遇到了它。我用“0.6.0”代替解决了这个问题。 就我而言,这是安装多个库的问题。我已经安装了 ROS,它似乎也随 yaml-cpp 一起提供。不同版本之间的冲突引发了未定义的引用错误。 卸载我添加的所有 yaml-cpp 版本解决了该问题。
我正在尝试将 libirimager 库中的 directshow 示例的一部分添加到我自己的 Qt 项目中。我无法链接 IRImager 类。 sdk 目录中只有头文件 IRImager.h。在我的 main.cpp 中,我刚刚添加了
我在创建库后运行多个文件时遇到问题,在本例中我将其称为“calcola.h”。 对我来说似乎没问题,但是错误“未定义的错误 somma,错误:ld
在构建 OpenMPL 项目时未定义对“boost::timer”库的引用
我正在尝试构建 OpenMPL 项目。但是,boost 库会发生一些错误 [ 99%] 链接 CXX 可执行文件 OpenMPL CMakeFiles/OpenMPL.dir/main.cpp.o:在函数“main”中: main.cpp:(.text.
我最终正在尝试构建和利用使用 MinGW 构建的 log4cxx 库。我已经用 MSYS2 和 MinGW 构建了它。但是,当我尝试使用(链接)它时,我得到了一堆未定义的引用......
我正在尝试从点云数据中使用 SurfaceReconstruction,这是我的代码 #包括 #包括 #包括 #包括 我正在尝试从点云数据中使用 SurfaceReconstruction,这是我的代码 #include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include <pcl/io/ply_io.h> #include <pcl/surface/marching_cubes_hoppe.h> int main(int argc, char** argv) { // Open the input text file std::ifstream input_file("prereq/model.txt"); // Create a PCL point cloud object to store the points pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // Parse the text file line by line to extract the point coordinates std::string line; while (std::getline(input_file, line)) { std::istringstream iss(line); float x, y, z; if (!(iss >> x >> y >> z)) { // Handle parsing error break; } // Add the point to the PCL point cloud object cloud->push_back(pcl::PointXYZ(x, y, z)); } // Create a set of triangular meshes using the Marching Cubes algorithm pcl::PolygonMesh triangles; pcl::MarchingCubesHoppe<pcl::PointXYZ> mc; mc.setInputCloud(cloud); mc.setIsoLevel(0.025); mc.reconstruct(triangles); pcl::io::savePLYFile("output_mesh.ply", triangles); return 0; } 当我尝试使用命令构建它时 g++ hmm.cpp -o a.out -I/usr/include/pcl-1.12/ -I/usr/include/eigen3 -lpcl_common -lpcl_io -lpcl_surface -lpcl_visualization -lpcl_octree -lpcl_recognition -lpcl_segmentation -lpcl_registration -lpcl_tracking -lpcl_search -lpcl_common -lpcl_surface -lpcl_kdtree -lpcl_features -lpcl_filters 它给了我错误 /usr/bin/ld: /tmp/ccPoS1h1.o: in function `main': hmm.cpp:(.text+0x2d1): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()' /usr/bin/ld: hmm.cpp:(.text+0x3ba): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x10): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x18): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::~MarchingCubesHoppe()' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x60): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PolygonMesh&)' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x68): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PointCloud<pcl::PointXYZ>&, std::vector<pcl::Vertices, std::allocator<pcl::Vertices> >&)' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x70): undefined reference to `pcl::MarchingCubesHoppe<pcl::PointXYZ>::voxelizeData()' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE[_ZTVN3pcl18MarchingCubesHoppeINS_8PointXYZEEE]+0x78): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::getGridValue(Eigen::Matrix<int, 3, 1, 0, 3, 1>)' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl13MarchingCubesINS_8PointXYZEEE[_ZTVN3pcl13MarchingCubesINS_8PointXYZEEE]+0x60): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PolygonMesh&)' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl13MarchingCubesINS_8PointXYZEEE[_ZTVN3pcl13MarchingCubesINS_8PointXYZEEE]+0x68): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::performReconstruction(pcl::PointCloud<pcl::PointXYZ>&, std::vector<pcl::Vertices, std::allocator<pcl::Vertices> >&)' /usr/bin/ld: /tmp/ccPoS1h1.o:(.data.rel.ro._ZTVN3pcl13MarchingCubesINS_8PointXYZEEE[_ZTVN3pcl13MarchingCubesINS_8PointXYZEEE]+0x78): undefined reference to `pcl::MarchingCubes<pcl::PointXYZ>::getGridValue(Eigen::Matrix<int, 3, 1, 0, 3, 1>)' collect2: error: ld returned 1 exit status 我什至尝试过 cmake cmake_minimum_required(VERSION 3.10) project(pointcloud-to-mesh) find_package(PCL 1.12 REQUIRED COMPONENTS common io surface) add_executable(pointcloud-to-mesh hmm.cpp) target_include_directories(pointcloud-to-mesh PRIVATE ${PCL_INCLUDE_DIRS}) target_link_libraries(pointcloud-to-mesh PRIVATE ${PCL_LIBRARIES}) GreedyProjectionTriangulation 和 Poisson 的相同类型的错误。 我在这里做错了什么?我使用 apt 安装了 pcl(我在 ubuntu 上) 不能将MarchingCubesHoppe与pcl::PointXYZ一起使用。你必须使用pcl::PointNormal或pcl::PointXYZRGBNormal或pcl::PointXYZINormal. 另见官方文档:https://pointclouds.org/documentation/classpcl_1_1_marching_cubes_hoppe.html#details