2012-11-10 4 views
0

나는 zip 파일에서 소스 코드를 the website에 압축 해제하고 Code :: Blocks의 'include'폴더에 넣었지만 제공된 'hello.cpp'예제는 컴파일 할 수 없습니다.TinyThread ++를 제작해야합니까?

(

#include <iostream> 
#include <tinythread.h> 

using namespace std; 
using namespace tthread; 


// This is the child thread function 
void HelloThread(void * aArg) 
{ 
    cout << "Hello world!" << endl; 
} 

// This is the main program (i.e. the main thread) 
int main() 
{ 
    // Start the child thread 
    thread t(HelloThread, 0); 

    // Wait for the thread to finish 
    t.join(); 
} 

그리고 이들은 다음과 같은 오류가 있습니다 :) 참고로 : ++

|41|undefined reference to `tthread::thread::thread(void (*)(void*), void*)'| 
|44|undefined reference to `tthread::thread::join()'| 
|44|undefined reference to `tthread::thread::~thread()'| 
|44|undefined reference to `tthread::thread::~thread()'| 

같은 일이 wxDev-C와 함께 발생합니다. 나는 무엇인가 놓치고 있는가? 내가 도서관이나 아무것도 만들지 않아도 돼? 그렇다면 어떻게?

+1

대부분의 경우 라이브러리에 링크해야합니다. 이 오류에 대한 좋은 참조입니다 : http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris

+0

@chris 이것이 많은 최근의 오류에 대해 많은 것을 * 들었지만, 어떻게 라이브러리를 연결할 수 있습니까? 너 또는 다른 누군가가 나에게 설명해 줄 수 있니? : O – Mutoh

+0

여기서는 적용되지 않지만 IDE를 사용하는 경우 일반적으로 링커 프로젝트 설정으로 이동하여 라이브러리를 추가 할 수 있습니다. MSVC는'#pragma comment (lib, "nameoflibrary.lib")'를 할 수있게 해주 며, 커맨드 라인에서는'-llibraryname'을 사용합니다. – chris

답변

3
아카이브 내부의 readme.txt에서

다음 cpp를 컴파일되지 않기 때문에 그냥 헤더 포함

Using TinyThread++

To use TinyThread++ in your own project, just add tinythread.cpp and tinythread.h to your project. In your own code, do:

#include <tinythread.h> 
using namespace tthread; 

If you wish to use the fast_mutex class, inlude fast_mutex.h:

#include <fast_mutex.h> 

해결되지 않은 기호를 리드.

+0

tinythread.cpp를 프로젝트에 추가해 주셔서 감사합니다. – Mutoh

+0

어, 재미 있어요. 필자는 라이브러리가 라이브러리에 빌드하는 대신 구현을 링크하도록 만든 적이 없습니다. – chris

+0

단지 하나의 구현 파일에 너무 많은 노력이 필요합니다. 또한 미니멀리즘으로 광고됩니다. –

0

TinyThread는 작습니다.

헤더를 포함하는 것 외에 TinyThread.cpp를 프로젝트에 추가하거나 프로젝트의 일부로 빌드하는지 확인하십시오.

내 프로젝트에 CPP 파일을 추가 할 때까지 VC++에서 특별한 오류가 발생했습니다.

스레드 클래스와 메소드가 컴파일되지 않았습니다.

관련 문제