Neil Edelman
Neil Edelman

Reputation: 11

Getting a function pointer to a dynamic library in C (C89)

I have a function pointer to a dynamic library,

#include <GL/gl.h> /* or something */

void (*vertex)(float, float) = &glVertex2f;

On GCCi686-apple-darwin10-gcc-4.2.1 it's always worked, but fails on Visual Studio 2010 with,

error 'vertex': address of dllimport 'glVertex2f' is not static

I have it configured for C89; I believe that's the only C available. The idea is that I want to invoke the function pointer as an extern in other files that do not include the library headers.

Upvotes: 0

Views: 363

Answers (2)

Neil Edelman
Neil Edelman

Reputation: 11

#include <GL/gl.h>

void (*vertex)(float, float);

and explicitly,

int main(int argc, char **argv) {
    vertex = &glVertex2f;
    ...
}

fixes the error.

Upvotes: 1

ams
ams

Reputation: 25559

Windows DLLs do not work like BSD/Linux shared libraries :(

I believe you need the GetProcAddress function.

This link was just pulled from Google: http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx

Upvotes: 0

Related Questions