Can't find package X11 on WSL - cmake

I'm trying to build an opensource project on WSL using cmake.
I'm getting first these two errors which I don't understand :
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:185 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
The CXX compiler identification is GNU 9.3.0
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCXXCompiler.cmake:210 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
and for X11:
Searching X11
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindX11.cmake:366 (find_package_handle_standard_args)
CMakeLists.txt:18 (FIND_PACKAGE)
Here is the cmakelist.txt provided :
#CMake for the gard Project
project(GARD)
cmake_minimum_required(VERSION 2.4.0)
#Set the path to the Cmake Modules
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/")
MESSAGE("Path to Cmake Modules is " ${CMAKE_MODULE_PATH})
MESSAGE("The source directory of the project is " ${GARD_SOURCE_DIR})
MESSAGE("")
MESSAGE("STEP 1 : SEARCHING FOR NEEDED MODULES")
MESSAGE("")
MESSAGE("Searching X11")
FIND_PACKAGE(X11 REQUIRED)
IF(X11_FOUND)
MESSAGE(" X11 include path: " ${X11_INCLUDE_DIR})
MESSAGE(" X11 library path: " ${X11_LIBRARIES})
ENDIF(X11_FOUND)
MESSAGE("Searching LAPACK AND BLAS")
find_package(LAPACK)
IF(LAPACK_FOUND)
MESSAGE(" LAPACK library path: " ${LAPACK_LIBRARIES})
MESSAGE(" BLAS library path: " ${BLAS_LIBRARIES})
ENDIF(LAPACK_FOUND)
MESSAGE("Searching CIMG")
find_package(CImg)
IF(CIMG_FOUND)
MESSAGE(" CIMG include path: " ${CIMG_INCLUDE_DIR})
ENDIF(CIMG_FOUND)
MESSAGE("Searching pthread")
FIND_LIBRARY(PTHREADS_LIBRARY pthread
PATHS /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu
)
IF(PTHREADS_LIBRARY)
MESSAGE(" Pthread library path: " ${PTHREADS_LIBRARY})
ENDIF(PTHREADS_LIBRARY)
MESSAGE("Searching Graphviz")
find_package(GraphViz)
IF(GRAPHVIZ_FOUND)
MESSAGE(" Graphviz library path: " ${GRAPHVIZ_LIBRARIES})
MESSAGE(" Graphviz include path: " ${GRAPHVIZ_INCLUDE_DIRS})
SET(GRAPHVIZ_SUPPORT "#define GRAPHVIZ_SUPPORT")
ENDIF(GRAPHVIZ_FOUND)
CONFIGURE_FILE(GraphVizConfig.h.cmake ${CMAKE_SOURCE_DIR}/include/core/GraphVizConfig.h)
find_package(OpenMP)
if(OPENMP_FOUND)
message("openMP found")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
MESSAGE("Searching FLANN")
find_package(Flann)
IF(FLANN_FOUND)
MESSAGE(" FLANN include path: " ${FLANN_INCLUDE_DIR})
include_directories(${FLANN_INCLUDE_DIR})
SET(FLANN_SUPPORT "#define FLANN_SUPPORT")
ELSE(FLANN_FOUND)
MESSAGE(" FLANN include path not found")
SET(FLANN_SUPPORT "")
ENDIF(FLANN_FOUND)
include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
set(AVAILABLE_CORES "#define AVAILABLE_CORES ${N}")
else(NOT N EQUAL 0)
set(AVAILABLE_CORES "#define AVAILABLE_CORES 1")
endif()
CONFIGURE_FILE(FlannConfig.h.cmake ${CMAKE_SOURCE_DIR}/include/core/FlannConfig.h)
MESSAGE("")
MESSAGE("")
MESSAGE("STEP 2 : SET INCLUDE AND LIBRARY PATHS")
MESSAGE("")
SET(GARD_INCLUDE_DIR ${GARD_SOURCE_DIR}/include)
IF(LAPACK_FOUND)
SET(LINK_LIBRARIES ${X11_LIBRARIES} ${PTHREADS_LIBRARY} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${GRAPHVIZ_LIBRARIES})
SET(CIMG_USE_LAPACK "#define cimg_use_lapack")
ELSE()
SET(LINK_LIBRARIES ${X11_LIBRARIES} ${PTHREADS_LIBRARY} ${GRAPHVIZ_LIBRARIES})
ENDIF()
CONFIGURE_FILE(CimgConfig.h.cmake ${CMAKE_SOURCE_DIR}/include/core/CimgConfig.h)
MESSAGE("")
MESSAGE("STEP 3 : Documentation generation")
MESSAGE("")
MESSAGE("Searching DOXYGEN")
INCLUDE(${CMAKE_MODULE_PATH}/FindDoxygen.cmake)
IF(DOXYGEN_FOUND)
MESSAGE("DOXYGEN Dir " ${DOXYGEN_DIR})
MESSAGE("GENERATING DOCUMENTATION")
SET(ENV{GARD_INCLUDE_DIR} "${GARD_SOURCE_DIR}/include")
EXEC_PROGRAM("cd docs;${DOXYGEN_DIR}/doxygen doc.txt"
OUTPUT_VARIABLE MY_OUTPUT
)
ENDIF(DOXYGEN_FOUND)
MESSAGE(STATUS "Link libraries: ${LINK_LIBRARIES}")
MESSAGE("")
MESSAGE("STEP 4 : COMPILATION")
MESSAGE("")
add_subdirectory (${GARD_SOURCE_DIR}/examples)
# add_subdirectory (${GARD_SOURCE_DIR}/operators)
Can you help please? I'm new to cmake and WSL. I'm running WSL on Windows 10 and I've installed the X11 library with " sudo apt-get install libx11-dev " . The command 'cmake .' is running in the bash terminal and looks like :
ananass#DESKTOP-R1E6G2S:/mnt/c/Users/ananass/gard$

Related

dependency and option in meson project

I have a project with a similar folder trees:
├── meson.build (1)
├── meson_options.txt
├── README.md
└── src
└── mysub
├── meson.build (2)
└── mesonTest.c
the meson.options.txt contains
option('avx_opt', type : 'combo', choices : ['avx2', 'avx512'], value : 'avx512')
the mysub project is a dependency of the main proj
so the meson.build (1) :
project(
'my_proj',
'c',
version : '1.1.0',
default_options : ['buildtype=plain','warning_level=3'],
subproject_dir : 'src'
)
project_source_files = [
''
]
message('## source root : ' + meson.project_source_root() + ' ##')
project_dependencies = [
dependency('mysub', fallback : ['mysub', 'mysub_dep']),
]
build_args = [
]
# ===================================================================
# ======
# Target
# ======
build_args += [
'-DPROJECT_NAME=' + meson.project_name(),
'-DPROJECT_VERSION=' + meson.project_version(),
]
the meson.build (2) of the mysub proj is:
project(
'mysub',
'c',
version : '1.1.0',
default_options : ['warning_level=3']
)
project_description = 'mysub binary'
project_source_files = [
'mesonTest.c'
]
project_headers = [
]
avx_type = get_option('avx_opt')
if (avx_type == 'avx512')
build_args_avx512 = [
'-mavx512f',
'-mavx512cd',
'-mavx512vl',
'-mavx512bw',
'-mavx512dq',
'-DNEWLDPC=1'
]
else
build_args_avx512 = [
'-DNEWLDPC=0'
]
endif
project_target = executable(
meson.project_name(),
project_source_files,
install : true,
c_args : build_args,
link_args : '-Wl,--allow-shlib-undefined',
)
# =======
# Project
# =======
# Make this library usable as a Meson subproject.
project_dep = declare_dependency(
include_directories: public_headers,
link_with : project_target
)
set_variable(meson.project_name() + '_dep', project_dep)
# Make this library usable from the system's
# package manager.
install_headers(project_headers, subdir : meson.project_name())
pkg_mod = import('pkgconfig')
pkg_mod.generate(
name : meson.project_name(),
filebase : meson.project_name(),
description : project_description,
subdirs : meson.project_name(),
# libraries : project_target,
)
I have tried to configure in the following way:
meson builddir -Davx_opt=avx512
or
meson builddir -Davx_opt:mysub=avx512
but in both case I got:
The Meson build system
Version: 0.59.1
Source dir: /home/roccasal/wsEclipse/Intel/mesonTest/proj
Build dir: /home/roccasal/wsEclipse/Intel/mesonTest/proj/builddir
Build type: native build
Project name: my_proj
Project version: 1.1.0
C compiler for the host machine: cc (gcc 8.5.0 "cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)")
C linker for the host machine: cc ld.bfd 2.30-108
Host machine cpu family: x86_64
Host machine cpu: x86_64
Message: ## source root : /home/roccasal/wsEclipse/Intel/mesonTest/proj ##
Found pkg-config: /usr/bin/pkg-config (1.4.2)
Found CMake: /usr/bin/cmake (3.20.2)
Run-time dependency mysub found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency mysub
Executing subproject mysub
mysub| Project name: mysub
mysub| Project version: 1.1.0
mysub| C compiler for the host machine: cc (gcc 8.5.0 "cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)")
mysub| C linker for the host machine: cc ld.bfd 2.30-108
src/mysub/meson.build:32:0: ERROR: Tried to access unknown option "avx_opt".
what is wrong in the meson build configuration?
the meson ver used is 0.59.1
//thanks
Check Build-options page in reference manual:
To change values in subprojects prepend the name of the subproject and
a colon:
$ meson configure -Dsubproject:option=newvalue
Thus, try create new build dir with:
meson builddir -Dmysub:avx_opt=avx512
or configure existing with:
meson configure builddir -Dmysub:avx_opt=avx512
To make it working you also need this option defined in meson_options.txt in every subproject that uses it, but to simplify configuration you can as #dcbaker suggested use yielding, i.e. update option definition for the main project:
option('avx_opt', ...., yield : true)
This will give you possibility to configure it the same way for main and subprojects with just:
meson configure builddir -Davx_opt=avx512
Also, (I guess it's just typo in question) file with options should have name meson_options.txt (with underscore).

Adding MinGW Path for posix version

This is my cmake mingw32 toolchain file:
set(CMAKE_SYSTEM_NAME Windows)
######################################################
# Compiler Flags
######################################################
set(COMMON_FLAGS "")
set(COMMON_FLAGS ${COMMON_FLAGS} -static)
set(COMMON_FLAGS ${COMMON_FLAGS} -static-libgcc)
set(COMMON_FLAGS ${COMMON_FLAGS} -static-libstdc++)
set(COMMON_FLAGS_DEBUG "")
set(COMMON_FLAGS_RELEASE "")
set(C_FLAGS "")
set(CXX_FLAGS "")
set(C_FLAGS_DEBUG ${COMMON_FLAGS} ${WARNING_FLAGS} ${COMMON_FLAGS_DEBUG} ${C_FLAGS})
set(C_FLAGS_RELEASE ${COMMON_FLAGS} ${WARNING_FLAGS} ${COMMON_FLAGS_RELEASE} ${C_FLAGS})
set(CXX_FLAGS_DEBUG ${COMMON_FLAGS} ${WARNING_FLAGS} ${COMMON_FLAGS_DEBUG} ${CXX_FLAGS})
set(CXX_FLAGS_RELEASE ${COMMON_FLAGS} ${WARNING_FLAGS} ${COMMON_FLAGS_RELEASE} ${CXX_FLAGS})
######################################################
# Linker flags
######################################################
string(REPLACE ";" " " LINKER_FLAGS_DEBUG "${COMMON_FLAGS_DEBUG}")
string(REPLACE ";" " " LINKER_FLAGS_RELEASE "${COMMON_FLAGS_RELEASE}")
string(REPLACE ";" " " LINKER_FLAGS "${COMMON_FLAGS}")
I can create with this toolchain file my makefiles.
And when I use the
i686-6.4.0-release-win32-dwarf-rt_v5-rev0
I don't need to add the compiler folder to the PATH to compile and link the project.
But when I use the
i686-6.4.0-release-posix-dwarf-rt_v5-rev0
I have to add the compiler to the PATH for compilation. If I don't add the posix version to the path I got an error message during compilation
The code execution cannot proceed because libwinpthread-1.dll was not
found. Reinstalling the program may fix this problem
Is it possible to use the posix version without adding to path? What do I have to add in my toolchain file?
Thanks for the help!

undefined reference to `vtable in custom lib created with cmake

I'm getting the error: lib/libhrlLib.so: undefined reference to `hrlQseqDev::waiting(bool, int)' and some more ...
I'm trying to build my project with cmake (3.7.2) instead of with qmake (Qt5)
CMakeLists.txt:
project(${TARGET_NAME})
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(POSITION_INDEPENDENT_CODE FALSE)
macro(NAMELIST erg in)
set(os "")
set(srcs ${in})
separate_arguments(srcs)
foreach(is ${srcs})
set(os ${os} ${is})
endforeach(is)
set(${erg} ${os})
endmacro(NAMELIST)
macro(FINDMODULES erg in)
set(os "")
set(srcs ${in})
separate_arguments(srcs)
foreach(is ${srcs})
find_package(Qt5${is} REQUIRED)
set(os ${os} Qt5::${is})
endforeach(is)
set(${erg} ${os})
endmacro(FINDMODULES)
NAMELIST(SRCS ${TARGET_SRCS})
FINDMODULES(QLIBS ${QMODULES})
if(INC_PATH)
NAMELIST(INCS ${INC_PATH})
set(INCLUDES ${INCS})
endif(INC_PATH)
if(TARGET_EXTLIBS)
NAMELIST(EXTRA_LIBS ${EXTRA_LIBS} "${TARGET_EXTLIBS}")
endif(TARGET_EXTLIBS)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
include_directories(${INCLUDES})
if(BUILD_LIB)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-shared")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-shared")
add_library(${TARGET_NAME} SHARED ${SRCS})
target_link_libraries(${TARGET_NAME} ${QLIBS} ${EXTRA_LIBS})
set_property(TARGET ${TARGET_NAME} PROPERTY VERSION "1.0.0")
set_property(TARGET ${TARGET_NAME} PROPERTY SOVERSION 1 )
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib)
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib NAMELINK_ONLY)
else()
if(USE_LIB_PATH)
add_executable(${TARGET_NAME} ${SRCS})
target_link_libraries(${TARGET_NAME} -L${OUT_PATH}/lib lib${USE_LIB}.so.1
${QLIBS} ${EXTRA_LIBS})
else()
add_executable(${TARGET_NAME} ${SRCS})
target_link_libraries(${TARGET_NAME} ${QLIBS} ${EXTRA_LIBS})
endif(USE_LIB_PATH)
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin)
endif(BUILD_LIB)
The shared library is built with:
cmake -G "Unix Makefiles" -DINC_PATH:STRING="some includes" -DTARGET_EXTLIBS:STRING="sys libs" -DTARGET_NAME:STRING=LibName -DBUILD_LIB:BOOL=1 -DTARGET_SRCS:STRING="cpp- and c-file" -DQMODULES:STRING="Core Gui Widgets PrintSupport" -DOUT_PATH:STRING=InstallPath .. -DCMAKE_INSTALL_PREFIX=InstallPath >> /dev/null
When I try to build a program against this shared library with:
cmake -G "Unix Makefiles" -DINC_PATH:STRING="some includes" -DTARGET_EXTLIBS:STRING="sys libs" -DTARGET_NAME:STRING=ProgName -DBUILD_LIB:BOOL=0 -DTARGET_SRCS:STRING="cpp-file" -DQMODULES:STRING="Core Gui Widgets PrintSupport" -DOUT_PATH=InstallPath -DUSE_LIB:STRING="LibName" -DUSE_LIB_PATH:STRING="BuildPath of LibName" .. -DCMAKE_INSTALL_PREFIX=InstallPath >> /dev/null
I get the error 'lib/libhrlLib.so: undefined reference to ...'.
I do not get this error when the library was built with qmake.
How can I fix this?

How to build a "file copy" RPM using cmake?

I want to build a demo rpm package which copies one file to the target system and executes some pre and post script.
I managed to create a package. When I run the package on the target system I got the e warning "warning: package xxx intend for yyy plattform". But no file was copied.
Any ideas?
After goes my code/project:
Project tree:
myRpm/CMakeLists.txt
myRpm/install.txt
myRpm/post.py
myRpm/post.sh
myRpm/pre.py
myRpm/pre.sh
CMakeLists:
cmake_minimum_required (VERSION 2.8)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "my test")
set(CPACK_PACKAGE_VENDOR "tets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake rpm")
set(CPACK_PACKAGE_VERSION "6.6.6")
set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "6")
set(targetDestDir "myDir")
set(CPACK_GENERATOR "RPM")
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/install.txt" "${CMAKE_CURRENT_SOURCE_DIR}/pre.py" "${CMAKE_CURRENT_SOURCE_DIR}/post.py"
DESTINATION "${targetDestDir}"
)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/pre.sh")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/post.sh")
include(CPack)
endif()
The value of CPACK_RPM_PACKAGE_ARCHITECTURE is important when building RPMs for other systems/distros.
The following code should work:
cmake_minimum_required (VERSION 2.8)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for tmp")
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "mytest")
set(CPACK_PACKAGE_VENDOR "tets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake rpm")
set(CPACK_PACKAGE_VERSION "6.6.6")
set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "6")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch")
set(targetDestDir ${CMAKE_INSTALL_TMPDIR})
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/install.txt" "${CMAKE_CURRENT_SOURCE_DIR}/post.py"
DESTINATION "${targetDestDir}"
)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/pre.sh")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/post.sh")
include(CPack)
endif()
Note:
the pre.sh and post.sh are in the root dir of the sources. In the post.sh the post.py is called.

Compile an OpenMP program with CMake on OS X

I have a very simple openmp hello world program as this:
#include <stdio.h>
#include <omp.h>
int main()
{
#pragma omp parallel
{
int id = omp_get_thread_num();
printf("hello, from %d.\n", id);
}
return 0;
}
I can compile it in my terminal with gcc-5 -fopenmp hello.c -o hello.o
But I want to code in CLion, it uses CMake to organize project, when I just click the run button, I will got an error
fatal error: 'omp.h' file not found
#include <omp.h>
I did search in google, and add something into my CMakeLists.txt file
This is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.3)
project(openmp)
OPTION (USE_OpenMP "Use OpenMP" ON)
IF(USE_OpenMP)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF()
ENDIF()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp")
set(SOURCE_FILES hello.c omp.c)
add_executable(openmp ${SOURCE_FILES})
Your code is C, not C++, so instead of changing CMAKE_CXX_FLAGS, change CMAKE_C_FLAGS:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
And set your C compiler to gcc-5:
set(CMAKE_C_COMPILER /your/path/to/gcc-5)
To know gcc-5 path, in a terminal, type which gcc-5
See also: How to specify new gcc path for cmake