libpthread.a 는 정적라이브러리 인가요? 동적라이브러리 인가요?

pogusm의 이미지

ffmpeg관련 연습중인데.. (windows7 + qt(mingw32))

ffmpeg에서 아마도 pthread를 필요로 하는거 같습니다.

qtcreator에서 기본으로 설치되는 mingw32에는 기본적으로
pthread.h (42.1kb)
libpthread.a (87.5kb) 이 두개의 파일만 존재하더라구요..

그래서 정적라이브러리인거 같아서 (또, pthreadGC2.dll(58.8kb) 보다 용량이 커서 정적라이브러리라고 추측했습니다)

그냥 LIBS += -lpthread 의 방법으로 해당 라이브러리를 포함시키고 컴파일을 했는데,

pthreadGC2.dll 라는 동적 라이브러리가 없어서 실행할수가 없다고 나왔습니다.

그래서, ftp://sourceware.org/pub/pthreads-win32 에서 pthreads-w32-2-8-0-release.exe 라는 파일을 받아서
pre-build되어 있는
pthreadGC2.dll(58.8kb) 파일을 복사해왔더니, 정상적으로 실행이 됩니다.

-----------------------------------------------------------------------------------

질문1.
pthread 는 원래 C++가 아닌 C용 라이브러리 인가요?

질문2.
libpthread.a (87.5kb) 은 정적라이브러리가 아닌가요?
libpthread.a (87.5kb) 이 동적라이브러리라면, qtcreator에서 기본설치되는 mingw32에서 pthreadGC2.dll(58.8kb) 를 빠뜨린건 노키아의 실수인가요?

질문3.
xxxxx.a 라는 라이브러리 파일을 열어서 정적라이브러리인지, 동적라이브러리인지 정확히 아는 방법을 좀 알려주세요
(무엇으로 열어서 어디를 확인해야하는지... 등..)
그리고 xxxxx.a 가 "정적라이브러리"일 경우에도, 실행파일의 용량등을 최소화하기위해 "동적라이브러리"로 이용할 수도 있는건가요? 그럴땐 어디에서(소스코드에서? 또는 컴파일옵션에서?) 어떤 방법을 사용해야하나요?

조언부탁드립니다.

굽신굽신

참고로 관련 파일들을 첨부합니다.

File attachments: 
첨부파일 크기
Package icon pthread.zip36.78 KB
chadr의 이미지

답1 : pthread는 C로 "작성된" 라이브러리입니다. extern "c"를 이용하시면 C++에서도 사용하실 수 있습니다.

답2 : libpthread.a를 들여다보니 동적라이브러리 명시적링크용 라이브러리더군요.

답3 : 겉으로 보기에는 용량으로 비교 할수 있지만 몇몇 바이너리와 라이브러리와 용량 차이가 큰 경우에
해당됩니다. 프로그램 크기가 별로 크지 않아 서로간에 별로 차이가 안나는 경우에는 직접 까봐야합니다.

경험상 텍스트에디터로 라이브러리를 열었을때 특정 dll 파일의 이름이 명시(.dll로 검색)되어있는 경우는
동적라이브러리용이고 그렇지 않는 경우에는 정적라이브러리입니다. 동적라이브러리용은 반드시 로드해야하는
dll파일 이름이 있어야지만 운영체제가 로드 할 수 있으니까요.

정적라이브러리로 구성된건 정적으로만 링크 할 수 있습니다. 마찬가지로 동적라이브러리용은 동적으로만
링크할 수 있습니다. 애초 동적라이브러리용은 링크를 위한 심볼만 들어있을뿐 실행에 필요한 바이너리는 없습니다.
그반대로 정적라이브러리는 실행에 필요한 바이너리와 링크에 필요한 심볼이 같이 들어있습니다.

ps. http://ffmpeg.zeranoe.com/builds/ 여기가시면 phtread를 정적으로 링크한 ffmpeg를 구하실수 있습니다.
예전에는 정적으로 링크해서 배포했었는데 지금은 어쩐지 모르겠네요. 한번 시도해보세요.

-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.

pogusm의 이미지

친절한 답변 감사합니다.

정말 큰 도움이 되었습니다.

참고하고 있던 ffmpeg example에서 왜 아래와 같이 extern "C" {} 로 include하고 있는지도 이해가 됐습니다.

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
}

그런데,
QtCreator에서 설치되는 mingw32에서 pthreadGC2.dll(58.8kb) 를 실수로 빠뜨린줄 알았는데..
wxDev-C++ 에서도 pthread.h (42.1kb), libpthread.a (87.5kb) 이 두개 파일만 설치되네요..
(의도된건지, 실수인지는 모르겠지만.. 아무튼 따로 pthreadGC2.dll를 설치해야만 했습니다..)

반면 VC++에서는 pthreadVC.dll (52.0kb) 를 C:\Windows\SysWOW64 디렉토리에 자동으로 설치해 주는거 같습니다..

신기하네요 ㅎㅎ

익명 사용자의 이미지

Building the library as a statically linkable library
-----------------------------------------------------
 
General: PTW32_STATIC_LIB must be defined for both the library build and the
application build. The makefiles supplied and used by the following 'make'
command lines will define this for you.
 
MSVC (creates pthreadVCn.lib as a static link lib):
 
nmake clean VC-static
 
 
MinGW32 (creates libpthreadGCn.a as a static link lib):
 
make clean GC-static
 
 
Define PTW32_STATIC_LIB when building your application. Also, your
application must call a two non-portable routines to initialise the
some state on startup and cleanup before exit. One other routine needs
to be called to cleanup after any Win32 threads have called POSIX API
routines. See README.NONPORTABLE or the html reference manual pages for
details on these routines:
 
BOOL pthread_win32_process_attach_np (void);
BOOL pthread_win32_process_detach_np (void);
BOOL pthread_win32_thread_attach_np (void); // Currently a no-op
BOOL pthread_win32_thread_detach_np (void);
 
 
The tests makef iles have the same targets but only check that the
static library is statically linkable. They don't run the full
testsuite. To run the full testsuite, build the dlls and run the
dll test targets.

README 안에 위와 같은 내용이 있군요. 잠시 pthread.h 를 살펴보았는데, PTW32_STATIC_LIB 가 정의되어 있지 않으면 pthread 함수들을 동적으로 사용(dllimport)하도록 되어있네요.

/*
 
 * When building the DLL code, you should define PTW32_BUILD so that
 
 * the variables/functions are exported correctly. When using the DLL,
 
 * do NOT define PTW32_BUILD, and then the variables/functions will
 
 * be imported correctly.
 
 */
 
#ifndef PTW32_STATIC_LIB
 
#  ifdef PTW32_BUILD
 
#    define PTW32_DLLPORT __declspec (dllexport)
 
#  else
 
#    define PTW32_DLLPORT __declspec (dllimport)
 
#  endif
 
#else
 
#  define PTW32_DLLPORT
 
#endif

짐작입니다만, 제 생각에는 pthread*.dll 없이 정적으로 링크하는 것도 가능할 거 같습니다. 다만 정적으로 링크할 경우 라이센스에 주의하시기 바랍니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.