D:/Documents/NetBeansProjects/cap/main.cpp:33: undefined reference to `_imp__pthread_create'

D:/Documents/NetBeansProjects/cap/main.cpp:34: undefined reference to `_imp__pthread_create'

D:/Documents/NetBeansProjects/cap/main.cpp:35: undefined reference to `_imp__pthread_join'

D:/Documents/NetBeansProjects/cap/main.cpp:36: undefined reference to `_imp__pthread_join'

build/Debug/MinGW-Windows/main.o: In function `Z8cancelerPv':

D:/Documents/NetBeansProjects/cap/main.cpp:47: undefined reference to `_imp__pthread_kill'

D:/Documents/NetBeansProjects/cap/main.cpp:48: undefined reference to `_imp__pthread_exit'

D:/Documents/NetBeansProjects/cap/main.cpp:51: undefined reference to `_imp__pthread_exit'

this is the error i got when i compile the below program (not all parts inlcluded below..)

string getcommand();
string execute(string command);
void* runexe(void* args);
void* canceler(void* args);
void show(string val);

bool executing;
pthread_t tid, ctid;
string command;

int main(int argc, char** argv)
{
    while(true)
    {
        command = getcommand();
        executing = true;
        pthread_create(&tid,NULL,runexe,NULL);
        pthread_create(&ctid,NULL,canceler,NULL);
        pthread_join(tid,NULL);
        pthread_join(ctid,NULL);
    }
}

i goolged n found out that i should use -lpthread while compiling.. i put it in the netbean's additional options in c++ compiler section. then i got an error like this

/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/d/Documents/NetBeansProjects/cap'
/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cap.exe
make[2]: Entering directory `/d/Documents/NetBeansProjects/cap'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe -lpthread   -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
g++.exe: -lpthread: linker input file unused because linking not done

mkdir -p dist/Debug/MinGW-Windows
g++.exe -lpthread    -o dist/Debug/MinGW-Windows/cap build/Debug/MinGW-Windows/main.o  
d:\sOftware baCkup\programing\Cpp\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lpthread

collect2: ld returned 1 exit status

make[2]: *** [dist/Debug/MinGW-Windows/cap.exe] Error 1
make[2]: Leaving directory `/d/Documents/NetBeansProjects/cap'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/d/Documents/NetBeansProjects/cap'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)

som websites said i should use -mthreads as an option... it results...

/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/d/Documents/NetBeansProjects/cap'
/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cap.exe
make[2]: Entering directory `/d/Documents/NetBeansProjects/cap'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe -mthreads   -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++.exe -mthreads    -o dist/Debug/MinGW-Windows/cap build/Debug/MinGW-Windows/main.o  
build/Debug/MinGW-Windows/main.o: In function `main':

D:/Documents/NetBeansProjects/cap/main.cpp:33: undefined reference to `_imp__pthread_create'

D:/Documents/NetBeansProjects/cap/main.cpp:34: undefined reference to `_imp__pthread_create'

D:/Documents/NetBeansProjects/cap/main.cpp:35: undefined reference to `_imp__pthread_join'

D:/Documents/NetBeansProjects/cap/main.cpp:36: undefined reference to `_imp__pthread_join'

build/Debug/MinGW-Windows/main.o: In function `Z8cancelerPv':

D:/Documents/NetBeansProjects/cap/main.cpp:47: undefined reference to `_imp__pthread_kill'

D:/Documents/NetBeansProjects/cap/main.cpp:48: undefined reference to `_imp__pthread_exit'

D:/Documents/NetBeansProjects/cap/main.cpp:51: undefined reference to `_imp__pthread_exit'

collect2: ld returned 1 exit status

make[2]: *** [dist/Debug/MinGW-Windows/cap.exe] Error 1
make[2]: Leaving directory `/d/Documents/NetBeansProjects/cap'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/d/Documents/NetBeansProjects/cap'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)

i even used -pthread and -lpthreadGC2 .. still the same.. errors... :((((((((((((((((((( PLEASE HELP ME..

i compile this on fedora linux.. using -lpthread.. but why dont it work in dis daamn windows....

libpthread compile as .dll
recompile it as static library.

Or addind "-DPTW32_STATIC_LIB" for compiler args

this is the arguments that i put now

-DPTW32_STATIC_LIB -lpthread

this got an error like this.... i dnt recompile the source of pthreads for making is static library.....

/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/d/Documents/NetBeansProjects/cap'
/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cap.exe
make[2]: Entering directory `/d/Documents/NetBeansProjects/cap'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe -DPTW32_STATIC_LIB -lpthread   -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
g++.exe: -lpthread: linker input file unused because linking not done

mkdir -p dist/Debug/MinGW-Windows
g++.exe -DPTW32_STATIC_LIB -lpthread    -o dist/Debug/MinGW-Windows/cap build/Debug/MinGW-Windows/main.o  
d:\sOftware baCkup\programing\Cpp\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lpthread

collect2: ld returned 1 exit status

make[2]: *** [dist/Debug/MinGW-Windows/cap.exe] Error 1
make[2]: Leaving directory `/d/Documents/NetBeansProjects/cap'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/d/Documents/NetBeansProjects/cap'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 4s)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.