undefined reference to `LeaveCriticalSection@4'

Hi,

I've been struggling for the last few days to resolve this really annoying code problem. I have been trying to compile a piece of code from the OpenGL Red-book
and I keep getting a 'undefined reference to `LeaveCriticalSection@4' error. Now I know that to resolve this problem I should link in the kernel32.dll file into my linker options. The thing is it's there already! I can successfully specify the dll in the linker libraries and the compiler does not complain that it can't be found. So does anyone have a suggestions, because I'm stumped.

Thx

FC.

What compiler do you use?

In Visual Studio you need to specify kernel32.lib not kernel32.dll
I have used Cygwin and MinGW compilers. I have also used Netbeans and Codeblocks IDEs and I still get the same result in all of them. I have linked in kernel32.dll in other projects without this error and things have been ok. So I don't know what is wrong.

You're supposed to link to the library. For GCC compilers you should be linking to a file called "libkernel32.a".

OP wrote:
I have linked in kernel32.dll in other projects without this error and things have been ok.

That's because normally kernel32.dll is linked to your project whether you like it or not. But now you're using Cygwin which shuffles things up a bit. You'd be better off setting up a VM and installing whatever flavor of *nix you want then using Cygwin. Or dual boot if you would rather do it that way. It's not the products themselves that are the issue, it's that when people write documentation including the use of either one of these as a "solution" they are usually thinking of them as a magic bullet to solve all of the differences between *nix and Windows, but they leave out a ton of important crap. Personally I would rather perform my own dental surgery than use Cygwin or MSYS.
After years of using Cygwin and MinGW I have decided to stop using them because I've had no end of problems. I've just discovered that Microsoft have released Visual Studio Community Edition 2015, so I'm gonna try that. I think I'll still use Netbeans for Java development though.

Community edition 2015 includes the MFC, it's pretty good for free software where C++ is concerned.

Cygwin, that isn't a replacement for a native tool like VS. You'll still need it.
closed account (E0p9LyTq)
@Fractal Cat,

When you install VS 2015 make sure you do a custom install, Visual C++ is not installed with the typical install option.
I'll say it again, a Virtual Machine is going to be your best friend when you are working on stuff like this. Modern hardware, even on economy class PC's, is more than capable of running two OS's at the same time. It won't take you longer than a day to setup and you'll save ten times that amount of work not fighting with Cygwin and\or MSYS in addition to a few other extraneous benefits.
Seeing as though we're discussing VS 2015, I've been trying to build some GLFW code. Now, I can get it to work with Netbeans and Cygwin, but when I try to emulate it in VS it keeps reporting unresolved external symbols. For some reason I can't build it I've linked in the GLFW libs but I'm still getting no joy.

Here's an example of my problem, this is what keeps cropping up:

LNK2019 unresolved external symbol "extern "C" void __cdecl glfwPollEvents(void)" (?glfwPollEvents@@$$JOYAXXZ referenced in function "int_ __cdecl main(void)

Anyone any ideas ?

Topic archived. No new replies allowed.