#2218 csqrt

WSL
closed
nobody
Bug
duplicate
Unknown
False
2014-08-28
2014-06-17
rgallou
No

Hi All,

I've download gcc version 4.8.1 by MinGW install package in Windows 8.
I have problems in linking with math library. gcc do not found math functions as csqrt, for example.

I put here my source example :

\#include <stdio.h> 
\#include <complex.h> 
// Compilation command :
// gcc -march=native -std=gnu99 -O1 test_sqrt.c -o test_sqrt -lm
void main ()
{
    double complex foo = 4.0;

    double complex dummy = csqrt(foo);
    printf("Test value : %g + i%g\n", creal(dummy), cimag(dummy));  
}

The compilation command is (force -O0 option for force gcc to found library :
gcc -march=native -std=gnu99 -O0 test_sqrt.c -o test_sqrt -lm

The result is :

**C:\Users\rgallou\AppData\Local\Temp\ccPv6a7l.o:test_sqrt.c:(.text+0x3a): undefined reference to `csqrt'
collect2.exe: error: ld returned 1 exit status**

libm is really installed whith MinGW in /MinGW/lib and gcc is in C:\MinGW\bin
Please, can someone tell me what I've to do or is there a problem with this version of gcc for windows ?

Thansk in advance, regards.

Discussion

  • Keith Marshall
    Keith Marshall
    2014-06-17

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -5,7 +5,7 @@
    
     I put here my source example :
    
    -------------- 
    +~~~~
     \#include <stdio.h> 
     \#include <complex.h> 
     // Compilation command :
    @@ -17,15 +17,17 @@
        double complex dummy = csqrt(foo);
        printf("Test value : %g + i%g\n", creal(dummy), cimag(dummy));  
     }
    -
    +~~~~
    
     The compilation command is (force -O0 option for force gcc to found library :
     **gcc -march=native -std=gnu99 -O0 test_sqrt.c -o test_sqrt -lm**
    
     The result is : 
    -**C:\Users\rgallou\AppData\Local\Temp\ccPv6a7l.o:test_sqrt.c:(.text+0x3a): undefin
    -ed reference to `csqrt'
    +
    +~~~~
    +**C:\Users\rgallou\AppData\Local\Temp\ccPv6a7l.o:test_sqrt.c:(.text+0x3a): undefined reference to `csqrt'
     collect2.exe: error: ld returned 1 exit status**
    +~~~~
    
     libm is really installed whith MinGW in /MinGW/lib and gcc is in C:\MinGW\bin
     Please, can someone tell me what I've to do or is there a problem with this version of gcc for windows ?
    
    • status: unread --> closed
    • Group: OTHER --> WSL
    • Type: Support --> Bug
    • Resolution: none --> duplicate
     
  • Keith Marshall
    Keith Marshall
    2014-06-17

    Closing, since this is a duplicate of [#2174].

    FTR, this isn't a GCC issue; the problem lies in the (separately maintained) MinGW runtime libraries. Also, libm.a is irrelevant: MinGW has never provided anything within it, (although IMO, it should); the omission is from libmingwex.a, in the 4.x releases. Until the maintainer gets around to publishing a corrected release, your best option is to roll back to mingwrt-3.20, and w32api-3.17.

     

    Related

    Issues: #2174

  • rgallou
    rgallou
    2014-06-17

    Thansk for your help.

    I want just to signal that after downloading CodeLite IDE which installs release 4.8.1 of gcc, my compilation finishes well.

    There are clearly some differences between gcc version but I have no time for the moment to see it in details.

    Greetings.

     
  • Keith Marshall
    Keith Marshall
    2014-06-17

    The CodeLite folks will have done their own packaging, but as I'd mentioned before, this isn't a GCC issue, so the GCC version is irrelevant; whether you get GCC-4.8.1 from us, (as GCC-4.8.1-4, or whatever), or from them, (as unqualified GCC-4.8.1), it's still the same version of the same compiler. My guess is that they have bundled a different version of the MinGW runtime libraries -- one which doesn't suffer from the complex math omissions.