2011-02-18 2 views
2

mingw 컴파일러와 코드 블록 IDE를 사용하고 있습니다. 나는이 기능을 사용하여 심지어 __declspec(dllexport)을 사용하여도 내 dll이 모든 기능을 수출하는 방법을 이해하지 못하는 문제에 직면하고있다.내 dll이 내 동의없이 모든 기능을 내보내고 있습니다!

main.h :

#ifndef __MAIN_H__ 
#define __MAIN_H__ 
#include windows.h 

#ifdef BUILD_DLL 
    #define DLL_EXPORT __declspec(dllexport) 
#else 
    #define DLL_EXPORT __declspec(dllimport) 
#endif 

#ifdef __cplusplus 
extern "C" 
{ 
#endif 

void SomeFunction(const LPCSTR sometext); 

#ifdef __cplusplus 
} 
#endif 

#endif // __MAIN_H__ 

main.cpp : 여기에 두 개의 샘플 파일, main.hmain.cpp있는이 예에서

#include "main.h" 


void SomeFunction(const LPCSTR sometext) 
{ 
    MessageBoxA(0, sometext, "DLL fxn Message", MB_OK | MB_ICONINFORMATION); 
} 

bool flag = false; 

extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 
{ 
    switch (fdwReason) 
    { 
     case DLL_PROCESS_ATTACH: 
      // attach to process 
      // return FALSE to fail DLL load 
      break; 
     case DLL_PROCESS_DETACH: 
      // detach from process 
      break; 
     case DLL_THREAD_ATTACH: 
      // attach to thread 
      break; 
     case DLL_THREAD_DETACH: 
      // detach from thread 
      break; 
    } 

    flag = true; 

    return TRUE; // succesful 
} 

SomeFunction 내보낼와 나는 동적에서 호출 할 수 있어요 비록 내가 프로토 타입 화하지는 않았지만 외부 적으로 애플리케이션이다.

void __declspec(dllexport) SomeFunction(const LPSTR sometext); 

뿐만 아니라 전역 변수 flag조차도 자동 생성 .def 파일로 내보내집니다.

여기 무슨 일입니까? 제가 기술적 인 실수를 저지르고 있다면 저를 도와주십시오.

+0

가능한 중복 [? 모든 기호를 수출하지는 MinGW 링커를 말할 방법] (http://stackoverflow.com/questions/2810118/how- : 이것은 GCC의 인간이 페이지에서 무시 될 수 있습니다 to-tell-the-mingw-linker-not-to-export-all-symbols) – laalto

답변

0

저는 MinGW 링커 또는 CodeBlocks을 모르지만 함수를 내보낼 수있는 다른 방법은 .def 파일을 사용하는 것입니다. 링커에 전달할 SomeFunction을 나열하는 .def 파일이 있습니까?

는 당신이 그 (것)들을 기본적으로 숨겨져하지 않는 한

+0

아니요 .def 파일을 사용하지 않지만 IDE가 자동으로 생성합니다. 자동 생성을 비활성화하는 옵션이 있지만이 옵션을 사용하더라도 SomeFunction을 내 보냅니다. – Haziq

3

는 MinGW 링커는 모든 기호를 공개한다 (이 IIRC 그 수출과 .DEF 파일을 포함 않는 VC++ DLL 템플릿, 모양).

-fvisibility=default|internal|hidden|protected 

... 
A good explanation of the benefits offered by ensuring ELF symbols 
      have the correct visibility is given by "How To Write Shared 
      Libraries" by Ulrich Drepper (which can be found at 
      <http://people.redhat.com/~drepper/>)---however a superior solution 
      made possible by this option to marking things hidden when the 
      default is public is to make the default hidden and mark things 
      public. This is the norm with DLL's on Windows and with 
      -fvisibility=hidden and "__attribute__ ((visibility("default")))" 
      instead of "__declspec(dllexport)" you get almost identical 
      semantics with identical syntax. This is a great boon to those 
      working with cross-platform projects. 
+1

컴파일러 옵션에 -fvisibility = hidden 속성을 추가하려고 시도했지만 빌드 로그에 다음과 같이 표시됩니다. C : \ Test \ caught \ main.cpp | 7 경고 :이 구성에서는 가시성 속성이 지원되지 않습니다. 무시한 | || === 빌드 완료 : 0 개 오류, 3 개 경고 === | 그리고 함수를 다시 내 보냅니다. gcc 맨 페이지가 무엇을 의미하는지 설명하십시오. 나는 그것을 거기에서 타지 않고 있었다. 감사. – Haziq

+0

매뉴얼 페이지는 유닉스 세계에서 매뉴얼이다. 나는 이것이 이것이라고 생각한다 : http://linux.die.net/man/1/gcc. – Maister

관련 문제