X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=4.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Message-ID: <4C7AE88B.2000309@gmail.com> Date: Sun, 29 Aug 2010 19:08:59 -0400 From: =?ISO-8859-1?Q?Tom=E1s_Staig?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Linking shared libraries problem Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hi, I have been trying to port some software from Linux (Scientific Linux/RedHat) to windows using Cygwin. I have been able to port most of it with little changes but I encountered a problem when linking shared libraries. It seems that the chain of dependencies is not included when linking. Furthermore, ldd does not show the dependency libraries as in Linux. I have tried both using the import libraries (%.dll.a) and linking the dll files (%.dll) directly. I have arranged a small example program that reproduces this effect. Used Ubuntu 8.04 to and "CYGWIN_NT-5.1" version "1.7.6(0.230/5/3) 2010-08-16 16:06" on top of a 32-bits Windows XP Machine to test the above examples. x.h: int add(int a, int b); x.cpp: #include "x.h" int add(int a, int b) {return a + b;} y.h: int sub(int a, int b); y.cpp: #include "y.h" int sub(int a, int b){return a - b;} main.cpp: #include #include "x.h" #include "y.h" int main() { printf("%d\n",add(1,1)); printf("%d\n",sub(2,1)); return 0; } Makfile in Linux: #Compiling all: g++ -c x.cpp g++ -c y.cpp g++ -shared -Wl,-whole-archive y.o -Wl,-no-whole-archive -o liby.so g++ -shared -Wl,-whole-archive x.o -Wl,-no-whole-archive -L./ -ly -o libx.so g++ -o main main.cpp -L./ -lx Makefile in Cygwin: all: g++ -c x.cpp g++ -c y.cpp g++ -shared y.o -Wl,-out-implib=liby.dll.a -Wl,-export-all-symbols -Wl,-enable-auto-import -Wl,-whole-archive -Wl,-no-whole-archive -o liby.dll g++ -shared x.o -Wl,-out-implib=libx.dll.a -Wl,-export-all-symbols -Wl,-enable-auto-import -Wl,-whole-archive -Wl,-no-whole-archive -L./ -ly -o libx.dll g++ -o main main.cpp -L./ -lx Linux does not produce any output and the program 'main' works. Cygwin Output: /tmp/cc0LNesq.o:main.cpp:(.text+0x4a): undefined reference to `sub(int, int)' collect2: ld returned 1 exit status make: *** [all] Error 1 If I use ldd in Linux for libx.so: $ ldd libx.so linux-gate.so.1 => (0xb772f000) liby.so (0xb7729000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7635000) libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb75f9000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb75ee000) libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb749f000) /lib/ld-linux.so.2 (0xb7730000) and in Cygwin for libx.dll: $ ldd libx.dll ntdll.dll => /cygdrive/c/WINDOWS/system32/ntdll.dll (0x7c910000) kernel32.dll => /cygdrive/c/WINDOWS/system32/kernel32.dll (0x7c800000) As you can see, there is no reference to liby.dll. I could add the library (-ly) directly to the compiling line of main and it works, but the truth is that it would not be a good approach, since in the software I'm trying to port, there are several dependent modules, so the last ones would have an incredibly large list of dependencies. So, am I doing something wrong? Is there any way to add the dependency to be shown with ldd or any workaround(maybe a linker flag or something) to make the above example work? Thanks in advance. Best Regards, Tomas. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple