Pages

Monday, April 11, 2016

Cygwin linking library problem on windows systems

Have you ever faced problem in compiling the Cygwin on windows? have you ever faced problem in resolving error: ld returned 1 exit status? Then here is the solution.

Even i have faced this, i have googled a lot to solve this issue but i couldn't find solution from any site. With my previous debugging skills finally i am able to resolve this issue. So i thought it is worthwhile to share with others.

For example you want to include static libraries, files will be created either .a or .lib extension, created in windows directory c:\xxx\yyy\zzz\test.a (full path).

You might have tried below compiler configuration
Library Path (-L): c:\xxx\yyy\zzz
Libraries (-l): test.a

For this definitely you will get error: ld returned 1 exit status. Do you know why? compiler will be reading your configuration as c:\xxx\yyy\zzz\libtest.a.a. In reality this path and file doesn't exist.

Then how to set the path for external library include?
As i have seen, compiler always looks for lib directory in the library path for your file. So you can do it in two ways.

1. create lib folder to keep your test.a in c:\xxx\yyy\zzz directory (i.e c:\xxx\yyy\zzz\lib\test.a). Then use below configuration
Library Path (-L): c:\xxx\yyy\zzz
Libraries (-l): \test

So compiler will be resolved this as c:\xxx\yyy\zzz\lib\test.a. if the file doesn't exist then it will try to lookin c:\xxx\yyy\zzz\lib\test.lib file.

2. If you don't want create lib folder then give relative path to your library file. Use below configuration
Library Path (-L): c:\xxx\yyy\zzz
Libraries (-l): \..\test

So compiler will be resolved this as c:\xxx\yyy\zzz\lib\..\test.a which means c:\xxx\yyy\zzz\lib\test.a. if the file doesn't exist then it will try to lookin c:\xxx\yyy\zzz\lib\..\test.lib file.

Let me know your experience on this library include solution for cygwin on windows.