混合CPP OpenCV /主程序C.

时间:2014-11-23 20:48:54

标签: c++ c compilation cmake

我有一个基于C的主项目,我需要包含一个CPP功能(使用OpenCV)。 我正在使用Cmake文件来执行此操作,但是当我添加cpp文件时,它不再起作用。

这是我的Makefile

    cmake_minimum_required (VERSION 2.8.9)

project(tictactoe)

### Requierements

    find_package(OpenCV REQUIRED )
    include_directories(../Sources)
include_directories(${OpenCV_INCLUDE_DIRS})
    include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
### Subdirectories where the sources are

    FILE(GLOB MyCSources "../Sources/*.c")
ADD_LIBRARY(detect_tag ../Sources/detect_tag.cpp ../Sources/detect_tag.hpp)
ADD_EXECUTABLE(tictactoe  ${MyCSources} ../Sources/detect_tag.cpp ../Sources/detect_tag.hpp)

TARGET_LINK_LIBRARIES(tictactoe rt  ${CMAKE_THREAD_LIBS_INIT} ${OpenCV_LIBS})

1 个答案:

答案 0 :(得分:0)

好的,我使用包装器解决了我的问题: 我已经创建了一个像wrapper.h和wrapper.cpp这样的头文件。

在wrapper.h中我得到了:

extern "C" my_function_through_wrapper();
在包装器中的

我得到了:

#include file_where_my_function_if.h
extern "c" { 

my_function_through_wrapper(){
         my_function();
}

}

那就是它! 事实上,我已经在真实的CPP和C代码之间建立了接口。使用extern C我的编译器知道如何编译包装文件,我的C代码可以链接到它。然后通过包装器,可以使用CPP中包含的所有库,将CPP链接到其他CPP代码。解决了 !

相关问题