I'm developing a dynamic library that will be linked on both Windows and Linux softwares. In order to simplify the build operation I decided to use cmake.
我正在开发一个动态库,可以在Windows和Linux软件上链接。为了简化构建操作,我决定使用cmake。
The library has the following structure:
图书馆的结构如下:
MyProject
└ Subproject_1
| └ ...
| └ CMakeLists.txt
└ Subproject_2
| └ ...
| └ CMakeLists.txt
└ ...
└ CMakeLists.txt
In the Subproject_1 I used Eigen 3.3 (I downloaded the latest release) and OpenCV 3.3.0.
在Subproject_1中,我使用了Eigen 3.3(我下载了最新的版本)和OpenCV 3.3.0。
The main CMakeLists file is this
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")
while the Subproject_1 CMakeLists file is
虽然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}
)
Now, when I compile the project on Windows all work properly, but if I try to compile it on Ubuntu 16.04 LTS I have this errors:
现在,当我在Windows上编译这个项目时,一切都运行正常,但是如果我试图在Ubuntu 16.04 LTS上编译它,我有以下错误:
... 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);
^
I'm pretty sure that the problem is not due to cmake, but I didn't find anything on Google or here that help me to solve it. Furthermore, I tried to follow the Eigen official instructions but they not works for me on Windows.
我很确定问题不是由cmake引起的,但是我在谷歌或这里没有找到任何能帮助我解决它的东西。此外,我试着遵循本征的官方指示,但它们对我在Windows上不适用。
To be precise, I'm using:
确切地说,我正在使用:
- on Windows: Visual Studio 2017, make version 3.8 and Ninja
- 在Windows: Visual Studio 2017,制作3.8和Ninja版本
- on Ubuntu: make version 4.1
- Ubuntu:制作4.1版本
The library and the Eigen files are the same on the two OSs since I'm sharing the workspace directory containing the two repositories, and I've already tried to use Ninja also on Ubuntu.
两个OSs上的库和特征文件是相同的,因为我正在共享包含两个储存库的工作空间目录,并且我已经尝试在Ubuntu上使用忍者。
Every suggestion is welcome
每一个建议是受欢迎的
1 个解决方案
#1
2
You must avoid using not
and and
as variable names under Linux, you should just rename them to something else for your code to compile.
您必须避免在Linux下使用not和作为变量名,您应该将它们重命名为其他名称,以便您的代码进行编译。
They are actually C++ keywords (see here), which causes problems under Linux. Visual Studio does not recognize them, which explains why the compilation works under Windows. See this SO question for details.
它们实际上是c++关键字(参见这里),在Linux下会导致问题。Visual Studio不识别它们,这解释了为什么编译在Windows下工作。详情请参见这个问题。
#1
2
You must avoid using not
and and
as variable names under Linux, you should just rename them to something else for your code to compile.
您必须避免在Linux下使用not和作为变量名,您应该将它们重命名为其他名称,以便您的代码进行编译。
They are actually C++ keywords (see here), which causes problems under Linux. Visual Studio does not recognize them, which explains why the compilation works under Windows. See this SO question for details.
它们实际上是c++关键字(参见这里),在Linux下会导致问题。Visual Studio不识别它们,这解释了为什么编译在Windows下工作。详情请参见这个问题。