0

I'm trying to compile a shared library with cmake to use it further with the "dlfcn" lib in a C program. I am on Windows with Cygwin, but I don't know how to use "dlfcn" with the shared libraries of windows (.dll and .dll.a) and my teammates are using Linux. So I would like to create not .dll and .dll.a libraires but a .so library. I'm a beginner with cmake, is there a possibility to do it or am I obliged to install a Linux VM ?

Damien
  • 33
  • 8
  • Welcome to StackOverflow. You're asking for a [toolchain](https://cmake.org/cmake/help/v3.5/manual/cmake-toolchains.7.html) to [crosscompile](http://www.vtk.org/Wiki/CMake_Cross_Compiling). Which Linux distribution and version do we talk about? And - for convenience - you may want to take a look at [VisualGDB](http://visualgdb.com/tutorials/linux/cmake/). – Florian Apr 13 '16 at 07:30
  • Thanks a lot @Florian , it worked :) I added a .cmake file with minimal configuration to compile as a Linux program ( _set(CMAKE_SYSTEM_NAME Linux) (and few other optional things)_ ), and my librairies are now .so. NB : my teammates are working on Gnome. – Damien Apr 14 '16 at 07:42
  • You're welcome. You could just [self answer](http://stackoverflow.com/help/self-answer) your question and add the toolchain file info that worked for you. It might help other StackOverflow users with a similar problem in the future. For an example on moving things to a toolchain file see [here](http://stackoverflow.com/questions/33053840/converting-a-makefile-to-cmakelists-txt-for-tiva-c-series/33080132#33080132). – Florian Apr 14 '16 at 07:48

1 Answers1

1

So, thanks to @Florian, I finally made it. To the ones who want to know how it works, it's quite simple :

  • Create a new .cmake file :

    # this mandatory command will be the one that will make your cross-compiling work
    set(CMAKE_SYSTEM_NAME Linux)
    
    # indicate compilers (optional)
    set(CMAKE_C_COMPILER gcc)
    set(CMAKE_CXX_COMPILER g++)
    
  • When calling your cmake command, add an argument like this :

    cmake -DCMAKE_TOOLCHAIN_FILE=./myToolChainFile.cmake ..
    
Damien
  • 33
  • 8