CMake 3.8.0 generates wrong link command in makefiles - c++

Problem:
After I run cmake to generate a project with a STATIC library, which completes successfully, both ninja and mingw32-make fail to make their targets at linking. For SHARED libraries or executables this same setup worked fine. I've tried this both for "Ninja" and "MinGW Makefiles" generators:
ninja output:
[2/2] Linking CXX static library hello_wsl.lib
FAILED: hello_wsl.lib
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E remove hello_wsl.lib && "" qc hello_wsl.lib CMakeFiles/hello_wsl.dir/lib_hello_world.cpp.obj && cd ."
"""" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
ninja: build stopped: subcommand failed.
mingw32-make output:
Scanning dependencies of target hello_wsl
[ 50%] Building CXX object CMakeFiles/hello_wsl.dir/lib_hello_world.cpp.obj
[100%] Linking CXX static library hello_wsl.lib
Error running link command: El parámetro no es correcto
CMakeFiles\hello_wsl.dir\build.make:93: recipe for target 'hello_wsl.lib' failed
mingw32-make.exe[2]: *** [hello_wsl.lib] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/hello_wsl.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/hello_wsl.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
Also take a look at "project_root\build\CMakeFiles\hello_wsl.dir\link.txt" generated by "MinGW Makefiles":
"" qc hello_wsl.lib CMakeFiles/hello_wsl.dir/lib_hello_world.cpp.obj
Sample project, in steps, to reproduce the problem for "MinGW Makefiles":
Install CMake 3.8.0
Install MinGWx64 6.3 windows binaries (I've downloaded them from here)
Create a root folder for this project, I'll call it project_root in this sample.
Create these subfolders inside:
project_root\build
project_root\include
project_root\include\lib_hello_world
Create these files:
project_root\include\lib_hello_world\lib_hello_world.cpp:
#include <iostream>
class HelloWorldClass{
HelloWorldClass(){
std::cout << "Hello, world!" << std::endl;
}
};
project_root\include\lib_hello_world\CMakeLists.txt:
cmake_minimum_required(VERSION 3.8.0)
project(lib_hello_world)
add_library(lib_hello_world STATIC lib_hello_world.cpp)
project_root\toolchain.cmake:
# Target system (cross compile)
set(CMAKE_SYSTEM_NAME WindowsStore)
set(CMAKE_SYSTEM_VERSION 10.0)
# BIN utils
SET(CMAKE_AR "$ENV{MINGW_W64_BIN_DIR}/ar.exe")
SET(CMAKE_OBJCOPY "$ENV{MINGW_W64_BIN_DIR}/objcopy.exe")
SET(CMAKE_OBJDUMP "$ENV{MINGW_W64_BIN_DIR}/objdump.exe")
SET(CMAKE_RANLIB "$ENV{MINGW_W64_BIN_DIR}/ranlib.exe")
SET(CMAKE_NM "$ENV{MINGW_W64_BIN_DIR}/nm.exe")
SET(CMAKE_STRIP "$ENV{MINGW_W64_BIN_DIR}/strip.exe")
# C compiler
SET(CMAKE_C_COMPILER "$ENV{MINGW_W64_BIN_DIR}/gcc.exe")
# CXX compiler
SET(CMAKE_CXX_COMPILER "$ENV{MINGW_W64_BIN_DIR}/g++.exe")
# LINKER
SET(CMAKE_LINKER "$ENV{MINGW_W64_BIN_DIR}/ld.bfd.exe")
project_root\configure.bat:
#ECHO OFF
SETLOCAL
#ECHO OFF
REM Change these variables to the corresponding paths on your own system
SET "CMAKE_EXECUTABLE=C:\Program Files\CMake\bin\cmake.exe"
SET "MINGW_W64_BIN_DIR=C:/Program Files/MinGWx64/bin"
CD "%~dp0\build"
CALL "%CMAKE_EXECUTABLE%" "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-DCMAKE_BUILD_TYPE=Debug" -G "MinGW Makefiles" "-DCMAKE_MAKE_PROGRAM='%MINGW_W64_BIN_DIR%/mingw32-make.exe'" "-DCMAKE_TOOLCHAIN_FILE='%~dp0/toolchain.cmake'" "%~dp0/include/lib_hello_world"
ENDLOCAL
project_root\build.bat:
#ECHO OFF
SETLOCAL
#ECHO OFF
REM Change this variable to the corresponding path on your own system
SET "MINGW_W64_BIN_DIR=C:/Program Files/MinGWx64/bin"
CD "%~dp0\build"
CALL "%MINGW_W64_BIN_DIR%/mingw32-make.exe"
ENDLOCAL
Finally, open CMD and run the commands:
project_root\configure.bat
project_root\build.bat
This is a sketchy fix/workaround that I found:
Create this file:
project_root\fix.bat:
#ECHO OFF
SETLOCAL
#ECHO OFF
MOVE "%~dp0\build\CMakeCache.txt" ".\"
RMDIR "%~dp0\build" /S /Q
MKDIR "%~dp0\build"
MOVE "%~dp0\CMakeCache.txt" ".\build\"
ENDLOCAL
After reproducing the error, open CMD and run:
project_root\fix.bat
project_root\configure.bat
project_root\build.bat
ninja output after fix (successfully linked):
[2/2] Linking CXX static library hello_wsl.lib
mingw32-make after fix (successfully linked):
Scanning dependencies of target hello_wsl
[ 50%] Building CXX object CMakeFiles/hello_wsl.dir/lib_hello_world.cpp.obj
[100%] Linking CXX static library hello_wsl.lib
[100%] Built target hello_wsl
A few things I did to try to figure this out:
I made a backup of CMakeCache.txt (CMakeCache.txt.before_fix) before applying the fix and reruning configure and build. There was no diference between the CMakeCache.txt.before_fix and CMakeCache.txt files after reconfiguring and successfully building the project.
I also made a backup of "rules.ninja" and then compared them with FC. This is the output of FC "project_root\rules.ninja.before_fix" "project_root\build\rules.ninja":
Comparando archivos .\rules.ninja.before_fix y .\BUILD\RULES.NINJA
***** .\rules.ninja.before_fix
rule CXX_STATIC_LIBRARY_LINKER__lib_hello_world
command = cmd.exe /C "$PRE_LINK && "C:\Program Files\CMake\bin\cmake.exe" -E remove $TARGET_FILE && "" qc $TARGET_FILE $LINK_
FLAGS $in && $POST_BUILD"
description = Linking CXX static library $TARGET_FILE
***** .\BUILD\RULES.NINJA
rule CXX_STATIC_LIBRARY_LINKER__lib_hello_world
command = cmd.exe /C "$PRE_LINK && "C:\Program Files\CMake\bin\cmake.exe" -E remove $TARGET_FILE && C:\PROGRA~1\MinGWx64\bin\
ar.exe qc $TARGET_FILE $LINK_FLAGS $in && C:\PROGRA~1\MinGWx64\bin\ranlib.exe $TARGET_FILE && $POST_BUILD"
description = Linking CXX static library $TARGET_FILE
*****
And did the same for "MinGW Makefiles". This is the output of FC "project_root\link.txt.before_fix" "project_root\build\CMakeFiles\lib_hello_world.dir\link.txt":
Comparando archivos .\link.txt.before_fix y .\BUILD\CMAKEFILES\LIB_HELLO_WORLD.DIR\LINK.TXT
***** .\link.txt.before_fix
"" qc hello_wsl.lib CMakeFiles/hello_wsl.dir/lib_hello_world.cpp.obj
***** .\BUILD\CMAKEFILES\LIB_HELLO_WORLD.DIR\LINK.TXT
C:\PROGRA~1\MinGWx64\bin\ar.exe qc lib_hello_world.lib CMakeFiles/lib_hello_world.dir/lib_hello_world.cpp.obj
C:\PROGRA~1\MinGWx64\bin\ranlib.exe lib_hello_world.lib
*****

There is some specific about CMAKE_AR and CMAKE_RUNLIB variables: according to that bugreport they should be declared as CACHED:
SET(CMAKE_AR "$ENV{MINGW_W64_BIN_DIR}/ar.exe" CACHE FILEPATH "Arhiver")
SET(CMAKE_RANLIB "$ENV{MINGW_W64_BIN_DIR}/ranlib.exe" CACHE FILEPATH "Runlib")

Related

C++ VCPKG: ld: library not found for -lprotobuf

I'm working on a C++ Project with CMake and VCPKG for Dependencies.
After I installed by dependencies: OpenCV, gRPC, Protobuf and OpenSSL,
I get a bunch of warnings and a linker error when I start my "main" Application.
Configuration is executed as
cmake -S . -B build-files/ "-DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"
This is output of CMake: Pastebin.
Build is executed as
cmake --build build-files/ --target myproject.Core -v
This is its output:
/usr/local/Cellar/cmake/3.24.2/bin/cmake -S/Users/oliverkarger/Desktop/myproject -B/Users/oliverkarger/Desktop/myproject/build-files --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 myproject.Core
/usr/local/Cellar/cmake/3.24.2/bin/cmake -S/Users/oliverkarger/Desktop/myproject -B/Users/oliverkarger/Desktop/myproject/build-files --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.24.2/bin/cmake -E cmake_progress_start /Users/oliverkarger/Desktop/myproject/build-files/CMakeFiles 8
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 src/Core/CMakeFiles/myproject.Core.dir/all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f libraries/Protos/CMakeFiles/myproject.Protos.dir/build.make libraries/Protos/CMakeFiles/myproject.Protos.dir/depend
cd /Users/oliverkarger/Desktop/myproject/build-files && /usr/local/Cellar/cmake/3.24.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/oliverkarger/Desktop/myproject /Users/oliverkarger/Desktop/myproject/libraries/Protos /Users/oliverkarger/Desktop/myproject/build-files /Users/oliverkarger/Desktop/myproject/build-files/libraries/Protos /Users/oliverkarger/Desktop/myproject/build-files/libraries/Protos/CMakeFiles/myproject.Protos.dir/DependInfo.cmake --color=
Dependencies file "libraries/Protos/CMakeFiles/myproject.Protos.dir/Configuration.grpc.pb.cc.o.d" is newer than depends file "/Users/oliverkarger/Desktop/myproject/build-files/libraries/Protos/CMakeFiles/myproject.Protos.dir/compiler_depend.internal".
Dependencies file "libraries/Protos/CMakeFiles/myproject.Protos.dir/Configuration.pb.cc.o.d" is newer than depends file "/Users/oliverkarger/Desktop/myproject/build-files/libraries/Protos/CMakeFiles/myproject.Protos.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target myproject.Protos
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f libraries/Protos/CMakeFiles/myproject.Protos.dir/build.make libraries/Protos/CMakeFiles/myproject.Protos.dir/build
make[3]: Nothing to be done for `libraries/Protos/CMakeFiles/myproject.Protos.dir/build'.
[ 62%] Built target myproject.Protos
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f src/Core/CMakeFiles/myproject.Core.dir/build.make src/Core/CMakeFiles/myproject.Core.dir/depend
cd /Users/oliverkarger/Desktop/myproject/build-files && /usr/local/Cellar/cmake/3.24.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/oliverkarger/Desktop/myproject /Users/oliverkarger/Desktop/myproject/src/Core /Users/oliverkarger/Desktop/myproject/build-files /Users/oliverkarger/Desktop/myproject/build-files/src/Core /Users/oliverkarger/Desktop/myproject/build-files/src/Core/CMakeFiles/myproject.Core.dir/DependInfo.cmake --color=
Dependencies file "src/Core/CMakeFiles/myproject.Core.dir/ConfigurationServiceProvider.cc.o.d" is newer than depends file "/Users/oliverkarger/Desktop/myproject/build-files/src/Core/CMakeFiles/myproject.Core.dir/compiler_depend.internal".
Dependencies file "src/Core/CMakeFiles/myproject.Core.dir/Core.cc.o.d" is newer than depends file "/Users/oliverkarger/Desktop/myproject/build-files/src/Core/CMakeFiles/myproject.Core.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target myproject.Core
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f src/Core/CMakeFiles/myproject.Core.dir/build.make src/Core/CMakeFiles/myproject.Core.dir/build
[ 75%] Linking CXX executable /Users/oliverkarger/Desktop/myproject/build/runtime/myproject.Core
cd /Users/oliverkarger/Desktop/myproject/build-files/src/Core && /usr/local/Cellar/cmake/3.24.2/bin/cmake -E cmake_link_script CMakeFiles/myproject.Core.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/myproject.Core.dir/ConfigurationServiceProvider.cc.o CMakeFiles/myproject.Core.dir/Core.cc.o -o /Users/oliverkarger/Desktop/myproject/build/runtime/myproject.Core -L/Users/oliverkarger/Desktop/myproject/vcpkg/installed/x64-osx/debug/lib -L/Users/oliverkarger/Desktop/myproject/build/archive -lgRPC /Users/oliverkarger/Desktop/myproject/vcpkg/installed/x64-osx/debug/lib/libre2.a /Users/oliverkarger/Desktop/myproject/vcpkg/installed/x64-osx/debug/lib/libcares.a /Users/oliverkarger/Desktop/myproject/build/archive/libmyproject.Protos.a -lresolv -lgRPC -lprotobuf
ld: library not found for -lprotobuf
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/oliverkarger/Desktop/myproject/build/runtime/myproject.Core] Error 1
make[2]: *** [src/Core/CMakeFiles/myproject.Core.dir/all] Error 2
make[1]: *** [src/Core/CMakeFiles/myproject.Core.dir/rule] Error 2
make: *** [myproject.Core] Error 2
Project: myproject.Protos is a self-built library dependency of myproject.core
CMake Files:
CMakeLists.txt
# Project Name
project("myproject")
# Options
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED 17)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ../../../build/archive)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ../../../build/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ../../../build/runtime)
# Application Metadata
set (CMAKE_PROJECT_VERSION_MAJOR 1)
set (CMAKE_PROJECT_VERSION_MINOR 0)
set (CMAKE_PROJECT_VERSION_PATCH 0)
set (CMAKE_PROJECT_VERSION_TWEAK 0)
# CMake Required Version
cmake_minimum_required(VERSION 3.24)
# Add VCPKG Toolchain
include (./vcpkg/scripts/buildsystems/vcpkg.cmake)
set (VCPKG_TARGET_TRIPLET x64-osx)
# Packages
find_package(gRPC CONFIG REQUIRED)
find_package(protobuf CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
# Third Party Includes
include_directories(./vcpkg/installed/x64-osx/include)
include_directories("include")
include_directories(${OpenCV_INCLUDE_DIRS})
# Doxygen
find_package(Doxygen)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} #ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target( docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else (DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)
# Google Test
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Directories
add_subdirectory(src/Core)
add_subdirectory(src/CoreGUI)
add_subdirectory(src/CameraServer)
# add_subdirectory(src/TestRunner)
add_subdirectory(libraries/Math)
add_subdirectory(libraries/ImageProcessing)
add_subdirectory(libraries/DataStructures)
add_subdirectory(libraries/Protos)
add_subdirectory(libraries/CommonCC)
src/myproject.Core/CMakeLists.txt
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.cc *.h)
set(SOURCES ${SOURCES})
add_executable(myproject.Core ${SOURCES})
target_link_libraries(myproject.Core gRPC)
target_link_libraries(myproject.Core re2::re2 c-ares::cares)
target_link_libraries(myproject.Core myproject.Protos)
libraries/myproject.Protos/CMakeLists.txt
file(GLOB_RECURSE PROTOS LIST_DIRECTORIES true *.proto)
set(PROTOS ${PROTOS})
add_library(myproject.Protos ${PROTOS})
target_link_libraries(myproject.Protos gRPC)
target_link_libraries(myproject.Protos protobuf)
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
protobuf_generate(TARGET myproject.Protos LANGUAGE cpp)
protobuf_generate(TARGET myproject.Protos LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")
As far as I understand the issue is that cmake can't find the library file for protobuf. But I checked with vcpkg (is a submodule of my project) that the file and path both exist.
I also tried passing the path to the .a-file directly by using
target_link_library(myproject.(Core|Protos) vcpkg/installed/x64-osx/lib/libprotobuf.a)
but that didn't resolve my issues.
How to link libprotobuf properly?

Cross compiling for arm android

i want to build c++ library for my android device, more specific i want to build taglib to use with my Qt project, i have a music app that uses taglib, i build it for windows and ubuntu and it works as expected, but now i want to cross compile taglib to use on my android phone, i searched hours to find the solution, i found some article about toolchain file and manual cmake option but none of them worked for me,
i tried to set CMAKE_SYSTEM_NAME to android and set other Cmake option like below:
set(CMAKE_SYSTEM_NAME Android)
message("this is host system ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME} {CMAKE_SYSTEM_VERSION}")
set(CMAKE_SYSTEM_VERSION 21)
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_NDK /home/sub/Downloads/android/android-ndk-r20)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)
and when i check the generated .so file with file command it show my system info like below:
libmylib.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=4245460a39baea2cbd1f28c3a2fd8037b07fe995, with debug_info, not stripped
so can anyone give me some link or help to do this?
** update
my cmake command is like below:
cmake CMakeLists.txt -DCMAKE_SYSTEM_NAME=ANDROID -DCMAKE_TOOLCHAIN_FILE=/home/sub/Downloads/android-ndk-r21/build/cmake/android.toolchain.cmake
now i use new ndk and use it android.toolchain.cmake file but the output say it doesn't use it:
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHAIN_FILE
-- Build files have been written to: /home/sub/Documents/Projects/cpp/build-for-android
my new CMakeLists.txt is :
cmake_minimum_required(VERSION 3.17)
project(addlib CXX)
# set(CMAKE_SYSTEM_NAME Android)
# message("this is host system ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
# set(CMAKE_SYSTEM_VERSION 21)
# set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
# set(CMAKE_ANDROID_NDK /home/sub/Downloads/android/android-ndk-r20)
# set(CMAKE_ANDROID_STL_TYPE gnustl_static)
set(BUILD_SHARED_LIBS true)
add_library(mylib main.cpp)
target_include_directories(mylib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
message(${CMAKE_CROSSCOMPILING})
install(TARGETS mylib DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/)
make command output with verbose on is same as below:
/usr/local/bin/cmake -S/home/sub/Documents/Projects/cpp/build-for-android -B/home/sub/Documents/Projects/cpp/build-for-android --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/sub/Documents/Projects/cpp/build-for-android'
make -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/depend
make[2]: Entering directory '/home/sub/Documents/Projects/cpp/build-for-android'
cd /home/sub/Documents/Projects/cpp/build-for-android && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles/mylib.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/sub/Documents/Projects/cpp/build-for-android'
make -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/build
make[2]: Entering directory '/home/sub/Documents/Projects/cpp/build-for-android'
[ 50%] Linking CXX shared library libmylib.so
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/mylib.dir/link.txt --verbose=1
/usr/bin/g++ -fPIC -g -shared -Wl,-soname,libmylib.so -o libmylib.so CMakeFiles/mylib.dir/main.cpp.o
make[2]: Leaving directory '/home/sub/Documents/Projects/cpp/build-for-android'
[100%] Built target mylib
make[1]: Leaving directory '/home/sub/Documents/Projects/cpp/build-for-android'
/usr/local/bin/cmake -E cmake_progress_start /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles 0
thank you

Build issues with shared_mutex and MinGW-w64

I'm currently working on a C++14 project, using MinGW-w64 and a CMake configuration (MinGW Makefile generator). I'm having a hard time building it due to compatibility issues with the shared_mutex library. To circumnavigate such problems, I'm using a custom header-only library called mingw-std-threads. After following all the instructions of the library's mark-down file, I still have errors with shared_mutex.
Here's a minimal reproducible example of the error I am getting. Source file:
#include <shared_mutex>
int main()
{
return 0;
}
The CMake configuration for the test:
# CMake 3.9 or newer
cmake_minimum_required(VERSION 3.9)
# project name, version and description
project(test)
# C++14 or higher
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# library target
add_executable(test test.cpp)
# include directories
target_include_directories(test PRIVATE .)
#MinGW threads
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
add_subdirectory(./mingw-std-threads-master)
target_link_libraries(test PRIVATE mingw_stdthreads)
# defining install rules
include(GNUInstallDirs)
install(TARGETS test
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
The project generation log:
PS C:\Users\luigi\Desktop\test> cmake --version
cmake version 3.18.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
PS C:\Users\luigi\Desktop\test> cmake -G "MinGW Makefiles" -S ./ -B build/
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw-w64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw-w64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
cmake_stdheaders_generator: output_include_path set to C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator
cmake_stdheaders_generator: MINGW_STDTHREADS_DIR: C:/Users/luigi/Desktop/test/mingw-std-threads-master
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/condition_variable>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/future>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/thread>
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/luigi/Desktop/test/build
PS C:\Users\luigi\Desktop\test>
The resulting build log with the error:
PS C:\Users\luigi\Desktop\test> cmake --build ./build -v
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\luigi\Desktop\test -BC:\Users\luigi\Desktop\test\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\luigi\Desktop\test\build\CMakeFiles C:\Users\luigi\Desktop\test\build\\CMakeFiles\progress.marks
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake --color=
Dependee "C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Dependee "C:/Users/luigi/Desktop/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Scanning dependencies of target test
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
C:\mingw-w64\mingw64\bin\g++.exe -DMINGW_STDTHREADS_GENERATED_STDHEADERS #CMakeFiles/test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles\test.dir\test.cpp.obj -c C:\Users\luigi\Desktop\test\test.cpp
In file included from C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.condition_variable.h:53,
from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/condition_variable:10,
from C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex:37,
from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/shared_mutex:9,
from C:\Users\luigi\Desktop\test\test.cpp:1:
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:306:12: error: 'std::shared_lock' has not been declared
using std::shared_lock;
^~~~~~~~~~~
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:492:24: error: 'mingw_stdthread::shared_lock' has not been declared
using mingw_stdthread::shared_lock;
^~~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\test.dir\build.make:82: CMakeFiles/test.dir/test.cpp.obj] Error 1
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:132: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe: *** [Makefile:148: all] Error 2
PS C:\Users\luigi\Desktop\test>
These are the versions of the tools I'm using:
Windows 10 Pro x64
MinGW-w64 8.1.0
CMake 3.18.3 (using 3.9 for the configuration)
mingw-std-threads 1.0.0
Thanks for helping!

static linking with cmake fails [duplicate]

This question already has answers here:
cmake and libpthread
(4 answers)
Closed 3 years ago.
I am trying to link to a static c++ Library with cmake on ubuntu.
the library is installed here: /usr/local/lib/libfrnetlib.a and headers are located here: /usr/local/include/frnetlib
Thanks for any help!
my cmakelists.txt looks like this:
###### setup
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
###### names + sources
project(ws_server)
set(SOURCE_FILES ws_server.cpp TcpListener.h WebFrame.h WebSocket.h)
###### include
include_directories(/usr/local/lib)
include_directories(/usr/local/include/frnetlib)
link_directories(/usr/local/lib/libfrnetlib.a)
###### library
find_library(frnetlib NAMES libfrnetlib.a HINTS /usr/local/lib)
if(NOT frnetlib)
message([status] "
frnetlib library not found
")
else(frnetlib)
message([status] "---------------frnetlib library found :-)")
endif()
###### executable + linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${frnetlib})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
and the output of cmake like this:
> Executing task: if [ -d build ]; then rm -Rf build; fi && mkdir build && cd build && cmake -v -DCMAKE_BUILD_TYPE=release .. && cmake --build . -v <
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
[status]--------------------------------------frnetlib library found :-)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pandapc/vscode/own_ws_server/build
/usr/local/bin/cmake -S/home/pandapc/vscode/own_ws_server -B/home/pandapc/vscode/own_ws_server/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/pandapc/vscode/own_ws_server/build/CMakeFiles /home/pandapc/vscode/own_ws_server/build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/pandapc/vscode/own_ws_server/build'
/usr/bin/make -f CMakeFiles/ws_server.dir/build.make CMakeFiles/ws_server.dir/depend
make[2]: Entering directory '/home/pandapc/vscode/own_ws_server/build'
cd /home/pandapc/vscode/own_ws_server/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/pandapc/vscode/own_ws_server /home/pandapc/vscode/own_ws_server /home/pandapc/vscode/own_ws_server/build /home/pandapc/vscode/own_ws_server/build /home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/DependInfo.cmake --color=
Dependee "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/DependInfo.cmake" is newer than depender "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/depend.internal".
Dependee "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/pandapc/vscode/own_ws_server/build/CMakeFiles/ws_server.dir/depend.internal".
Scanning dependencies of target ws_server
make[2]: Leaving directory '/home/pandapc/vscode/own_ws_server/build'
/usr/bin/make -f CMakeFiles/ws_server.dir/build.make CMakeFiles/ws_server.dir/build
make[2]: Entering directory '/home/pandapc/vscode/own_ws_server/build'
[ 50%] Building CXX object CMakeFiles/ws_server.dir/ws_server.cpp.o
/usr/bin/c++ -I/usr/local/lib -I/usr/local/include/frnetlib -std=c++11 -O3 -DNDEBUG -std=gnu++11 -o CMakeFiles/ws_server.dir/ws_server.cpp.o -c /home/pandapc/vscode/own_ws_server/ws_server.cpp
[100%] Linking CXX executable ws_server
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/ws_server.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 -O3 -DNDEBUG -rdynamic CMakeFiles/ws_server.dir/ws_server.cpp.o -o ws_server -L/usr/local/lib/libfrnetlib.a -Wl,-rpath,/usr/local/lib/libfrnetlib.a: /usr/local/lib/libfrnetlib.a
CMakeFiles/ws_server.dir/ws_server.cpp.o: In function `main':
ws_server.cpp:(.text.startup+0x18e): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/ws_server.dir/build.make:84: recipe for target 'ws_server' failed
make[2]: *** [ws_server] Error 1
make[2]: Leaving directory '/home/pandapc/vscode/own_ws_server/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/ws_server.dir/all' failed
make[1]: *** [CMakeFiles/ws_server.dir/all] Error 2
make[1]: Leaving directory '/home/pandapc/vscode/own_ws_server/build'
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
The terminal process terminated with exit code: 2
Terminal will be reused by tasks, press any key to close it.
thanks some programmer dude,
the solution is either to set this flag:
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
or use this cmakelists.txt
###### setup
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
###### names + sources
project(ws_server)
set(SOURCE_FILES ws_server.cpp TcpListener.h WebFrame.h WebSocket.h)
###### library
find_library(frnetlib NAMES libfrnetlib.a HINTS /usr/local/lib)
find_package( Threads )
if(NOT frnetlib)
message([status] "
frnetlib library not found!
")
else(frnetlib)
message([status] "--------------------------------------frnetlib library found :-)")
endif()
###### executable + linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${frnetlib} ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

/usr/bin/ld: cannot find -lpthreads

I'm compiling NVIDIA Caffe tool on a Fedora 22 and I having problems to find lpthread library:
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_d410e/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_d410e.dir/build.make CMakeFiles/cmTC_d410e.dir/build
gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o
/usr/bin/cc -o CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o -c /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_d410e
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d410e.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o -o cmTC_d410e -rdynamic
CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o: En la función `main':
CheckSymbolExists.c:(.text+0x16): referencia a `pthread_create' sin definir
collect2: error: ld devolvió el estado de salida 1
CMakeFiles/cmTC_d410e.dir/build.make:97: recipe for target 'cmTC_d410e' failed
gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_d410e/fast' failed
gmake[1]: *** [cmTC_d410e] Error 1
gmake: *** [cmTC_d410e/fast] Error 2
File /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#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
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_e693b/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_e693b.dir/build.make CMakeFiles/cmTC_e693b.dir/build
gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTC_e693b
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e693b.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o -o cmTC_e693b -rdynamic -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld outputs 1
CMakeFiles/cmTC_e693b.dir/build.make:97: recipe for target 'cmTC_e693b' failed
gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_e693b/fast' failed
gmake[1]: *** [cmTC_e693b] Error 1
gmake: *** [cmTC_e693b/fast] Error 2
It seems that it doesn't find pthreads lib (/usr/bin/ld: cannot find -lpthreads), but running command find / name "*pthread*" it outputs this:
/usr/lib64/libpthread.so
/usr/lib64/libpthread.a
/usr/lib64/libpthread_nonshared.a
/usr/lib64/libpthread-2.21.so
/usr/lib64/libpthread.so.0
But there is something strange with this, becaue CMakeOutut.log has this:
Determining if the function pthread_create exists in the pthread passed with the following output:
Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_705ba/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_705ba.dir/build.make CMakeFiles/cmTC_705ba.dir/build
gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTC_705ba
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_705ba.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o -o cmTC_705ba -rdynamic -lpthread
gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
It has this line using lpthread:
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o -o cmTC_705ba -rdynamic -lpthread
And this is CMakeList.txt:
cmake_minimum_required(VERSION 2.8.7)
# ---[ Caffe project
project(Caffe C CXX)
# ---[ Caffe version
set(CAFFE_TARGET_VERSION "0.14.5")
set(CAFFE_TARGET_SOVERSION "0.14")
add_definitions(-DCAFFE_VERSION=${CAFFE_TARGET_VERSION})
# ---[ Using cmake scripts and modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
include(ExternalProject)
include(cmake/Utils.cmake)
include(cmake/Targets.cmake)
include(cmake/Misc.cmake)
include(cmake/Summary.cmake)
include(cmake/ConfigGen.cmake)
# ---[ Options
caffe_option(CPU_ONLY "Build Caffe without CUDA support" OFF) # TODO: rename to USE_CUDA
caffe_option(USE_CUDNN "Build Caffe with cuDNN library support" ON IF NOT CPU_ONLY)
caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
caffe_option(BUILD_python "Build Python wrapper" ON)
set(python_version "2" CACHE STRING "Specify which Python version to use")
caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
caffe_option(BUILD_docs "Build documentation" ON IF UNIX OR APPLE)
caffe_option(BUILD_python_layer "Build the Caffe Python layer" ON)
caffe_option(USE_OPENCV "Build with OpenCV support" ON)
caffe_option(USE_LEVELDB "Build with levelDB" ON)
caffe_option(USE_LMDB "Build with lmdb" ON)
caffe_option(ALLOW_LMDB_NOLOCK "Allow MDB_NOLOCK when reading LMDB files (only if necessary)" OFF)
# ---[ Dependencies
include(cmake/Dependencies.cmake)
# ---[ Flags
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()
if(USE_libstdcpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
endif()
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
# ---[ Warnings
caffe_warnings_disable(CMAKE_CXX_FLAGS -Wno-sign-compare -Wno-uninitialized)
# ---[ Config generation
configure_file(cmake/Templates/caffe_config.h.in "${PROJECT_BINARY_DIR}/caffe_config.h")
# ---[ Includes
set(Caffe_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/3rdparty)
include_directories(${Caffe_INCLUDE_DIR} ${PROJECT_BINARY_DIR} ${THIRDPARTY_DIR})
include_directories(BEFORE src) # This is needed for gtest.
# ---[ Subdirectories
add_subdirectory(src/gtest)
add_subdirectory(src/caffe)
add_subdirectory(tools)
add_subdirectory(examples)
add_subdirectory(python)
add_subdirectory(matlab)
add_subdirectory(docs)
# ---[ Linter target
add_custom_target(lint COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
# ---[ pytest target
add_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )
add_dependencies(pytest pycaffe)
# ---[ Configuration summary
caffe_print_configuration_summary()
# ---[ Export configs generation
caffe_generate_export_configs()
What do I have to install? Does libphreads exist or I have to use libphread?
You have a typo. You should use -lpthread instead of -lpthreads.
Alternatively you can just use -pthread, that also works.
I have this error when I follow the caffe doc on a new Ubuntu, and after some Google with caffe collect2: error: ld returned 1 exit status, I find I was lack of some packages, not typo:
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler libatlas-base-dev
sudo apt-get install python-dev python-pip gfortran
For more detailed info, ref here.
The problem is caused by googletest, and just set the following line of CMakeList.txt of googletest:
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." ON)
by the flags on.
The reason is:
We must check for the threads library under a number of different
names; the ordering is very important because some systems
(e.g. DEC) have both -lpthread and -lpthreads, where one of the
libraries is broken (non-POSIX).