2

Behold: My Cmakelists.txt file

project(facedetectlib)
cmake_minimum_required(VERSION 2.8)
include (GenerateExportHeader)

SET(CMAKE_VERBOSE_MAKEFILE TRUE)

file(GLOB HEADER_LIST ./include/*.h)
include_directories(./include)

aux_source_directory(. SRC_LIST)

find_package(OpenCV REQUIRED )

# Allow the developer to select if Dynamic or Static libraries are built
OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
# Set the LIB_TYPE variable to STATIC
SET (LIB_TYPE STATIC)
IF (BUILD_SHARED_LIBS)
  # User wants to build Dynamic Libraries, so change the LIB_TYPE variable to CMake keyword 'SHARED'
  SET (LIB_TYPE SHARED)
ENDIF (BUILD_SHARED_LIBS)

add_library(ocvfacedetectlib ${LIB_TYPE}  ${SRC_LIST} ${HEADER_LIST})
target_link_libraries(ocvfacedetectlib ${OpenCV_LIBS})
GENERATE_EXPORT_HEADER( ocvfacedetectlib
             BASE_NAME ocvfacedetectlib
             EXPORT_MACRO_NAME ocvfacedetectlib_EXPORT
             EXPORT_FILE_NAME ocvfacedetectlib_Export.h
             STATIC_DEFINE ocvfacedetectlib_BUILT_AS_STATIC
)

Using this cmake file and piecing together some instructions from here:

http://www.cmake.org/Wiki/BuildingWinDLL

I am trying to figure out if the DLL is getting built correctly. My header file for my little library has the following in it:

#include "ocvfacedetectlib_Export.h"
typedef unsigned char uint8_t;
extern "C" {
ocvfacedetectlib_EXPORT uint8_t * facedetect( uint8_t *imageData, long buffsize,  unsigned char *retbuffer );
}

And then I have in my .cpp file this:

ocvfacedetectlib_EXPORT uint8_t * facedetect( uint8_t *imageData, long buffsize, unsigned char *retbuffer )
{ ..do stuff using OpenCV
 ...}

This seems to be enough to generate a DLL but I am not sure if it is being built correctly - I am unable to load it use js.ctypes() which is what I am trying to do as my end goal.

For what it's worth—my .cpp has a main() method as well and when I build the code to an .exe it runs.

What is the proper way to generate a windows DLL from a CMake project for later versions of CMake than 2.8, and what has to be changed in the source code to make it work?

Noitidart
  • 35,443
  • 37
  • 154
  • 323
Derek
  • 11,715
  • 32
  • 127
  • 228
  • I understand what you're asking, but could you edit your question such that it includes an actual question? – Greg Kramida Feb 27 '15 at 21:21
  • I would first make a small C executable target that's trying to use the library and make sure it can make use of exported library functions OK, you can even add another tiny test function to your library to do so. If the library can be used by the executable, it's some compatibility problem, but your library is fine. – Greg Kramida Feb 27 '15 at 21:37
  • I don't understand what you're asking, but if you a js-ctypes question (which is ctypes from priveagled javascript in firefox) let me know. :) – Noitidart Feb 28 '15 at 00:02
  • well, it's probably a separate thread at this point, but in general I do have a question how on debugging problems like when ctypes fails to load a dll in general. this has happened to me before as well, and I stumbled into a fix that time. – Derek Feb 28 '15 at 19:17
  • Side note: the whole dance with `LIB_TYPE` is unnecessary. You're exactly duplicating CMake behaviour when `BUILD_SHARED_LIBS` is used and *no type* (neither `STATIC` nor `SHARED`) is specified in the `add_library()` call. – Angew is no longer proud of SO Mar 02 '15 at 07:57

0 Answers0