2011-03-06 2 views
1

바보 같은 질문은 틀린 문법입니다. 값을 반환하는 함수로 dlsym을 사용하려면 어떻게해야합니까? 다음 코드에서 LSError (*)()로 void *를 잘못 변환했습니다. OS X dylib에 링크 할 수 있기를 희망하는 linux lightscribe 샘플 프로그램을 컴파일하려고합니다. 't HP는 실제 코코아 SDK를 공개 LS 전용) 지금 무엇을 6 칠년 주변에있다 :???dlsym()에서 값을 반환하는 함수?

void* LSHandle = dlopen("liblightscribe.1.dylib", RTLD_LOCAL|RTLD_LAZY); 
    if (LSHandle) { 
     LSError (*LS_DiscPrinter_ReleaseExclusiveUse)() = dlsym(LSHandle, "LS_DiscPrinter_ReleaseExclusiveUse"); 

.. 
lsError = LS_DiscPrinter_ReleaseExclusiveUse(pDiscPrinter); 
+1

이 페이지는 http://www.trilithium.com/johan/2004/12/problem-with-dlsym/에서 발견되었으며 void 포인터를 함수 포인터에 캐스트해야하는 것과 같은 문제를 해결하는 것으로 보입니다. Uugh .. –

+0

나는 일하는 건축을 발견했다. dlopen으로 파일을 연 후 다음과 같은 행 세트가 있습니다. LSError (* LS_DiscPrinter_ReleaseExclusiveUse) (LS_DiscPrinterHandle); LS_DiscPrinter_ReleaseExclusiveUse = (LSError (*) (void *)) dlsym (LSHandle, "LS_DiscPrinter_ReleaseExclusiveUse"); 다소 다루기 힘듭니다. xCode는 내가 발견 한 두 번째 페이지에서 typedef를 사용하는 것을 좋아하지 않았습니다. 'extern'C로 이해하지 못합니다. "typedef XML_Parser parsercreate_t (const XML_Char *); ' XML_ParserStruct의 반환 유형을 전혀 언급하지 않습니다. –

답변

3

C 표준이 실제로와 함수 포인터에서 변환 동작을 정의하지 않습니다. 설명은 이유에 따라 다릅니다. 가장 일반적인 것은 모든 아키텍처가 데이터에 대한 간단한 포인터로 함수 포인터를 구현하지 않는다는 것입니다. 일부 아키텍처에서는 함수가 void 포인터를 사용하여 주소를 지정할 수없는 전혀 다른 메모리 세그먼트에 상주 할 수 있습니다.

LSError (*LS_DiscPrinter_ReleaseExclusiveUse)(LS_DiscPrinterHandle); 

*(void **)&LS_DiscPrinter_ReleaseExclusiveUse = dlsym("LS_DiscPrinter_ReleaseExclusiveUse"); 

자세한 내용은 dlsym의 POSIX 페이지에 근거 예를 읽기 :

“은 dlsym를 사용하는 ” 방법을 권장합니다.