Hi,
obviously, a classical error.
I'm working on code::blocks, raspbian
I use -lpthread (last option) to compile my project, but i've got this error:
/usr/bin/ld: obj/Debug/pict.o: référence au symbole non défini «pthread_create@@GLIBC_2.4»
//lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 16 second(s))
0 error(s), 20 warning(s) (0 minute(s), 16 second(s))
this is my .cbp
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="dic_gtk_opencv_01" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/dic_gtk_opencv_01" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add option="-rdynamic" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/dic_gtk_opencv_01" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" />
<Add option="`pkg-config gtk+-3.0 --cflags`" />
<Add option="`pkg-config opencv --cflags`" />
</Compiler>
<Linker>
<Add option="`pkg-config gtk+-3.0 --libs`" />
<Add option="'pkg-config opencv --libs'" />
<Add option="`pkg-config --libs opencv`" />
<Add library="wiringPi" />
<Add library="udev" />
<Add library="pthread" />
</Linker>
<Unit filename="hard.cpp" />
<Unit filename="hard.h" />
<Unit filename="ihm.cpp" />
<Unit filename="ihm.h" />
<Unit filename="ihm_sig.cpp" />
<Unit filename="ihm_sig.h" />
<Unit filename="interrupt.cpp" />
<Unit filename="interrupt.h" />
<Unit filename="main.cpp" />
<Unit filename="pict.cpp" />
<Unit filename="pict.h" />
<Extensions>
<editor_config active="1" use_tabs="0" tab_indents="1" tab_width="2" indent="2" eol_mode="0" />
<code_completion />
<envvars />
<lib_finder disable_auto="1" />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
An idea to help me please?
Bye
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
a build log would be more helpfull
first match on duckduckgo:
https://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux#1665110
this will fix your problem
You have to use the other linker settings, not the library...
Thank you BlueHazzard,
Sorry, it was only the end of the build log, the complete is :
-------------- Clean: Debug in dic_gtk_opencv_01 (compiler: GNU GCC Compiler)---------------
Cleaned "dic_gtk_opencv_01 - Debug"
-------------- Build: Debug in dic_gtk_opencv_01 (compiler: GNU GCC Compiler)---------------
g++ -std=c++11 -Wall -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/opencv -g -rdynamic -c /home/pi/dic2/dic_gtk_opencv_01/hard.cpp -o obj/Debug/hard.o
g++ -std=c++11 -Wall -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/opencv -g -rdynamic -c /home/pi/dic2/dic_gtk_opencv_01/ihm.cpp -o obj/Debug/ihm.o
g++ -std=c++11 -Wall -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/opencv -g -rdynamic -c /home/pi/dic2/dic_gtk_opencv_01/ihm_sig.cpp -o obj/Debug/ihm_sig.o
/home/pi/dic2/dic_gtk_opencv_01/ihm_sig.cpp: In function 'void BoutonTest_Click()':
/home/pi/dic2/dic_gtk_opencv_01/ihm_sig.cpp:12:14: warning: variable 'view' set but not used [-Wunused-but-set-variable]
GtkWidget *view;
^
g++ -std=c++11 -Wall -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/opencv -g -rdynamic -c /home/pi/dic2/dic_gtk_opencv_01/interrupt.cpp -o obj/Debug/interrupt.o
g++ -std=c++11 -Wall -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/opencv -g -rdynamic -c /home/pi/dic2/dic_gtk_opencv_01/main.cpp -o obj/Debug/main.o
/home/pi/dic2/dic_gtk_opencv_01/main.cpp: In function 'int main(int, char**)':
/home/pi/dic2/dic_gtk_opencv_01/main.cpp:7:21: warning: passing NULL to non-pointer argument 1 of 'int main_gtk(int, char**)' [-Wconversion-null]
main_gtk(NULL,NULL);
^
g++ -std=c++11 -Wall -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/opencv -g -rdynamic -c /home/pi/dic2/dic_gtk_opencv_01/pict.cpp -o obj/Debug/pict.o
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp: In function 'void myInterruptBpShot()':
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'DEMARRAGE' not handled in switch [-Wswitch]
switch (etatSystem){
^
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'DEMANDE_PHOTO0' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'DEMANDE_SEQ' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'DEMANDE_SALVE' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'FIN_SALVE' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'ERROR' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'ABORT_DEMANDE_SALVE' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:448:10: warning: enumeration value 'ABORT_SALVE_EN_COURS' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp: In function 'void myInterruptOpto()':
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'DEMARRAGE' not handled in switch [-Wswitch]
switch (etatSystem){
^
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'DEMANDE_PHOTO0' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'DEMANDE_SEQ' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'DEMANDE_SALVE' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'SALVE_EN_COURS' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'FIN_SALVE' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'ERROR' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'SLEEP' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'ABORT_DEMANDE_SALVE' not handled in switch [-Wswitch]
/home/pi/dic2/dic_gtk_opencv_01/pict.cpp:496:10: warning: enumeration value 'ABORT_SALVE_EN_COURS' not handled in switch [-Wswitch]
g++ -o bin/Debug/dic_gtk_opencv_01 obj/Debug/hard.o obj/Debug/ihm.o obj/Debug/ihm_sig.o obj/Debug/interrupt.o obj/Debug/main.o obj/Debug/pict.o -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 'pkg-config opencv --libs' /usr/lib/arm-linux-gnueabihf/libopencv_calib3d.so -lopencv_calib3d /usr/lib/arm-linux-gnueabihf/libopencv_contrib.so -lopencv_contrib /usr/lib/arm-linux-gnueabihf/libopencv_core.so -lopencv_core /usr/lib/arm-linux-gnueabihf/libopencv_features2d.so -lopencv_features2d /usr/lib/arm-linux-gnueabihf/libopencv_flann.so -lopencv_flann /usr/lib/arm-linux-gnueabihf/libopencv_gpu.so -lopencv_gpu /usr/lib/arm-linux-gnueabihf/libopencv_highgui.so -lopencv_highgui /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.so -lopencv_imgproc /usr/lib/arm-linux-gnueabihf/libopencv_legacy.so -lopencv_legacy /usr/lib/arm-linux-gnueabihf/libopencv_ml.so -lopencv_ml /usr/lib/arm-linux-gnueabihf/libopencv_objdetect.so -lopencv_objdetect /usr/lib/arm-linux-gnueabihf/libopencv_ocl.so -lopencv_ocl /usr/lib/arm-linux-gnueabihf/libopencv_photo.so -lopencv_photo /usr/lib/arm-linux-gnueabihf/libopencv_stitching.so -lopencv_stitching /usr/lib/arm-linux-gnueabihf/libopencv_superres.so -lopencv_superres /usr/lib/arm-linux-gnueabihf/libopencv_ts.so -lopencv_ts /usr/lib/arm-linux-gnueabihf/libopencv_video.so -lopencv_video /usr/lib/arm-linux-gnueabihf/libopencv_videostab.so -lopencv_videostab -pthread -lwiringPi -ludev -lmount
/usr/bin/ld: obj/Debug/pict.o: référence au symbole non défini «pthread_create@@GLIBC_2.4»
//lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 15 second(s))
0 error(s), 20 warning(s) (0 minute(s), 15 second(s))
I read on this
https://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux#1665110 (https://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux#1665110)
For Linux the correct command is:
gcc -pthread -o term term.c
I put -pthread in other linker option, not in library, but It doesn't work better
And because I don't understand nuance, I tried
pthread
lpthread
-pthread
-lpthread
'pthread'
...
Neither solves the problem, can you explain me again?
Thanks
well sry, i probably messed this up. i have no linux machine at the moment so i can not test it.
You have to set the -pthread option in "other compiler settings", not "other linker settings"...
https://stackoverflow.com/questions/30101874/linux-setting-codeblocks-to-compile-multithreading-c-code
and to clear things up:
-pthread is a compiler setting
pthread
lpthread is nothing....
-lpthread is a library called "pthread" or "libpthread" or some other derivative names. The "-l" in front indicates a library to the compiler/linker. This "-l" is added automatically by codeblocks if you add a library in the linker settings
'pthread' is nothing (it could be that it gets interpreted by the compiler or the shell i am not sure here. i would have to test it on linux)
`pthread`
this gets executed by codeblocks in a shell and the output of the shell is passed as command to the linker/compiler so anything inside the `` should run in shell or it wont work.
One correction: -pthread must be passed to both compiler and linker. So it must be set in other compiler options and other linker options. -lpthread might work, but it might not work... For more details read the compiler manual.
Hi,
I tried twe two proposal, with no results.
When I started this project on RPI3 + OS raspbian(jessie), I compiled directly on the terminal, with this command line, with success:
g++ DicTstHsv_v0.0.cpp `pkg-config opencv --cflags` -lwiringPi -o hsv -lmount `pkg-config --libs opencv` -ludev -std=c++11 -lpthread
then I transfered my project in CB, and add gtkmm libs, in the same card and OS, always with only one file for all my code.
about ptrhread, I use only pthread
in link libraries for "debug"
g++ -o bin/Debug/Dic_0-81 obj/Debug/main.o obj/Debug/usb_devices.o -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lglibmm-2.4 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lgio-2.0 -lcairomm-1.0 -lcairo -lsigc-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -I/usr/include/opencv /usr/lib/arm-linux-gnueabihf/libopencv_calib3d.so -lopencv_calib3d /usr/lib/arm-linux-gnueabihf/libopencv_contrib.so -lopencv_contrib /usr/lib/arm-linux-gnueabihf/libopencv_core.so -lopencv_core /usr/lib/arm-linux-gnueabihf/libopencv_features2d.so -lopencv_features2d /usr/lib/arm-linux-gnueabihf/libopencv_flann.so -lopencv_flann /usr/lib/arm-linux-gnueabihf/libopencv_gpu.so -lopencv_gpu /usr/lib/arm-linux-gnueabihf/libopencv_highgui.so -lopencv_highgui /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.so -lopencv_imgproc /usr/lib/arm-linux-gnueabihf/libopencv_legacy.so -lopencv_legacy /usr/lib/arm-linux-gnueabihf/libopencv_ml.so -lopencv_ml /usr/lib/arm-linux-gnueabihf/libopencv_objdetect.so -lopencv_objdetect /usr/lib/arm-linux-gnueabihf/libopencv_ocl.so -lopencv_ocl /usr/lib/arm-linux-gnueabihf/libopencv_photo.so -lopencv_photo /usr/lib/arm-linux-gnueabihf/libopencv_stitching.so -lopencv_stitching /usr/lib/arm-linux-gnueabihf/libopencv_superres.so -lopencv_superres /usr/lib/arm-linux-gnueabihf/libopencv_ts.so -lopencv_ts /usr/lib/arm-linux-gnueabihf/libopencv_video.so -lopencv_video /usr/lib/arm-linux-gnueabihf/libopencv_videostab.so -lopencv_videostab -lwiringPi -lmount -ludev -lpthread
Output file is bin/Debug/Dic_0-81 with size 250,33 KB
Process terminated with status 0 (0 minute(s), 11 second(s))
0 error(s), 54 warning(s) (0 minute(s), 11 second(s))
sucsess!!
then I change my target, always RPI3, always Raspbian (jessie), but an other card, with perhaps some differences about lib installed and version of them.
and my problem occurs with the pthread
I just now compiled this project in the first card, there are a lot of warnings, but a successful compilation !!
To resume, it seems that the behavior is not the same on the two targets (but with the same Hardawre and OS)
I can duplicate my OS to avoid differencies between the two card, but I prefer understand the problem.
How can I check the directories and version of pthread lib? It can be a good thing to check, isn't it?
Best
if you change anything and rebuild and you still get the (or any) error, always post a full rebuild log. We can not help without exact error messages... Now you tell us it is the same error but after discussing 3 days we get the information that it was a different error message (no offense, but i had 1000 discussions with this problem). To not even come remotely in this situation, always post a full rebuild log.
Thanks
PS. With the full rebuild log we can also tell if you put the settings in the right place...
All right,
thanks a lot for your help, and sorry for my errors using forum.
Now I'm lost in my too much software versions, 2 targets, using CB compiler/linker options, .... and your proposal (certainly very clear, but not for my understanding level) .. and my bad english.
I'm very grateful for you help.
I decide to restart from a very light software, which works on the two targets and run step by step, with a good logic, and correcting by
Quote-pthread must be passed to both compiler and linker.
I update you on my progress
And again, i don't understand where the problem is to post a full build log. I could give you a step by step direction with the build log.
But ok, i respect your decision and I will try to help you the next time...
Hi,
I remade my project, slowly and step by step, from one big file main.cpp (at the origin) to more than 15 files (.cpp + .h)
Now it's very clear, and easier to continue (adding now gtk3+ for an interface first designed with glade ....)
but now, there is no compilation error about this thread.
I tried both methods, using
Quote-pthread must be passed to both compiler and linker. So it must be set in other compiler options and other linker options
and
Quote-lpthread
the two are ok, but I choose the first one.
So I don't know where was my error, but I found and other way to eliminate it...
thanks a lot for your responses, very usefull.
Merci infiniment.