CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2009
    Posts
    5

    Problems linking with Winmm

    I'm using GCC with the included libwinmm.a library, and including windows.h and mmsystem.h. I compile it with the -lwinmm parameter, but I still get the error "Undefined reference to '<functionname>'" for every time that I've used a Winmm function. For example, this very simple program will generate a linker error:
    Code:
    #include<windows.h>
    #include<mmsystem.h>
    int main()
    {
     mixerGetNumDevs();   
    }
    Which comes with the corresponding error: "undefined reference to mixerGetNumDevs@0"

    Exact command used to compile:
    Code:
    gcc.exe -o winmmtest.exe -lwinmm winmmtest.c
    Any ideas as to the source of this problem are greatly appreciated. Thanks in advance.

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Smile Re: Problems linking with Winmm

    Maybe libwinmm.a should be placed in your Somedirectory\Dev-Cpp\lib directory, or you might need to specify the directory with -L"Somewhere/lib" (capital L this time).
    Or maybe a space is needed between #include and <mmsystem.h> Or maybe it should be #include "mmsystem.h" with quotes instead of angular brackets for it is not a standard header.
    Or maybe libwinmm.a is for Windows instead of Unix, or vice versa.

  3. #3
    Join Date
    Jun 2009
    Posts
    5

    Re: Problems linking with Winmm

    Quote Originally Posted by olivthill2 View Post
    Maybe libwinmm.a should be placed in your Somedirectory\Dev-Cpp\lib directory, or you might need to specify the directory with -L"Somewhere/lib" (capital L this time).
    Ah, yes. I've already tried that strategy, and with no success. I've tried commands to the linker like "-Wl, ...\Dev-Cpp\lib\libwinmm.a", and it produces the exact same result, unfortunately.

    Or maybe a space is needed between #include and <mmsystem.h> Or maybe it should be #include "mmsystem.h" with quotes instead of angular brackets for it is not a standard header.
    I've already played around with the headers, if I remove them, I get a compiler error, meaning that GCC couldn't find a prototype for mixerGetNumDevs() (for example). If I leave the header in, it generates a linker error, suggesting to me that it's not finding the right function in the library.

    Or maybe libwinmm.a is for Windows instead of Unix, or vice versa.
    Winmm is a multimedia library for Windows, and I'm using a version of it that came with my compiler. Along with libwinmm.a, which came with my compiler, I've also tried using the winmm.lib library from Visual Studio 6, which is supposedly identical. The result? Same problem.

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Smile Re: Problems linking with Winmm

    Okay. I have Windows and Dev-Cpp. I have created a new project, and I have compiled and linked your source code ... successfully !

    The first time, I had exactly your error message.
    Then, I right-cliked on the project to access to the "Project Options".
    Then, I selected the tab for Parameters.
    I wrote "-lwinmm", without the quotes, in the textarea under "Linker".
    I clicked OK, and there were no more errors.

    The resulting makefile contains:
    Code:
    # Project: Project1
    # Makefile created by Dev-C++ 4.9.9.2
    
    CPP  = g++.exe
    CC   = gcc.exe
    WINDRES = windres.exe
    RES  = 
    OBJ  = mm1.o $(RES)
    LINKOBJ  = mm1.o $(RES)
    LIBS =  -L"D:/blabla/Dev-Cpp/lib" -lwinmm  
    INCS =  -I"D:/blabla/Dev-Cpp/include" 
    CXXINCS =  -I"D:/blabla/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"D:/blabla/Dev-Cpp/include/c++/3.4.2/backward"  -I"D:/blabla/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"D:/blabla/Dev-Cpp/include/c++/3.4.2"  -I"D:/blabla/Dev-Cpp/include" 
    BIN  = mm1.exe
    CXXFLAGS = $(CXXINCS)  
    CFLAGS = $(INCS)  
    RM = rm -f
    
    .PHONY: all all-before all-after clean clean-custom
    
    all: all-before mm1.exe all-after
    
    
    clean: clean-custom
    	${RM} $(OBJ) $(BIN)
    
    $(BIN): $(OBJ)
    	$(CC) $(LINKOBJ) -o "mm1.exe" $(LIBS)
    
    mm1.o: mm1.c
    	$(CC) -c mm1.c -o mm1.o $(CFLAGS)

  5. #5
    Join Date
    Jun 2009
    Posts
    5

    Re: Problems linking with Winmm

    Excellent work, it was successful for my environment as well. I very much appreciate your help.

  6. #6
    Join Date
    Jan 2014
    Posts
    1

    Re: Problems linking with Winmm

    Quote Originally Posted by tuco View Post
    ...
    Which comes with the corresponding error: "undefined reference to mixerGetNumDevs@0"
    Exact command used to compile:
    ...
    Code:
    gcc.exe -o winmmtest.exe -lwinmm winmmtest.c
    ...
    Any ideas as to the source of this problem are greatly appreciated. Thanks in advance.
    Since this question was never answered and it's appearing near the top of Google's search results (in 2014) I would like to offer the following observation.

    When calling gcc from the command line, you provided the -lwinmm option BEFORE the source filename (winmmtest.c) which is incorrect. When invoking gcc from the command line, you must pass the -lwinmm (linker) option AFTER the source filename. For example:

    gcc -o winmmtest.exe winmmtest.c -lwinmm

    Or in the case of C++ source:

    g++ -o winmmtest.exe winmmtest.cpp -lwinmm

    I hope this may help someone!

    -z

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