Building OCE on linux for mingw

94 views
Skip to first unread message

Ben Hollingsworth

unread,
Jun 8, 2016, 1:09:31 AM6/8/16
to oce-dev
I'm trying to use OCE 0.17.1 in our multi-platform software package.  Our software runs on both Linux and Windows (32- & 64-bit for both), but all four platforms are built on linux development stations using gcc.  The Windows builds are compiled using MinGW compilers.  Our company has been using mingw for years, but I haven't had to deal with it myself.  Nobody here, including me, has any prior experience with cmake.

I've gotten OCE built for linux easily enough, and it seems to link with our software & run just fine.  However, I'm having trouble building the Windows version of OCE with MinGW on our linux boxen.  Due to licensing constraints, I need to build shared DLL's for OCE rather than linking it into our software statically.  I've created what I think should be appropriate cmake files that describe our mingw build environment, but when OCE compiles, the resulting libraries are all ELF shared libs with a .so extension.  I'm having a hard time figuring out how to force it to build Windows DLL's.  Our company has been using mingw for years, but I haven't had to deal with it myself.  Nobody here, including me, has any prior experience with cmake.

Has anybody build OCE for Windows DLL's using a linux platform with mingw?  How did you do it?

Below is the cmake file that I'm using to configure the 64-bit Windows build:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON  CACHE BOOL "Show compiler commands" FORCE)
set(CMAKE_SYSTEM_NAME gcc)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_FORCE_CXX_COMPILER "x86_64-w64-mingw32-g++"    CACHE FILEPATH "CXX compiler" FORCE)
set(CMAKE_FORCE_C_COMPILER   "x86_64-w64-mingw32-gcc"    CACHE FILEPATH "C compiler" FORCE)
set(CMAKE_RANLIB       "x86_64-w64-mingw32-ranlib" CACHE FILEPATH "Path to a program." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-shared --enable-runtime-pseudo-reloc" CACHE STRING "Flags used by the linker during the creation of dll's." FORCE)
set(CMAKE_FORCE_CXX_FLAGS "-fmessage-length=0 -fno-strict-aliasing -fno-stack-protector -DMINGW -DUNICODE -D_WIN32_WINNT=0x0500 -D_DWFCORE_WIN32_SYSTEM -D__MINGW32__ -Wno-deprecated -DOD_STD_ALLOCATOR_AS_IS" CACHE STRING "Flags used by the compiler during all build types." FORCE)
set(CMAKE_FORCE_C_FLAGS   "-fmessage-length=0 -fno-strict-aliasing -fno-stack-protector -DMINGW -DUNICODE -D_WIN32_WINNT=0x0500 -D_DWFCORE_WIN32_SYSTEM -D__MINGW32__ -DOD_STD_ALLOCATOR_AS_IS" CACHE STRING "Flags used by the compiler during all build types." FORCE)
set(FREETYPE_INCLUDE_DIR_freetype2 /usr/include/freetype2                                                    CACHE PATH "the path of freetype2" FORCE)
set(FREETYPE_INCLUDE_DIR_ft2build  /usr/lib/sds2/thirdparty-libs-for-sds2-2015/win64-gcc46/include           CACHE PATH "the path of ft2build.h" FORCE)
set(FREETYPE_LIBRARY               /usr/lib/sds2/thirdparty-libs-for-sds2-2015/lib/win64-gcc46/libfreetype.a CACHE FILEPATH "freetype library" FORCE)
set(OPENGL_INCLUDE_DIR             /usr/x86_64-w64-mingw32/include/GL                                          CACHE PATH "path to OpenGL includes" FORCE)
set(OPENGL_gl_LIBRARY              /usr/x86_64-w64-mingw32/lib/libopengl32.a                                   CACHE FILEPATH "path to OpenGL library" FORCE)
set(OPENGL_glu_LIBRARY             /usr/x86_64-w64-mingw32/lib/libglu32.a                                      CACHE FILEPATH "path to OpenGL library" FORCE)
set(OCE_INSTALL_PREFIX /tmp/oce/win64 CACHE PATH "Directory that will contain install files of OCCT" FORCE)
set(OCE_VISUALISATION          OFF CACHE BOOL "include Visualization" FORCE)
set(OCE_TESTING                OFF CACHE BOOL "Enable unittesting framework" FORCE)
set(OCE_DISABLE_TKSERVICE_FONT ON  CACHE BOOL "Disable TKService Font (only without Visualization)" FORCE)
set(INSTALL_FREETYPE OFF CACHE BOOL "Is freetype required to be copied into install directory" FORCE)
set(INSTALL_TCL      OFF CACHE BOOL "Is tcl lib required to be copied into install directory" FORCE)
set(INSTALL_TESTS    OFF CACHE BOOL "Is tests copy to install directory" FORCE)
set(INSTALL_VTK      OFF CACHE BOOL "Is vtk required to be copied into install directory" FORCE)
set(USE_FREEIMAGE OFF CACHE BOOL "Is freeimage used or not" FORCE)
set(USE_GL2PS     OFF CACHE BOOL "Is gl2ps used or not" FORCE)
set(USE_OPENCL    OFF CACHE BOOL "Is OpenCL used or not" FORCE)
set(USE_TBB       OFF CACHE BOOL "Is tbb used or not" FORCE)
set(USE_VTK       OFF CACHE BOOL "Is VTK used or not" FORCE)

Thomas Paviot

unread,
Jun 8, 2016, 2:16:21 AM6/8/16
to oce...@googlegroups.com
Hi  Ben,

I think this is the first cross compilation related thread, thanks for posting.

I never experienced cross compiling, did you have a loook at the official tutorial http://www.vtk.org/Wiki/CMake_Cross_Compiling ? It suggests to set the CMAKE_SYSTEM_NAME variable to the target system, e.g. Linux or Windows, whereas you define it as "gcc". Did you try to set it to Windows instead ?

Thomas

--
You received this message because you are subscribed to the Google Groups "oce-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oce-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Paviot

unread,
Jun 8, 2016, 2:19:32 AM6/8/16
to oce...@googlegroups.com
You should also read this page http://www.vtk.org/Wiki/CmakeMingw

Richard Shaw

unread,
Jun 8, 2016, 9:10:18 AM6/8/16
to oce...@googlegroups.com
I'm not sure what linux distro you're building from but Fedora has a very nice mingw setup which I have used with very few issues although I have not attempted to cross compile OCE.

It provides both a cmake toolchain file (contents below) and wrappers to setup the environment (mingw32-cmake, mingw64-cmake).

$ cat /usr/share/mingw/toolchain-mingw32.cmake
SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_SYSTEM_PROCESSOR x86)

# specify the cross compiler
SET(CMAKE_C_COMPILER /usr/bin/i686-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/i686-w64-mingw32-g++)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32/sys-root/mingw)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Make sure Qt can be detected by CMake
SET(QT_BINARY_DIR /usr/i686-w64-mingw32/bin /usr/bin)

# set the resource compiler (RHBZ #652435)
SET(CMAKE_RC_COMPILER /usr/bin/i686-w64-mingw32-windres)

# These are needed for compiling lapack (RHBZ #753906)
SET(CMAKE_Fortran_COMPILER /usr/bin/i686-w64-mingw32-gfortran)
SET(CMAKE_AR:FILEPATH /usr/bin/i686-w64-mingw32-ar)
SET(CMAKE_RANLIB:FILEPATH /usr/bin/i686-w64-mingw32-ranlib)

HTH!

Richard

Richard Shaw

unread,
Jun 8, 2016, 10:00:41 AM6/8/16
to oce...@googlegroups.com
Ok, just successfully built OCE using mingw on Fedora, the only option I had to set was OCE_INSTALL_PREFIX as it defaults to a "C:\" type value, this could probably be detected using the CMAKE_CROSSCOMPILING variable and set to something more appropriate.

Thanks,
Richard

Boris Pek

unread,
Jun 8, 2016, 11:09:48 AM6/8/16
to oce...@googlegroups.com
Hi everyone,

> Has anybody build OCE for Windows DLL's using a linux platform with mingw?  How did you do it?

Yes. http://mxe.cc/

Best wishes,
Boris
Reply all
Reply to author
Forward
0 new messages