cmake 3.10 cant internally test the blas library - cmake

I cant get working my blas library with cmake. I have arch-linxux, both blas and cmake are installed with pacman. Cant understand where is problem :-(. I made cmake to print out the output of macro CHECK_FORTRAN_FUNCTION_EXISTS, because it fails there. Maybe I dont have proper configuration of ld?
My simple testing CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(Test C Fortran)
find_package(BLAS)
Error part from output:
-- Looking for Fortran sgemm
-- Change Dir: /home/jiri/test_lapack/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_486fc/fast"
/usr/bin/make -f CMakeFiles/cmTC_486fc.dir/build.make CMakeFiles/cmTC_486fc.dir/build
make[1]: Entering directory '/home/jiri/test_lapack/CMakeFiles/CMakeTmp'
Building Fortran object CMakeFiles/cmTC_486fc.dir/testFortranCompiler.f.o
/usr/bin/gfortran -c /home/jiri/test_lapack/CMakeFiles/CMakeTmp/testFortranCompiler.f -o CMakeFiles/cmTC_486fc.dir/testFortranCompiler.f.o
Linking Fortran executable cmTC_486fc
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_486fc.dir/link.txt --verbose=1
/usr/bin/gfortran CMakeFiles/cmTC_486fc.dir/testFortranCompiler.f.o -o cmTC_486fc /usr/local/lib64/libblas.a
/usr/bin/ld: /usr/local/lib64/libblas.a(sgemm.f.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib64/libblas.a(xerbla.f.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_486fc.dir/build.make:99: cmTC_486fc] Error 1
make[1]: Leaving directory '/home/jiri/test_lapack/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_486fc/fast] Error 2
-- Looking for Fortran sgemm - not found

Related

Linking problems with yaml-cpp

I am trying to incorporate yaml-cpp into my project.
I have a "Demes" class where I need to parse a YAML file.
This is the relevant method in Demes.cpp:
#include "Demes.hpp"
void Demes::parse(const std::string& fileName)
{
YAML::Node test = YAML::LoadFile(fileName);
}
where Demes.hpp includes the yaml-cpp headers and declares the 'parse' method.
Building with make -VERBOSE=1 (as suggested by #Tsyvarev) gives:
[100%] Linking CXX executable momentspp
cd /home/gvbarroso/Devel/momentspp/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/momentspp.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native CMakeFiles/momentspp.dir/Log.cpp.o CMakeFiles/momentspp.dir/PolymorphismData.cpp.o CMakeFiles/momentspp.dir/SumStatsLibrary.cpp.o CMakeFiles/momentspp.dir/Drift.cpp.o CMakeFiles/momentspp.dir/Migration.cpp.o CMakeFiles/momentspp.dir/Mutation.cpp.o CMakeFiles/momentspp.dir/Recombination.cpp.o CMakeFiles/momentspp.dir/Epoch.cpp.o CMakeFiles/momentspp.dir/Model.cpp.o CMakeFiles/momentspp.dir/OptimizationWrapper.cpp.o CMakeFiles/momentspp.dir/Demes.cpp.o CMakeFiles/momentspp.dir/main.cpp.o -o momentspp -Wl,-rpath,/home/gvbarroso/.local/lib: /home/gvbarroso/.local/lib/libbpp-phyl3.so.1.0.0 /usr/lib/x86_64-linux-gnu/libboost_iostreams.so.1.74.0 /home/gvbarroso/.local/lib/libbpp-seq3.so.1.0.0 /home/gvbarroso/.local/lib/libbpp-core3.so.1.0.0
/usr/bin/ld: CMakeFiles/momentspp.dir/Demes.cpp.o: in function Demes::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': Demes.cpp:(.text+0x4c): undefined reference to YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
/usr/bin/ld: Demes.cpp:(.text+0x12c): undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/momentspp.dir/build.make:277: src/momentspp] Error 1
make[2]: Leaving directory '/home/gvbarroso/Devel/momentspp/build'
make[1]: *** [CMakeFiles/Makefile2:125: src/CMakeFiles/momentspp.dir/all] Error 2
make[1]: Leaving directory '/home/gvbarroso/Devel/momentspp/build'
make: *** [Makefile:156: all] Error 2
I am using CMake to build my project, but I am still fairly unfamiliar with it.
EDIT: I forgot to mention that I have two CMakeLists.txt files, one inside src and the other inside the external build.
The start of my CMakeLists.txt file in the external build is:
cmake_minimum_required (VERSION 3.5.0)
project (momentspp CXX)
SET(CMAKE_CXX_FLAGS "-std=c++20 -Weffc++ -Wshadow -Wall -Wextra -ffast-math -O3 -march=native")
And the part of it where I look for yaml-cpp is:
FIND_PACKAGE(yaml-cpp REQUIRED)
IF(yaml-cpp_FOUND)
INCLUDE_DIRECTORIES(${yaml-cpp_INCLUDE_DIRS})
SET(LIBS {yaml-cpp_LIBRARIES})
MESSAGE("-- yaml-cpp libraries found here:")
MESSAGE(" includes: ${yaml-cpp_INCLUDE_DIRS}")
ENDIF()
My full CMakeLists.txt file inside src is:
SET(momentspp_CPP
Log.cpp
PolymorphismData.cpp
SumStatsLibrary.cpp
Drift.cpp
Migration.cpp
Mutation.cpp
Recombination.cpp
Epoch.cpp
Model.cpp
OptimizationWrapper.cpp
Demes.cpp
main.cpp
)
ADD_EXECUTABLE (momentspp ${momentspp_CPP})
SET(momentspp-targets momentspp)
FOREACH (target ${momentspp-targets})
TARGET_LINK_LIBRARIES(${target} ${BPP_LIBS_SHARED} ${BOOST_LIBS_SHARED} ${EIGEN3_LIBS_SHARED} ${yaml-cpp_LIBS_SHARED})
TARGET_LINK_LIBRARIES (${target} ${LIBS})
ENDFOREACH (target)
INSTALL(TARGETS ${momentspp-targets} DESTINATION ${CMAKE_INSTALL_BINDIR})
and this was working prior to the inclusion of yaml-cpp.
This feels like a rather complicated CMake set-up, but I am copying and editing it from a previous project where someone else helped me with it.
How can I fix the linking issue?
I tried looking similar questions around here, but couldn't get their solutions to work for me (apparently those people where not using CMake to build their projects).
Thank you,
Gustavo

How to statically link PROJ to pybind11

I'm interested in statically linking PROJ to a library created with pybind11.
but, I get error by cmake.
Why am I getting this error and how can I fix it?
My CMakeLists.txt is this.
cmake_minimum_required(VERSION 3.4)
project(myearth LANGUAGES CXX)
add_subdirectory(pybind11)
pybind11_add_module(myearth MyEarth.cpp)
include_directories(${CMAKE_SOURCE_DIR}/PROJ/include)
add_library(proj4 STATIC IMPORTED)
set_target_properties(proj4 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/PROJ/lib/libproj.a)
target_link_libraries(myearth PRIVATE proj4)
CMake Error.
I think fPIC option is for shared library. so, libproj.a is not necessary this option because this is static library.
(venv) ~/Projects/LinkLibTest/MySample/build$ make
[ 50%] Building CXX object CMakeFiles/myearth.dir/MyEarth.cpp.o
[100%] Linking CXX shared module myearth.cpython-36m-x86_64-linux-gnu.so
/usr/bin/ld: ../PROJ/lib/libproj.a(proj_4D_api.o): relocation R_X86_64_PC32 against symbol `pj_errno' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/myearth.dir/build.make:98: myearth.cpython-36m-x86_64-linux-gnu.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/myearth.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
(venv) ~/Projects/LinkLibTest/MySample/build$
I created libproj.a by the following command.
$ ./configure --prefix=/output --disable-shared
$ sudo make
$ sudo make install
Linux Mint 20.3 64bit
CMake v3.22.2
PROJ v5.2.0 (https://proj.org/)
Python v3.6.8
Thank you.
Shared libraries must have position independent code, but your version of PROJ was built without it; you will have to rebuild PROJ with PIC.
$ ./configure --prefix=/output --with-pic

Unable to build FreeRTOS WIN32 demo in Clion

Below is the CmakeLists file that I'm using. I'm using the linker flags from eclipse as it seems to build in eclipse properly.
project(new1 LANGUAGES CXX C)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 14)
# Compiler options for compiling MinGW targets.
set(CMAKE_C_FLAGS_DEBUG "-D_WIN32_WINNT=0x0601 -DprojCOVERAGE_TEST=0 -fmessage-length=0 -Wcast-qual")
#-------------------------------------------------------------
# Linker options for Linking MinGW targets.
set(CMAKE_EXE_LINKER_FLAGS "-Xlinker -lwinmm")
#-------------------------------------------------------------
include_directories(FreeRTOS/Source/include
FreeRTOS/Source/portable/MSVC-MingW
/)
add_subdirectory(FreeRTOS/Source)
add_executable(application main.cpp)
target_link_libraries(application kernel)
target_link_libraries(application winmm.lib)
The below is the build output
"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -E cmake_link_script CMakeFiles\application.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -E remove -f CMakeFiles\application.dir/objects.a
"F:\TrueSTUDIO for STM32 9.0.0\PCTools\bin\ar.exe" cr CMakeFiles\application.dir/objects.a #CMakeFiles\application.dir\objects1.rsp
"F:\TrueSTUDIO for STM32 9.0.0\PCTools\bin\g++.exe" -g -Xlinker -lwinmm -Wl,--whole-archive CMakeFiles\application.dir/objects.a -Wl,--no-whole-archive -o application.exe -Wl,--out-implib,libapplication.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\application.dir\linklibs.rsp
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0x15): undefined reference to `timeGetDevCaps#8'
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0x2d): undefined reference to `timeBeginPeriod#4'
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0xd5): undefined reference to `timeGetDevCaps#8'
FreeRTOS/Source/portable/MSVC-MingW/libport.a(port.c.obj):port.c:(.text+0xe7): undefined reference to `timeEndPeriod#4'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [application.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/application.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/application.dir/rule] Error 2
mingw32-make.exe: *** [application] Error 2
Can somebody help please.
So, there was no issue with linking the winmm library it is just that I'm linking this to a wrong target. It was a dependency of the windows port in freeRTOS/Source/Portable.

CMake: cannot create target because another target with the same name already exists

I'm trying to install plexe-sumo with cmake. I followed the tutorial at plexe.car2x.org and here's the results:
-- CMAKE_BUILD_TYPE: Release
-- CMAKE_BINARY_DIR: /home/cc/src/plexe-sumo/build-release
-- CMAKE_SOURCE_DIR: /home/cc/src/plexe-sumo
--
-- Platform:
-- Host: Linux4.15.0-34-genericx86_64
-- CMake: 3.12.2
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
--
-- Found Proj: /usr/lib/x86_64-linux-gnu/libproj.so
CMake Error at /usr/local/share/cmake-3.12/Modules/UseSWIG.cmake:627 (add_custom_target):
add_custom_target cannot create target "libsumo_swig_compilation" because
another target with the same name already exists. The existing target is a
custom target created in source directory
"/home/cc/src/plexe-sumo/src/libsumo". See documentation for policy
CMP0002 for more details.
Call Stack (most recent call first):
src/libsumo/CMakeLists.txt:39 (SWIG_ADD_LIBRARY)
-- Enabled features: Linux-4.15.0-34-generic Proj GUI GDAL OSG GL2PS SWIG
-- Configuring incomplete, errors occurred!
There is no file named 'libsumo_swig_compilation' under "/home/cc/src/plexe-sumo/src/libsumo".
Then I checked the error log file, but the errors shown are about pthread saying 'undefined reference to pthread_creat' and 'cannot find -lpthreads'. Actually my pthread library is installed at 'libc6: /lib/x86_64-linux-gnu/libpthread.so.0'.
So I was wondering what's the exact problem here and how to solve it. I'm using a virtual machine with ubuntu 16. I appreciate your help!
Following is the error log file:
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_050d5/fast"
/usr/bin/make -f CMakeFiles/cmTC_050d5.dir/build.make CMakeFiles/cmTC_050d5.dir/build
make[1]: Entering directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o
/usr/bin/cc -Wall -pedantic -Wextra -o CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o -c /home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp/CheckSymbolExists.c
/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function ‘main’:
/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:11: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
return ((int*)(&pthread_create))[argc];
^
Linking C executable cmTC_050d5
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_050d5.dir/link.txt --verbose=1
/usr/bin/cc -Wall -pedantic -Wextra -rdynamic CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o -o cmTC_050d5
CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_050d5.dir/build.make:86: recipe for target 'cmTC_050d5' failed
make[1]: *** [cmTC_050d5] Error 1
make[1]: Leaving directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Makefile:121: recipe for target 'cmTC_050d5/fast' failed
make: *** [cmTC_050d5/fast] Error 2
File /home/cc/src/plexe-sumo/build-release/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/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_9f654/fast"
/usr/bin/make -f CMakeFiles/cmTC_9f654.dir/build.make CMakeFiles/cmTC_9f654.dir/build
make[1]: Entering directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_9f654.dir/CheckFunctionExists.c.o
/usr/bin/cc -Wall -pedantic -Wextra -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_9f654.dir/CheckFunctionExists.c.o -c /usr/local/share/cmake-3.12/Modules/CheckFunctionExists.c
Linking C executable cmTC_9f654
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9f654.dir/link.txt --verbose=1
/usr/bin/cc -Wall -pedantic -Wextra -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_9f654.dir/CheckFunctionExists.c.o -o cmTC_9f654 -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_9f654.dir/build.make:86: recipe for target 'cmTC_9f654' failed
make[1]: *** [cmTC_9f654] Error 1
make[1]: Leaving directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Makefile:121: recipe for target 'cmTC_9f654/fast' failed
make: *** [cmTC_9f654/fast] Error 2
My assumption is that this is really a behavior which only the new cmake shows. You could try to rename all references to libsumo in the java part of the CMakeLists.txt or simply use the CMakeLists of the main line sumo here: https://github.com/eclipse/sumo/blob/master/src/libsumo/CMakeLists.txt

handmade Makefile to Cmake with static library

Here is a MakeFile for my project, since I'm using CLion for as my IDE, I need a Cmake configuration. I could not convert the following Makefile correctly.
all: VisualCryptography
VisualCryptography: VisualCryptographyGPU.o VisualCryptographyMC.o ExtVisualCryptographyCPU.o ExtVisualCryptographyGPU.o ExtVisualCryptographyMC.o VisualCryptographyCPUTest.o
g++ *.o -L/usr/local/cuda/lib64 -lcudart -lpthread ./lib/libVC.a -o VisualCryptography
rm -rf *.o
VisualCryptographyMC.o: ./source/VisualCryptographyMC.c
g++ -lpthread -c ./source/VisualCryptographyMC.c
VisualCryptographyCPUTest.o: ./source/VisualCryptographyCPUTest.c
g++ -lpthread -c ./source/VisualCryptographyCPUTest.c
VisualCryptographyGPU.o: ./source/VisualCryptographyGPU.cu
/usr/local/cuda/bin/nvcc -c -arch=compute_20 -code=sm_20 -lm ./source/VisualCryptographyGPU.cu
ExtVisualCryptographyCPU.o: ./source/ExtVisualCryptographyCPU.c
g++ -c ./source/ExtVisualCryptographyCPU.c
ExtVisualCryptographyGPU.o: ./source/ExtVisualCryptographyGPU.cu
/usr/local/cuda/bin/nvcc -c -arch=compute_20 -code=sm_20 -lm ./source/ExtVisualCryptographyGPU.cu
ExtVisualCryptographyMC.o: ./source/ExtVisualCryptographyMC.c
g++ -lpthread -c ./source/ExtVisualCryptographyMC.c
clean:
rm -rf *.o VisualCryptography
Here is my CMakeList.txt file:
cmake_minimum_required(VERSION 3.7)
project(VC)
set(CMAKE_CXX_STANDARD 11)
find_package (Threads)
find_package(CUDA REQUIRED)
link_directories(${CMAKE_BINARY_DIR}/lib)
set(SOURCE_FILES
source/common.h
source/ExtVisualCryptographyGPU.cu
source/ExtVisualCryptographyCPU.c
source/ExtVisualCryptographyMC.c
source/preprocess.h
source/VisualCryptographyCPUDefault.h
source/VisualCryptographyCPUTest.c
source/VisualCryptographyCPUTest.h
source/VisualCryptographyMC.c
source/VisualCryptographyGPU.cu
source/VisualCryptographyGPU.h
source/VisualCryptographyMC.h)
add_executable(VC ${SOURCE_FILES})
target_link_libraries(VC ${CMAKE_THREAD_LIBS_INIT} libVC.a)
Where am I doing wrong?
This is the error that I'm getting:
/usr/bin/ld: cannot find -lVC
collect2: error: ld returned 1 exit status
CMakeFiles/VC.dir/build.make:172: recipe for target 'VC' failed
make[3]: *** [VC] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/VC.dir/all' failed
make[2]: *** [CMakeFiles/VC.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/VC.dir/rule' failed
make[1]: *** [CMakeFiles/VC.dir/rule] Error 2
Makefile:118: recipe for target 'VC' failed
make: *** [VC] Error 2
I also should note that the libVC.a is in lib sub dir of my project, and all other source codes are in source sub dir. the main function is also in libVC.a, which is static.
Try changing the name as oLen suggested, this behavior is seen in some versions of Cmake. You can check another version if you insist on using the same name.