链接器在 macos 上找不到特征符号

Linker can't find Eigen symbols on macos

提问人:YHD 提问时间:10/27/2023 最后编辑:YHD 更新时间:11/2/2023 访问量:103

问:

我正在尝试编写一个程序,并使用了一些 Eigen 功能。当我尝试运行它时,我在下图中出现错误,说“未定义的架构符号x86_64”和“ld:找不到架构x86_64的符号”。由于 Eigen 是一个仅标头库链接器,因此在我看来不应该处理它,但我收到错误并且无法修复它。我安装了带有 brew 的 Eigen,我的 mac 有英特尔处理器。 下面是我的CMakeLists,.txt和错误输出。

cmake_minimum_required(VERSION 3.25)

project(testCDMTrack)

set(CMAKE_CXX_STANDARD 17)

find_package(PkgConfig REQUIRED)
#find_package(Eigen3 CONFIG REQUIRED)
find_package(OpenCV REQUIRED)
#find_package(jsoncpp CONFIG REQUIRED)

set(EIGEN_ROOT_DIR "/usr/local/include/eigen3/")

include_directories(
        ${EIGEN_ROOT_DIR}
)
add_executable(testCDMTrack main.cpp CircularEdgeSampler.h CircularEdgeSampler.cpp)

target_link_libraries(testCDMTrack PRIVATE ${OpenCV_LIBS})

我试图将 Eigen 作为 pkgconfig 提供,并且我还尝试通过 CMake 标志向目录显示,但是。无法让它工作。此外,我在这里检查了大多数答案是否有类似的问题,但没有一个答案对我有用。

这是 CircularEdgeSampler.sample 在 main 中的用法。

int temp = CESampler.sample(rotationMatrices[idx], translation, _edges, samples);

这是头文件。

#ifndef TESTCDMTRACK_CIRCULAREDGESAMPLER_H
#define TESTCDMTRACK_CIRCULAREDGESAMPLER_H

#include <vector>
#include "type.h"
#include <Eigen/Core>

class CircularEdgeSampler {
public:
    int sample(Matrix33f& rotation, Eigen::Vector3f& translation, std::vector<Circle3f> _edges, std::vector<EdgeSample>& samples);
};


#endif //TESTCDMTRACK_CIRCULAREDGESAMPLER_H

这就是 In the Source 的定义。


#include "CircularEdgeSampler.h"

using namespace Eigen;

int CircularEdgeSampler::sample(Matrix33f& rotation, Eigen::Vector3f& translation, std::vector<Circle3f> _edges, std::vector<EdgeSample>& samples)
{
}

我削减了定义,以免占用太多空间。

这是错误。

====================[ Build | all | Debug ]=====================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/yusufdurkaya/CLionProjects/testCDMTrack/cmake-build-debug --target all -j 14
[1/3] Building CXX object CMakeFiles/testCDMTrack.dir/CircularEdgeSampler.cpp.o
In file included from /Users/yusufdurkaya/CLionProjects/testCDMTrack/CircularEdgeSampler.cpp:5:
In file included from /Users/yusufdurkaya/CLionProjects/testCDMTrack/CircularEdgeSampler.h:9:
In file included from /Users/yusufdurkaya/CLionProjects/testCDMTrack/type.h:8:
In file included from /usr/local/include/eigen3/Eigen/Core:273:
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:390:5: warning: inline function 'Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0>>::cross<Eigen::Matrix<float, 3, 1, 0>>' is not defined [-Wundefined-inline]
    cross(const MatrixBase<OtherDerived>& other) const;
    ^
/Users/yusufdurkaya/CLionProjects/testCDMTrack/CircularEdgeSampler.cpp:70:41: note: used here
        secondBaseVector = normalVector.cross(firstBaseVector);
                                        ^
1 warning generated.
[3/3] Linking CXX executable testCDMTrack
FAILED: testCDMTrack 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mmacosx-version-min=13.0 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/testCDMTrack.dir/main.cpp.o CMakeFiles/testCDMTrack.dir/CircularEdgeSampler.cpp.o -o testCDMTrack  -Wl,-rpath,/usr/local/lib  /usr/local/lib/libopencv_gapi.4.8.1.dylib  /usr/local/lib/libopencv_stitching.4.8.1.dylib  /usr/local/lib/libopencv_alphamat.4.8.1.dylib  /usr/local/lib/libopencv_aruco.4.8.1.dylib  /usr/local/lib/libopencv_bgsegm.4.8.1.dylib  /usr/local/lib/libopencv_bioinspired.4.8.1.dylib  /usr/local/lib/libopencv_ccalib.4.8.1.dylib  /usr/local/lib/libopencv_dnn_objdetect.4.8.1.dylib  /usr/local/lib/libopencv_dnn_superres.4.8.1.dylib  /usr/local/lib/libopencv_dpm.4.8.1.dylib  /usr/local/lib/libopencv_face.4.8.1.dylib  /usr/local/lib/libopencv_freetype.4.8.1.dylib  /usr/local/lib/libopencv_fuzzy.4.8.1.dylib  /usr/local/lib/libopencv_hfs.4.8.1.dylib  /usr/local/lib/libopencv_img_hash.4.8.1.dylib  /usr/local/lib/libopencv_intensity_transform.4.8.1.dylib  /usr/local/lib/libopencv_line_descriptor.4.8.1.dylib  /usr/local/lib/libopencv_mcc.4.8.1.dylib  /usr/local/lib/libopencv_quality.4.8.1.dylib  /usr/local/lib/libopencv_rapid.4.8.1.dylib  /usr/local/lib/libopencv_reg.4.8.1.dylib  /usr/local/lib/libopencv_rgbd.4.8.1.dylib  /usr/local/lib/libopencv_saliency.4.8.1.dylib  /usr/local/lib/libopencv_sfm.4.8.1.dylib  /usr/local/lib/libopencv_stereo.4.8.1.dylib  /usr/local/lib/libopencv_structured_light.4.8.1.dylib  /usr/local/lib/libopencv_superres.4.8.1.dylib  /usr/local/lib/libopencv_surface_matching.4.8.1.dylib  /usr/local/lib/libopencv_tracking.4.8.1.dylib  /usr/local/lib/libopencv_videostab.4.8.1.dylib  /usr/local/lib/libopencv_viz.4.8.1.dylib  /usr/local/lib/libopencv_wechat_qrcode.4.8.1.dylib  /usr/local/lib/libopencv_xfeatures2d.4.8.1.dylib  /usr/local/lib/libopencv_xobjdetect.4.8.1.dylib  /usr/local/lib/libopencv_xphoto.4.8.1.dylib  /usr/local/lib/libopencv_shape.4.8.1.dylib  /usr/local/lib/libopencv_highgui.4.8.1.dylib  /usr/local/lib/libopencv_datasets.4.8.1.dylib  /usr/local/lib/libopencv_plot.4.8.1.dylib  /usr/local/lib/libopencv_text.4.8.1.dylib  /usr/local/lib/libopencv_ml.4.8.1.dylib  /usr/local/lib/libopencv_phase_unwrapping.4.8.1.dylib  /usr/local/lib/libopencv_optflow.4.8.1.dylib  /usr/local/lib/libopencv_ximgproc.4.8.1.dylib  /usr/local/lib/libopencv_video.4.8.1.dylib  /usr/local/lib/libopencv_videoio.4.8.1.dylib  /usr/local/lib/libopencv_imgcodecs.4.8.1.dylib  /usr/local/lib/libopencv_objdetect.4.8.1.dylib  /usr/local/lib/libopencv_calib3d.4.8.1.dylib  /usr/local/lib/libopencv_dnn.4.8.1.dylib  /usr/local/lib/libopencv_features2d.4.8.1.dylib  /usr/local/lib/libopencv_flann.4.8.1.dylib  /usr/local/lib/libopencv_photo.4.8.1.dylib  /usr/local/lib/libopencv_imgproc.4.8.1.dylib  /usr/local/lib/libopencv_core.4.8.1.dylib && :
Undefined symbols for architecture x86_64:
  "Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >::cross_product_return_type<Eigen::Matrix<float, 3, 1, 0, 3, 1> >::type Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >::cross<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&) const", referenced from:
      CircularEdgeSampler::sample(Eigen::Matrix<float, 3, 3, 2, 3, 3>&, Eigen::Matrix<float, 3, 1, 0, 3, 1>&, std::__1::vector<Circle3f, std::__1::allocator<Circle3f> >, std::__1::vector<EdgeSample, std::__1::allocator<EdgeSample> >&) in CircularEdgeSampler.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

C++ macOS CMake 特征

评论

2赞 jlx 10/27/2023
请复制并粘贴您的CMakeLists,.txt而不是拍照
1赞 n. m. could be an AI 10/27/2023
“我在下图中得到错误”下面没有图像。请将您的错误粘贴为文本。
1赞 Botje 10/27/2023
请显示错误和导致错误的最小代码量。您原始帖子中的屏幕截图遗漏了非常重要的细节。
1赞 Botje 10/27/2023
编译器和链接器不同意。请使用 CircularEdgeSampler::sample 方法的声明和定义以及使用它的位置和错误以文本形式编辑您的问题。
2赞 chtz 10/28/2023
这仍然不是一个最小的可重现示例,但是有足够多的错误消息,我可以告诉您,您需要。#include <Eigen/Geometry>

答: 暂无答案