Question

I need to connect to a token using the standard PKCS#11. In my C program, wrote with Visual Studio, I included PKCS#11 headers, downloaded from RSA site and some macros.

//define macros
#define CK_PTR *
#define CK_DEFINE_FUNCTION(returnType, name) returnType name
#define CK_DECLARE_FUNCTION(returnType, name) returnType name
#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
#define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
#ifndef NULL_PTR
#define NULL_PTR 0
#endif

#include "pkcs11.h"

int main(int argc, char * argv[]) {
[..]
   C_Initialize(NULL_PTR);
   [..]

When i build it, i get "undefined reference to C_Initialize". The same error for all the pkcs11 function I used. In the program directory there are also the other pkcs11 headers. What is the wrong with it?

Was it helpful?

Solution

For static linking you need to have a corresponding .lib file. You can have it if you link the application with the SDK of particular hardware device.

The generic approach is to load the DLL given by the end user dynamically. To do this your code needs to use LoadLibrary() and GetProcAddress() Windows API functions to obtain addresses of each function of the library (yes, there are more than 50 functions there if memory serves).

OTHER TIPS

You're not linking with whatever object file or library that C_Initialize function is defined in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top