[CMake] Can't get CMake to use an import library generated from a MODULE target

Sam Habiel sam.habiel at gmail.com
Fri Feb 19 04:10:55 EST 2016


Thank you all for your help. I ran a quick experiment to see what's what:

MODULE:
[ 91%] Linking C shared module cyggtmshr.dll
/usr/local/bin/cmake.exe -E cmake_link_script
CMakeFiles/libgtmshr.dir/link.txt --verbose=1
/usr/bin/cc   -march=i586 -fsigned-char -Wmissing-prototypes
-Wreturn-type -Wpointer-sign -fno-omit-frame-pointer -g -DDEBUG
-Wl,-u,gtm_ci -Wl,-u,gtm_filename_to_id
-Wl,--version-script,"/home/sam/fis-gtm-cygwin/gtmshr_symbols.export"
-Wl,--out-implib=libgtmshr.lib -shared -Wl,--enable-auto-import -o
cyggtmshr.dll -Wl,--major-image-version,0,--minor-image-version,0
CMakeFiles/libgtmshr.dir/sr_unix/gtm_main.c.o libmumps.a
libgnpclient.a libcmisockettcp.a -lncurses -lm -ldl -lc -lpthread -lrt

SHARED:
[ 91%] Linking C shared library cyggtmshr.dll
/usr/local/bin/cmake.exe -E cmake_link_script
CMakeFiles/libgtmshr.dir/link.txt --verbose=1
/usr/bin/cc   -march=i586 -fsigned-char -Wmissing-prototypes
-Wreturn-type -Wpointer-sign -fno-omit-frame-pointer -g -DDEBUG
-Wl,-u,gtm_ci -Wl,-u,gtm_filename_to_id
-Wl,--version-script,"/home/sam/fis-gtm-cygwin/gtmshr_symbols.export"
-Wl,--out-implib=libgtmshr.lib -shared -Wl,--enable-auto-import -o
cyggtmshr.dll -Wl,--out-implib,libgtmshr.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
CMakeFiles/libgtmshr.dir/sr_unix/gtm_main.c.o libmumps.a
libgnpclient.a libcmisockettcp.a -lncurses -lm -ldl -lc -lpthread -lrt

If you look carefully, you will see the they are identical, except
that shared exports an Import Library libgtmshr.dll.a. The solution to
my problems!
The other --out-implib=libgtmshr.lib is hardcoded by myself.

On Thu, Feb 18, 2016 at 1:04 AM, Petr Kmoch <petr.kmoch at gmail.com> wrote:
> Then I would suggest something like
>
> if(CYGWIN)
>   set(libType SHARED)
> else()
>   set(libType MODULE)
> endif()
>
> add_library(TheProblematicOne ${libType} ...)
>
> Petr
>
> On Thu, Feb 18, 2016 at 9:59 AM, Sam Habiel <sam.habiel at gmail.com> wrote:
>>
>> https://cmake.org/cmake/help/v3.0/command/add_library.html
>>
>> The module library (libgtmshr) is dlopened from the main exe. It's not
>> supposed to be linked, except for Cygwin.
>>
>>
>> On Thursday, February 18, 2016, Mueller-Roemer, Johannes Sebastian
>> <Johannes.Sebastian.Mueller-Roemer at igd.fraunhofer.de> wrote:
>>>
>>> Why are you trying to link a MODULE? The add_library should be changed to
>>> SHARED not MODULE.
>>>
>>> --
>>> Johannes S. Mueller-Roemer, MSc
>>> Wiss. Mitarbeiter - Interactive Engineering Technologies (IET)
>>>
>>> Fraunhofer-Institut für Graphische Datenverarbeitung IGD
>>> Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
>>> Tel +49 6151 155-606  |  Fax +49 6151 155-139
>>> johannes.mueller-roemer at igd.fraunhofer.de  |  www.igd.fraunhofer.de
>>>
>>>
>>> -----Original Message-----
>>> From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Sam Habiel
>>> Sent: Thursday, February 18, 2016 09:45
>>> To: cmake at cmake.org
>>> Subject: [CMake] Can't get CMake to use an import library generated from
>>> a MODULE target
>>>
>>> Rather than email one of the folks at Kitware, I decided to join the
>>> CMake mailing list... Hello all for those who remember me.
>>>
>>> I apologize for the long email.
>>>
>>> A few of us have been trying to port GT.M
>>> (https://www.fisglobal.com/Solutions/Services/Database-Engine) to Cygwin,
>>> 1. to get it running on Windows 2. as an exercise to prepare for harder
>>> ports, the Raspberry Pi being the holy grail here. That's the background.
>>>
>>> The problem we are having is familiar to many; but not initially to me.
>>> See the heading "Shared libraries with Windows/MinGW" in this
>>> article:
>>> http://gernotklingler.com/blog/creating-using-shared-libraries-different-compilers-different-operating-systems/.
>>>
>>> CMakeLists.txt:
>>> https://github.com/shabiel/fis-gtm/blob/cygwin/CMakeLists.txt
>>>
>>> The error:
>>> [ 88%] Linking C shared module plugin/cyggtmcrypt_gcrypt_AES256CFB.dll
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/sr_unix/gtmcrypt_util.c.o:
>>> In function `gc_load_gtmshr_symbols':
>>> /home/sam/fis-gtm-cygwin/sr_unix/gtmcrypt_util.c:100: undefined reference
>>> to `gtm_malloc'
>>> /home/sam/fis-gtm-cygwin/sr_unix/gtmcrypt_util.c:101: undefined reference
>>> to `gtm_free'
>>> collect2: error: ld returned 1 exit status
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/build.make:202: recipe for
>>> target 'plugin/cyggtmcrypt_gcrypt_AES256CFB.dll' failed
>>> make[2]: *** [plugin/cyggtmcrypt_gcrypt_AES256CFB.dll] Error 1
>>> CMakeFiles/Makefile2:891: recipe for target
>>> 'CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/all' failed
>>> make[1]: *** [CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/all] Error 2
>>> Makefile:116: recipe for target 'all' failed
>>> make: *** [all] Error 2
>>>
>>> Here's the link command (I turned CMAKE_VERBOSE_MAKEFILE=ON):
>>> /usr/bin/cc   -march=i586 -fsigned-char -Wmissing-prototypes
>>> -Wreturn-type -Wpointer-sign -fno-omit-frame-pointer -g -DDEBUG -shared
>>> -Wl,--enable-auto-import -o plugin/cyggtmcrypt_gcrypt_AES256CFB.dll
>>> -Wl,--major-image-version,0,--minor-image-version,0
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/sr_unix/gtmcrypt_ref.c.o
>>>
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/sr_unix/gtmcrypt_pk_ref.c.o
>>>
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/sr_unix/gtmcrypt_dbk_ref.c.o
>>>
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/sr_unix/gtmcrypt_sym_ref.c.o
>>> CMakeFiles/libgtmcrypt_gcrypt_AES256CFB.so.dir/sr_unix/gtmcrypt_util.c.o
>>> -lgpg-error -lgpgme -lgcrypt /usr/local/lib/libconfig.dll.a
>>>
>>> What is missing is that there needs to be either a link to cyggtmshr.dll,
>>> or a way for CMake to know to generate a libgtmshr_import.lib and add it to
>>> the link command.
>>>
>>> So here is what I tried:
>>> 1. Using the GenerateExportHeader functionality of CMake on libgtmshr.
>>> If I do that, it doesn't seem to generate the import library; but it sure
>>> does generate an export header, which I don't need. Here it is:
>>> include(GenerateExportHeader)
>>> generate_export_header(libgtmshr
>>>     BASE_NAME libgtmshr
>>>     EXPORT_MACRO_NAME libgtmshr_EXPORTS
>>>     EXPORT_FILE_NAME  libgtmshr_EXPORTS.h
>>>     STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC)
>>>
>>> 2. Explicitly adding a libgtmshr as a dependency on line
>>> https://github.com/shabiel/fis-gtm/blob/cygwin/CMakeLists.txt#L531,
>>> but only for Cygwin. I get this error message:
>>> CMake Error at CMakeLists.txt:542 (target_link_libraries):
>>>   Target "libgtmshr" of type MODULE_LIBRARY may not be linked into
>>> another
>>>   target.  One may link only to STATIC or SHARED libraries, or to
>>> executables
>>>   with the ENABLE_EXPORTS property set.
>>>
>>> The GT.M developer familiar with CMake suggested me to use LINK_FLAGS and
>>> have CMake use the file by us hardcoding it in; which I am okay doing, but I
>>> thought I would check to see if there is an alternative way of doing this.
>>>
>>> I also tried the suggestions here:
>>>
>>> "https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/"
>>> to no avail.
>>>
>>> Last, but not least:
>>>
>>> sam at horus ~/fis-gtm-cygwin
>>> $ cmake --version
>>> cmake version 3.4.3
>>>
>>> CMake suite maintained and supported by Kitware (kitware.com/cmake).
>>>
>>> sam at horus ~/fis-gtm-cygwin
>>> $ uname -a
>>> CYGWIN_NT-10.0-WOW horus 2.2.0(0.289/5/3) 2015-08-03 12:49 i686 Cygwin
>>>
>>> --
>>> Sam Habiel, Pharm.D.
>>> VISTA Expertise Network
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Kitware offers various services to support the CMake community. For more
>>> information on each offering, please visit:
>>>
>>> CMake Support: http://cmake.org/cmake/help/support.html
>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/cmake
>>
>>
>>
>> --
>> Sam Habiel, Pharm.D.
>> VISTA Expertise Network
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake
>
>



-- 
Sam Habiel, Pharm.D.
VISTA Expertise Network


More information about the CMake mailing list