CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: libm

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    libm

    Anyone know if libm is available for win32? I tried a few Google searches but all I could find were ports for Linux, Solaris etc and complaints from people who couldn't seem to make it work under Windows. However AFAIK it's only a math library so it would be a bit strange if it only worked with certain OS's.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: libm

    I have a program, named test.c, for Unix and for Windows. I compile them and they are working well for me.

    With Unix, I use:
    Code:
    gcc -lm -o test.exe test.c
    where -lm refers to libm (the "lib" prefix is removed as usual).

    With Windows, I use dev-cpp which is creating the following makefile:
    Code:
    CPP  = g++.exe
    OBJ  = test.o
    BIN  = test.exe
    LINKOBJ  = test.o
    LIBS =  -L"C:/Dev-Cpp/lib"  
    INCS =  -I"C:/Dev-Cpp/include" 
    CXXINCS =  -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include" 
    CXXFLAGS = $(CXXINCS)
    
    $(BIN): $(OBJ)
    	$(CPP) $(LINKOBJ) -o "test.exe" $(LIBS)
    
    test.o: test.c
    	$(CPP) -c test.c -o test.o $(CXXFLAGS)
    where libm is implictly refered since there is libm.a file in C:/Dev-Cpp/lib

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: libm

    Okay, a slight misunderstanding. I see you're building with mingw (or is it Dev-Cpp? Not sure what that is). In fact I can also build programs that use libm (with Cygwin, in my case) but I was thinking more about building with VC++.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Re: libm

    Yes, Dev-CPP is a GUI for Windows, calling the mingw compiler, which is named g++.exe.
    I am sure my program could also be compiled and linked with VC++, without having to install an additional library, but I don't know the name of the equivalent library of libm for VC++.

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: libm

    Yes, same problem here. Looking at the header files, libm seems to rely quite heavily on the Boost development library (although that does seem to be available for VC++). I'm not sure if it actually links to boost but it does seem to need the header files.

    In fact, if I'm looking at the right source modules, libm seems mostly to be inplemented using templates. So I can see why it might not have worked with earlier versions of VC++ but (presumably) it would work with the more up-to-date versions
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    Nov 2003
    Posts
    1,902

    Re: libm

    libm just provides "standard" math functions for C. Here, "standard" means ISO C[99], Posix, and others.

    The MS CRT provides math routines from "C95" (C89 plus amendment 1 corrections).

    Are you using something special from libm that isn't provided by the MS CRT?

    gg

  7. #7
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: libm

    No, actually I'm trying to build libsndfile using VC++2005. In libsndfile's config.h file there are loads of options for features that you might or might not have - such as libFLAC, libm, unistd.h, alsa_soundlib and various other things. I'm trying to build it with as much functionality as I can obtain for VC++.

    Having said that, I've had a good look through the source code and I can't see anywhere where libm functions are actually used - so it might be something that's now obsolete, or maybe something that's in there for future expansion.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  8. #8
    Join Date
    Nov 2003
    Posts
    1,902

    Re: libm

    When you use a function from <math.h>, some system require "-lm" when linking, and some systems don't. This may be all it's trying to determine, whether or not include "-lm" when linking.

    gg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured