[CMake] How Can I compile the following code on Windows with CMake?

Kermit Mei kermit.mei at gmail.com
Mon Mar 30 19:48:25 EDT 2009


I want to add the following program as a part of my project, but I don't
konw how to manage it in CMake.

I worte the following in my CMakeLists.txt:
  FIND_LIBRARY(LIBWMM winmm)
  ADD_EXECUTABLE(aplay WIN32 aplay.c)
  TARGET_LINK_LIBRARIES(aplay ${LIBWMM})
But it always told me that "undefined reference to 'PlaySoundA at 12' ".
How can I solve it?


By the way, what's the meaning of -mwindows? Can I also use strip in
CMake for optimization?


Thanks.
Kermit 





------------------------------------------------------------------------------------------
// compiling with mingw: gcc -mwindows aplay.c -lwinmm -o aplay.exe
//                       strip aplay.exe

#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
  if (argc == 1) {
    printf ("%s <soundfile>\n", argv[0]);
    exit(0);
  }

  if (!PlaySound(argv[1], 0, SND_FILENAME)) {
    printf ("error playing file\n");
  }
  return 0;
}



More information about the CMake mailing list