Click to See Complete Forum and Search --> : Problems linking with Winmm
tuco
June 7th, 2009, 05:56 PM
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:
#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:
gcc.exe -o winmmtest.exe -lwinmm winmmtest.c
Any ideas as to the source of this problem are greatly appreciated. Thanks in advance.
olivthill2
June 8th, 2009, 08:02 AM
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.
tuco
June 8th, 2009, 06:54 PM
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.
olivthill2
June 9th, 2009, 05:41 AM
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:
# 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)
tuco
June 9th, 2009, 10:37 AM
Excellent work, it was successful for my environment as well. I very much appreciate your help.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.