0

I would like to compile gtkmm programs that use mutithreading. I used this example to test multithreading.

Unfortunately I get some linking errors when I compile:

/usr/bin/ld: src/multithreadingandprogress.p/multithreadingandprogress-window.cpp.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'

and:

/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line

I guess I need some LDFLAGS or some environment variables to set in the settings?? Is there anyone who knowes exactly how to set up gnome builder for this task to compile?

Any help? Thx

useruser
  • 1
  • 4
  • Did you add -pthread as documented in the article you provided? – BobMorane Nov 26 '21 at 01:13
  • 1
    Yes, so the solution was to add "dependency('threads')," in the "multithreadingandprogress_deps" array of the meson.build file (where "multithreadingandprogress" is the name of the program in lowercase). Thx BobMorane – useruser Dec 05 '21 at 15:30
  • I encourage you to publish an official answer, for anyone else trying to find the answer. Good job! – BobMorane Dec 05 '21 at 18:45

1 Answers1

0

I had similar issues while building the same tutorial in gtkmm-3.0. Adding the following line in the CMake file fixed the issue.

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

If you are not using CMake you need to add this flag for your compiler manually.

The complete CMake for using threads in linux systems must contain following commands:

      set(CMAKE_THREAD_LIBS_INIT "-lpthread")
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
      set(CMAKE_HAVE_THREADS_LIBRARY 1)
      set(CMAKE_USE_WIN32_THREADS_INIT 0)
      set(CMAKE_USE_PTHREADS_INIT 1)
      set(THREADS_PREFER_PTHREAD_FLAG ON)

Check this link for a more complete approach with CMake.

NOVA1323
  • 69
  • 8