Actually, main() is defined in the test file used to compile. Thus this code tests for the existence of the library, but it does not check what the library defines.
This doesn't work, you really need the -lgdi32 flag. I think that's because LyX is a command line application and gdi32 is a user-interface library.
Joost