Search code examples
gcccmakecygwin

What library types are expected in Cygwin gcc?


I'm using Cygwin 2.9.0-2, which included cmake 3.6.2. I'm trying to get a cmake file developed on CentOS using cmake 2.8 to run. It's a large cmake file, importing a variety of libraries, and includes compiling all of the unit tests to run again gtest.

I've a total lack of understanding of whether cygwin gcc wants Windows or Linux libraries for linking input, and what it produces. I haven't been able to google the answer to this question: does Cygwin expect .a/.so or .lib/.dll files for compiled in libraries, does it create the same, or does it not care at all. After all, it is compiling an executable that is to be run on Windows, so I would expect it to only produce .lib/.dll, and to expect them as well.

What has me confused is that I've cloned the gtest repo and it built and installed to /usr/local/lib/libgtest.a, and I've linked in my vendor's *.lib libraries, but the linker can't find the gtest libraries. Do I need to modify the gtest cmake to produce .lib instead of .a?

There are so many things that I could try to finish porting this cmake file that I'm not sure where to start, and this lack of understanding is killing me. I feel that if I understood this, then I could make a better decision about moving forward.

The Cygwin gcc man page implies that -lLibName looks for the file libLibName.a to link in. Same as Linux. Great. So why does VendorLib.lib link in? (All indications are that it is linking in because I had link errors go away once I got cmake to correctly search and locate the library.)

If the best explanation is a link to the proper documentation, I'll accept that as the answer. If that's it, I just can't locate the documentation. TIA SO users!

Update:

Configuring cmake to use 64-bit linux libraries, I get the following message outputs from cmake:

-- Found Ballard library /usr/local/lib64/ballard/libbtiCard.so
-- Found Ballard library /usr/local/lib64/ballard/libbti1553.so

And the following from make:

/usr/local/lib64/ballard/libbtiCard.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status

I don't get this error message when compiling with the Windows .lib static libaries. Renaming from .so to .dll.a didn't change anything.

I don't need a special build for Cygwin, do I? Is this just a problem with the vendor's library, and not with Cygwin, and I need to get with them to address the issue?

Final Update

I copied my vendor's WIN64/VENDOR.LIB to /usr/local/lib64/vendor/libVendor.a.

I copied my vendor's Linux/API64/*.h to /usr/local/include/vendor/*.h

I also added the following line to my cmake file so it would search the lib64/ path:

set_property( GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE )

and then moved compiled google test/mock libraries from /usr/local/lib to /usr/local/lib64. There were other things unrelated to this question I had to change, but these are all covered in other SO questions. What an awesome community!


Solution

  • On cygwin the import libraries are named

    libNAME.a for static version
    libNAME.dll.a for shared version

    The packages containing header and import libraries are named {lib}NAME-devel.

    As example:

    $ cygcheck -cd |grep glpk
    glpk                                    4.63-1
    libglpk-devel                           4.63-1
    libglpk40                               4.63-1
    
     $ cygcheck -l libglpk-devel |grep usr/lib
    /usr/lib/libglpk.dll.a
    
    $ cygcheck -l libglpk40
    /usr/bin/cygglpk-40.dll
    

    So libglpk-devel package contains the shared import library libglpk.dll.a. The corresponding shared lib used by the other programs is cygglpk-40.dll

    Import library called NAME.lib are windows one and you should not mix or use them when building a cygwin program.