Linking error with opensc-pkcs

我的未来我决定 提交于 2019-12-04 05:53:06

问题


I am trying to use opensc-pkcs11.so which I have built on Redhat linux 5. However, when I try to use in a sample program it is giving a linking error:

main.cpp:(.text+0x265): undefined reference to `C_Initialize'

The sample code snippet is as follows:

int main()
{
CK_RV l_rv = 0;     
l_rv = C_Initialize(NULL_PTR);
//other staffs ...

}

If I see the nm output of opensc-pkcs11.so it is showing:

-bash-3.2$ nm opensc-pkcs11.so |grep C_Initialize
0000000000008c70 t C_Initialize

What is the meaning of 't'? I see it is not 'T'. But is also not 'U'. Can anybody suggest what is happening? Thanks in advance.


回答1:


PKCS#11 library opensc-pkcs11.so developed as a part of OpenSC project exports only C_GetFunctionList function which provides pointers to all the other PKCS#11 functions. It is exceptionally helpful when you load PKCS#11 library dynamically with dlopen() because you don't need to acquire function pointer for all 60+ functions with dlsym() call.

In your case you need to call C_GetFunctionList first and then call rest of the functions via returned pointers. Here is the example from PKCS#11 v2.20 specification created by RSA Security Inc.:

CK_FUNCTION_LIST_PTR pFunctionList; 
CK_C_Initialize pC_Initialize; 
CK_RV rv; 

/* It’s OK to call C_GetFunctionList before calling 
C_Initialize */ 
rv = C_GetFunctionList(&pFunctionList); 
assert(rv == CKR_OK); 
pC_Initialize = pFunctionList -> C_Initialize; 

/* Call the C_Initialize function in the library */ 
rv = (*pC_Initialize)(NULL_PTR); 


来源:https://stackoverflow.com/questions/22764447/linking-error-with-opensc-pkcs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!