Jump to content

Cmake error I cannot understand

mrchow19910319

I was trying to install Polybar on my system while I stumble upon these commands :

 

$ mkdir build
$ cd build
$ cmake ..
$ make -j$(nproc)
$ sudo make install

after install cmake from the app store, I tried the commands above.
Here is the error message I got: (CMakeError.log)

 

Spoiler

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/zhouxiang/polybar/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_e33d6/fast"
/usr/bin/make -f CMakeFiles/cmTC_e33d6.dir/build.make CMakeFiles/cmTC_e33d6.dir/build
make[1]: Entering directory '/home/zhouxiang/polybar/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_e33d6.dir/CheckSymbolExists.cxx.o
/home/linuxbrew/.linuxbrew/bin/c++    -Wall -Wextra -Wpedantic    -o CMakeFiles/cmTC_e33d6.dir/CheckSymbolExists.cxx.o -c /home/zhouxiang/polybar/build/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
Linking CXX executable cmTC_e33d6
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e33d6.dir/link.txt --verbose=1
/home/linuxbrew/.linuxbrew/bin/c++   -Wall -Wextra -Wpedantic     -rdynamic CMakeFiles/cmTC_e33d6.dir/CheckSymbolExists.cxx.o  -o cmTC_e33d6 
CMakeFiles/cmTC_e33d6.dir/CheckSymbolExists.cxx.o: In function `main':
CheckSymbolExists.cxx:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_e33d6.dir/build.make:97: recipe for target 'cmTC_e33d6' failed
make[1]: *** [cmTC_e33d6] Error 1
make[1]: Leaving directory '/home/zhouxiang/polybar/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_e33d6/fast' failed
make: *** [cmTC_e33d6/fast] Error 2

File /home/zhouxiang/polybar/build/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

 

after some google search about this undefined reference to pthread_create here are some of the answer I found. But I do not know where to put it inside the CMakeList.txt file…

 

answer one : https://github.com/mmp/pbrt-v3/issues/24

 

Quote

Hi,
the nicest solution would be to add
${CMAKE_THREAD_LIBS_INIT} to all of the TARGET_LINK_LIBRARIES commands referencing pbrt in CMakeLists.txt.
Could you verify that this works? If so, I’ll commit a fix.

Here is my CMake.list file

 

#
# Build configuration
#
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)

# Enable ccache by default and as early as possible because project() performs
# checks on the compiler
option(ENABLE_CCACHE "Enable ccache support" ON)
if(ENABLE_CCACHE)
  message(STATUS "Trying to enable ccache")
  find_program(BIN_CCACHE ccache)

  string(ASCII 27 esc)
  if(NOT BIN_CCACHE)
    message(STATUS "${esc}[33mCouldn't locate ccache, disabling ccache...${esc}[0m")
  else()
    # Enable only if the binary is found
    message(STATUS "${esc}[32mUsing compiler cache ${BIN_CCACHE}${esc}[0m")
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BIN_CCACHE})
  endif()
endif()

project(polybar CXX)

# Extract version information from version.txt. The first line that looks like
# a version string is used, so the file supports comments
file(STRINGS version.txt version_txt REGEX "^[0-9]+\\.[0-9]+\\.[0-9]+.*$" LIMIT_COUNT 1)

# If we are in a git repo we can get the version information from git describe
execute_process(COMMAND git describe --tags --dirty=-dev
  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  RESULT_VARIABLE git_result
  OUTPUT_VARIABLE git_describe
  OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)

if(git_result EQUAL "0")
  set(APP_VERSION "${git_describe}")
else()
  message(STATUS "Could not detect version with git, falling back to built-in version information.")
  set(APP_VERSION "${version_txt}")
endif()

set(CMAKE_MODULE_PATH
  ${CMAKE_MODULE_PATH}
  ${PROJECT_SOURCE_DIR}/cmake
  ${PROJECT_SOURCE_DIR}/cmake/common
  ${PROJECT_SOURCE_DIR}/cmake/modules)

include(GNUInstallDirs)
include(utils)
include(01-core)
include(02-opts)
include(03-libs)
include(04-targets)
include(05-summary)

if(BUILD_DOC)
  add_subdirectory(doc)
endif()
add_subdirectory(contrib/bash)
add_subdirectory(contrib/zsh)
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(src bin)

# We need to enable testing in the root folder so that 'ctest' and 'make test'
# can be run in the build directory
if(BUILD_TESTS)
  enable_testing()
  add_subdirectory(tests)
endif()


#
# Generate configuration file
#

set(MODULES_LEFT "bspwm i3")
set(MODULES_CENTER "mpd")
set(MODULES_RIGHT "filesystem xbacklight alsa pulseaudio xkeyboard memory cpu wlan eth battery temperature date powermenu")

set(FONT_FIXED "fixed:pixelsize=10")
set(FONT_UNIFONT "unifont:fontformat=truetype")
set(FONT_SIJI "siji:pixelsize=10")

queryfont(FONT_FIXED ${FONT_FIXED} FIELDS family pixelsize)
queryfont(FONT_UNIFONT ${FONT_UNIFONT} FIELDS family fontformat)
queryfont(FONT_SIJI ${FONT_SIJI} FIELDS family pixelsize)

# Strip disabled modules {{{

if(NOT ENABLE_PULSEAUDIO)
  string(REPLACE " pulseaudio" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT ENABLE_ALSA)
  string(REPLACE " alsa" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT ENABLE_I3)
  string(REPLACE " i3" "" MODULES_LEFT ${MODULES_LEFT})
endif()
if(NOT ENABLE_MPD)
  string(REPLACE "mpd" "" MODULES_CENTER ${MODULES_CENTER})
endif()
if(NOT ENABLE_NETWORK)
  string(REPLACE " wlan eth" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT WITH_XRANDR)
  string(REPLACE "xbacklight " "backlight-acpi " MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT WITH_XKB)
  string(REPLACE "xkeyboard " "" MODULES_RIGHT ${MODULES_RIGHT})
endif()

# }}}
# Get battery/adapter name {{{

string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY})
string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER})
file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*)
file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*)
if(BAT_LIST)
  list(GET BAT_LIST 0 BATTERY)
else()
  set(BATTERY BAT0)
endif()
if(ADP_LIST)
  list(GET ADP_LIST 0 ADAPTER)
else()
  set(ADAPTER ADP1)
endif()

# }}}
# Get network interfaces {{{

if(ENABLE_NETWORK)
  file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*)
  foreach(INTERFACE ${IFLIST})
    if(NOT ${INTERFACE} STREQUAL "lo")
      file(GLOB IS_WIRELESS /sys/class/net/${INTERFACE}/wireless)
      if(IS_WIRELESS)
        set(INTERFACE_WLAN ${INTERFACE})
      else()
        set(INTERFACE_ETH ${INTERFACE})
      endif()
    endif()
  endforeach()
  if(NOT INTERFACE_ETH)
    set(INTERFACE_ETH net0)
  endif()
  if(NOT INTERFACE_WLAN)
    set(INTERFACE_WLAN net1)
  endif()
endif()

# }}}
# Configure and install {{{

configure_file(
  ${CMAKE_CURRENT_LIST_DIR}/config.cmake
  ${CMAKE_CURRENT_LIST_DIR}/config
  ESCAPE_QUOTES @ONLY)

install(FILES config
  DESTINATION ${CMAKE_INSTALL_DOCDIR}
  COMPONENT config)

# }}}

 

 

or it is some other issue… does anyone knows a fix here?

 

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

52 minutes ago, Sauron said:

Did you install the dependencies?

no.... let me check those real quick..

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×