1

I am trying to compile the code provided here, but I am stuck when trying to run the command cmake ..

When running this command a lot of stuff is output to the screen and one of those things are those lines:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
G2O_EXT_CSPARSE

and also

-- Configuring incomplete, errors occurred!
See also "/home/yalishanda/Downloads/lsd_slam_noros-master/build/CMakeFiles/CMakeOutput.log".
See also "/home/yalishanda/Downloads/lsd_slam_noros-master/build/CMakeFiles/CMakeError.log".

So when doing cat of CMakeError.log I can see among many other things this:

/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_792f7.dir/build.make:97: recipe for target 'cmTC_792f7' failed

I already installed pthreads using:

 sudo apt-get install libpthread-stubs0-dev

which even returned:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libpthread-stubs0-dev is already the newest version (0.3-4).
The following package was automatically installed and is no longer required:
  snap-confine
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

So this shouldn't be the issue I think, yet the error output file complains about this.

I also already read 2 other posts on SE related to this kind of errors, but they didn't solve my issue.

Could someobody explain what I am doing incorrectly?

6

3 Answers 3

4

This appears to be a long-standing CMake bug. Something else is going wrong, CMake gets confused, and reports this spurious problem instead of the real error.

Look for "thread" in your CMakeLists.txt file and temporarily remove that.

2
  • Thank you, this was the case for me. Actually all I had to do was scroll up higher in CMake's output to find the root cause. Apr 3, 2020 at 7:33
  • Do you have references to this "long-standing CMake bug"? Removing "thread" is often not a solution, as linking against pthreads may be necessary. Nov 29, 2021 at 16:03
1

This error may related with linking of library. I was facing the same issue but installing build-essential package solved the problem. Try apt-get install build-essential

1

This is an old question, but it's one of the first hits on my search engine when I search the error message:

/usr/bin/ld: cannot find -lpthreads

The problem here is the typo: -lpthreads should be -lpthread; there is no trailing s.

As an alternative, at least on some versions of ld, you also can use just -pthread.

6
  • @sancho.sReinstateMonicaCellio What do you mean? Nov 29, 2021 at 16:07
  • If I mean to use this as a solution to a problem, it should probably show what file/s have to be changed, how to change them, etc. Where is -lpthreads to be changed by -lpthread? Nov 29, 2021 at 16:18
  • @sancho.sReinstateMonicaCellio That's a commandline flasg passed to your linker, so it would usually belong in your Makefile, build scripts, whatever you use to invoke your toolchain. For this kind of question, git grep is your friend. Nov 29, 2021 at 16:25
  • I know exactly what that is. But the problem in the OP is with cmake, which is a framework for automated generation of the Makefile. Is there any place in a CMakeLists.txt where you can introduce your change? I guess this answer does not address the problem of the OP... it is merely a "related observation". Related: stackoverflow.com/questions/31948521/…, github.com/pytorch/pytorch/issues/9310 Nov 29, 2021 at 16:48
  • Oh, some CMake thing ... I have no idea. I've never used it. Nov 29, 2021 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .