跨平台项目中的eigen错误

Error with Eigen in cross-platform project

本文关键字:eigen 错误 项目 跨平台      更新时间:2023-10-16

我正在开发一个动态库,该库将在Windows和Linux软件上链接。为了简化构建操作,我决定使用 cmake

库具有以下结构:

MyProject
└ Subproject_1
| └ ...
| └ CMakeLists.txt
└ Subproject_2
| └ ...
| └ CMakeLists.txt
└ ...
└ CMakeLists.txt

subproject_1 中我使用 eigen 3.3 (我下载了最新版本(和 opencv 3.3.0

主要的cmakelists文件是此

cmake_minimum_required (VERSION 2.8)
SET(CMAKE_CXX_STANDARD 11)
project (MyProject)
## Output directory configuration
SET(out_dir ./)
SET(EXECUTABLE_OUTPUT_PATH ${out_dir}../lib/ CACHE PATH "Build directory" FORCE)
SET(LIBRARY_OUTPUT_PATH ${out_dir}../lib/ CACHE PATH "Build directory" FORCE)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${out_dir}../lib)
SET(CMAKE_BUILD_FILES_DIRECTORY ${out_dir})
SET(CMAKE_BUILD_DIRECTORY ${out_dir})
SET(CMAKE_BINARY_DIR  ${out_dir})
SET(CMAKE_CACHEFILE_DIR ${out_dir})
SET(opencv_path "")
if (WIN32 OR MSVC OR MSYS OR MINGW)
  SET(opencv_path "../opencv-3.3.0/build64/")
endif()
message("Setted OpenCV path to '" ${opencv_path} "'")
find_package(OpenCV REQUIRED PATHS ${opencv_path}
    opencv_core opencv_features2d opencv_flann opencv_highgui opencv_imgcodecs opencv_imgproc opencv_photo opencv_plot opencv_xfeatures2d opencv_ml opencv_video
)
# Additional dependencies
include_directories(
  ${OPENCV_INCLUDE_DIRS}
  "../eigen/"
  "Subprojects_1/include"
  "Subprojects/include"
)
## Subprojects
add_subdirectory ("Subproject_1")
add_subdirectory ("Subproject_2")

subproject_1 cmakelists文件是

cmake_minimum_required (VERSION 2.8)
project(Subproject_1)
file (GLOB core_file "include/*.h" "src/*.cpp")
add_library(library SHARED ${core_file})
target_link_libraries(library 
  ${OpenCV_LIBRARIES}
)

现在,当我在Windows上编译该项目时,都可以正常工作,但是如果我尝试在Ubuntu 16.04 LT上进行编译,我有此错误:

... error: cannot declare reference to ‘Eigen::MatrixXi& {aka class Eigen::Matrix<int, -1, -1>&}’, which is not a typedef or a template type argument
   static void bitwiseAND(const Eigen::MatrixXi& m1, const Eigen::MatrixXi& m2, Eigen::MatrixXi& and);
                                                                                                 ^
... error: cannot declare reference to ‘Eigen::MatrixXi& {aka class Eigen::Matrix<int, -1, -1>&}’, which is not a typedef or a template type argument
   static void bitwiseNOT(const Eigen::MatrixXi& m, Eigen::MatrixXi& not);
                                                                     ^

我很确定问题不是归因于CMake,但是我在Google上没有任何东西,或者在这里可以帮助我解决它。此外,我试图按照特征官方说明进行操作,但它们在Windows上不起作用。

确切地说,我正在使用:

  • 在Windows上:Visual Studio 2017,制作3.8版和Ninja
  • 在Ubuntu上:制作版本4.1

由于我共享包含两个存储库的工作区目录,因此库和特征文件是相同的,而且我已经尝试在ubuntu上也尝试使用忍者。

欢迎每个建议

您必须避免使用notand作为Linux下的变量名称,您应该将它们重命名为其他内容以进行编译。

它们实际上是C 关键字(请参阅此处(,在Linux下引起问题。Visual Studio无法识别它们,这解释了为什么汇编在Windows下工作的原因。有关详细信息,请参阅此问题。