Not able to compile C source files using make. CMake error Cannot find source files but they are there - c

Im trying to compile the posest C++ library
posest : A C/C++ Library for Robust 6DoF Pose Estimation from 3D-2D Correspondences
with make. But when run the make I got the following error
make
-- LEVMAR_INCLUDE_DIR = /usr/local/levmar-2.6
-- LEVMAR_BINARY_DIR = /usr/local/levmar-2.6/w32
-- LAPACKBLAS_DIR = /usr/lib
-- demos will be linked against posest;levmar;lapack;blas;f2c
-- Configuring done
CMake Error at CMakeLists.txt:24 (ADD_LIBRARY):
Cannot find source file:
mlsl/mlsl.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Warning (dev) at CMakeLists.txt:65 (ADD_DEPENDENCIES):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "levmar" of target "binocposest_demo" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at CMakeLists.txt:64 (ADD_DEPENDENCIES):
Policy CMP0046 is not set: Error on non-existent dependency in
add_dependencies. Run "cmake --help-policy CMP0046" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.
The dependency target "levmar" of target "posest_demo" does not exist.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error: Cannot determine link language for target "posest".
CMake Error: CMake can not determine linker language for target: posest
-- Generating done
-- Build files have been written to: /home/admini/posest-1.2
Makefile:714: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
But the source file mlsl.c is already there
Here is the contents of the CMakeList.txt file
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(POSEST)
# levmar library
SET(LEVMAR_INCLUDE_DIR "/usr/local/levmar-2.6" CACHE PATH "Path to LEVMAR library header")
#ADD_SUBDIRECTORY(${LEVMAR_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LEVMAR_INCLUDE_DIR})
MESSAGE(STATUS "LEVMAR_INCLUDE_DIR = ${LEVMAR_INCLUDE_DIR}")
IF(MSVC)
ADD_DEFINITIONS(/arch:SSE2)
# get rid of CRT warnings
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(MSVC)
INCLUDE_DIRECTORIES(mlsl)
ADD_LIBRARY(posest buckets.c lqs.c ransac.c rngs.c prosac.c deal.c p3p.c p4pf.c planep4p.c svd3.c polysolve.c
poseproj.c posest.c align.c lhm.c sam.c compiler.h lqs.h ransac.h prosac.h p3p.h p4pf.h planep4p.h svd3.h
polysolve.h poseproj.h posest.h util.h rngs.h sam.h
mlsl/mlsl.c mlsl/mt19937ar.c mlsl/redblack.c mlsl/sobolseq.c
)
OPTION(BUILD_DEMOS "Build demo programs?" TRUE)
# demo program
IF(BUILD_DEMOS)
# paths to levmar & lapack/blas libraries
SET(LEVMAR_BINARY_DIR "${LEVMAR_INCLUDE_DIR}/w32" CACHE PATH "Path to levmar library")
MESSAGE(STATUS "LEVMAR_BINARY_DIR = ${LEVMAR_BINARY_DIR}")
SET(LAPACKBLAS_DIR "/usr/lib" CACHE PATH "Path to lapack/blas libraries")
MESSAGE(STATUS "LAPACKBLAS_DIR = ${LAPACKBLAS_DIR}")
# actual names for the lapack/blas/f2c libraries
SET(LAPACKBLAS_LIB_NAMES "lapack;blas" CACHE STRING "The name of the lapack & blas libraries")
SET(F2C_LIB_NAME f2c CACHE STRING "The name of the f2c or F77/I77 library")
# f2c is sometimes equivalent to libF77 & libI77
#SET(F2C_LIB_NAME "libF77;libI77" CACHE STRING "The name of the f2c or F77/I77 library")
SET(LIBS posest levmar)
SET(LIBS ${LIBS} ${LAPACKBLAS_LIB_NAMES} ${F2C_LIB_NAME})
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) # location of the posest library
LINK_DIRECTORIES(${LEVMAR_BINARY_DIR}) # location of the levmar library
LINK_DIRECTORIES(${LAPACKBLAS_DIR})
ADD_EXECUTABLE(posest_demo posest_demo.c)
TARGET_LINK_LIBRARIES(posest_demo ${LIBS})
ADD_EXECUTABLE(binocposest_demo binocposest_demo.c)
TARGET_LINK_LIBRARIES(binocposest_demo ${LIBS})
MESSAGE(STATUS "demos will be linked against ${LIBS}")
# make sure that the libraries are built before the demos
ADD_DEPENDENCIES(posest_demo posest levmar)
ADD_DEPENDENCIES(binocposest_demo posest levmar)
ENDIF(BUILD_DEMOS)
Here the Project Directory screenshot.
And the content of the mlsl directory
/home/posest-1.2/mlsl/mlsl.c
/home/posest-1.2/mlsl/mlsl.h
/home/posest-1.2/mlsl/mt19937ar.c
/home/posest-1.2/mlsl/mt19937ar.h
/home/posest-1.2/mlsl/redblack.c
/home/posest-1.2/mlsl/redblack.h
/home/posest-1.2/mlsl/sobol.h
/home/posest-1.2/mlsl/soboldata.h
/home/posest-1.2/mlsl/sobolseq.c
Im not sure what is the problem. Any help?

I had to download the tar file from the website. It is malformed and won't work.
~/swdev/posest-1.2$ ls -ld mlsl/
drw-r--r-- 2 XXX XXXX 4096 Oct 6 2014 mlsl/
~/swdev/posest-1.2$ chmod u+x mlsl/
~/swdev/posest-1.2$ cmake .
The sources and directories are required to be readable. In this case mlsl has incorrect permissions and CMake cannot read the file. Use the chmod command to fix the permissions on the directory.

Related

Make a file available during runtime in CMake and Qt Creator

I am trying to make a resource file available to the executable during the runtime. I am using the following CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
project(open-gl-test)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
add_executable(${PROJECT_NAME} "main.c")
message(Executable is set!)
target_link_libraries(${PROJECT_NAME} ${GLEW_LIBRARIES} ${OPENGL_gl_LIBRARY} glfw)
# List of files for which we add a copy rule.
set(data_SHADOW "basic.shader")
# We don't want to copy if we're building in the sourse dir.
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(WARNING "Directories are not equal")
foreach(item IN LISTS data_SHADOW)
message(STATUS ${item})
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/res/shaders/${item}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${item}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${item}"
)
endforeach()
else()
message(WARNING "Directories are equal")
endif()
# Files are only copied if a target depends on them.
add_custom_target(data-target ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/res/shaders/${data_SHADOW}")
And this is how I access the file.
struct ShaderProgramSource source = parseShader("res/shaders/basic.shader");
But nothing gets copied to the project build directory and the even the messages don't show up in the *compile output window. And the error message I am getting is:
Error while opening the file: No such file or directory
What might be the issue?

CMake project build with multi CMakeLists.txt [duplicate]

I'm currently using recursive make and autotools and am looking to migrate to CMake for a project that looks something like this:
lx/ (project root)
src/
lx.c (contains main method)
conf.c
util/
str.c
str.h
etc.c
etc.h
server/
server.c
server.h
request.c
request.h
js/
js.c
js.h
interp.c
interp.h
bin/
lx (executable)
How should I go about this?
If there's never any source higher than the lx/src directory, then there's no need for the lx/CMakeLists.txt file. If there is, it should look something like this:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx)
add_subdirectory(src)
add_subdirectory(dir1)
add_subdirectory(dir2)
# And possibly other commands dealing with things
# directly in the "lx" directory
...where the subdirectories are added in library dependency order. Libraries that depend on nothing else should be added first, and then libraries that depend on those, and so on.
lx/src/CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx_exe)
add_subdirectory(util)
add_subdirectory(js)
add_subdirectory(server)
set(lx_source_files conf.c lx.c)
add_executable(lx ${lx_source_files})
target_link_libraries(lx server)
# also transitively gets the "js" and "util" dependencies
lx/src/util/CMakeLists.txt
set(util_source_files
etc.c
etc.h
str.c
str.h
)
add_library(util ${util_source_files})
lx/src/js/CMakeLists.txt
set(js_source_files
interp.c
interp.h
js.c
js.h
)
add_library(js ${js_source_files})
target_link_libraries(js util)
lx/src/server/CMakeLists.txt
set(server_source_files
request.c
request.h
server.c
server.h
)
add_library(server ${server_source_files})
target_link_libraries(server js)
# also transitively gets the "util" dependency
Then, in a command prompt:
mkdir lx/bin
cd lx/bin
cmake ..
# or "cmake ../src" if the top level
# CMakeLists.txt is in lx/src
make
By default, the lx executable will end up in the "lx/bin/src" directory using this exact layout. You can control what directory it ends up in by using the RUNTIME_OUTPUT_DIRECTORY target property and the set_property command.
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_property
Refer to target_link_libraries libs either by CMake target name, if the lib is built as a CMake target via add_library, or by full path to the library file otherwise.
See also, the output of "cmake --help-command target_link_libraries", or any other cmake command, and the full online documentation for cmake commands found here:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_Commands
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries
Steinberg VST3 library has a reusable method which recursively loops through subdirectories and adds them if they include a CMakeLists.txt file:
# add every sub directory of the current source dir if it contains a CMakeLists.txt
function(smtg_add_subdirectories)
file(GLOB subDirectories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(dir ${subDirectories})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${dir}")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
add_subdirectory(${dir})
endif()
endif()
endforeach(dir)
endfunction()
https://github.com/steinbergmedia/vst3_cmake/blob/master/modules/SMTG_AddSubDirectories.cmake

Cmake 'check_include_files' function failed when files exist

Assume we have a CMakeLists.txt who has code like ( following is little part of whole file ):
cmake_minimum_required(VERSION 2.6.3)
#...
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/include/mit-krb5/")
message("CMAKE_REQUIRED_INCLUDES=${CMAKE_REQUIRED_INCLUDES};CMAKE_REQUIRED_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS};CMAKE_REQUIRED_FLAGS=${CMAKE_REQUIRED_FLAGS}")
message("before find path, fuckGssApiIncludes=${fuckGssApiIncludes}")
find_path(fuckGssApiIncludes "gssapi.h" "/usr/include")
if(NOT fuckGssApiIncludes)
message(FATAL_ERROR "Can't find folder containing gssapi.h")
endif()
message("after, fuckGssApiIncludes=${fuckGssApiIncludes}")
include_directories(${fuckGssApiIncludes})
check_include_files("gssapi.h" HAVE_GSSAPI_H)
#....
if (NOT HAVE_GSSAPI_H)
message(FATAL_ERROR "Cannot find GSS libraries")
And we have some files:
# ls /usr/include/gssapi.h
/usr/include/gssapi.h
But when I run this command with cmake version 3.12.1, I got error like this:
CMAKE_REQUIRED_INCLUDES=/usr/include/;/usr/include/x86_64-linux-gnu/;CMAKE_REQUIRED_DEFINITIONS=;CMAKE_REQUIRED_FLAGS=
before find path, fuckGssApiIncludes=
after, fuckGssApiIncludes=/usr/include
CMake Error at CMakeLists.txt:548 (message):
Cannot find GSS libraries
I thought in someway, Cmake.check_include_files did not works as Cmake's definition.
So, Q1: Is my thought correct, and why? Q2: How to work around, and make this cmakelists.txt run well?
Answer find, just remove all cmake temporary files.

(automake, libtool) build fails in automake when using same source file name in different directory

OS: Ubuntu 14.14
automake version: automake (GNU automake) 1.14.1
I build source codes to make a shared library by using automake.
But I got a error that automake may can't handle source codes which are same name and different directory.
Can't I compile the same file name source codes in different directory by using automake?
For instance, lib_sample/lib.c, lib_sample/enhance/lib.c those two files are the same name but different source and different directories.
Also, After typing the configure, I check the src directory, weird directory($(LIB_DIR)) is created.
./configure --with-lib=/home/user/workspace/lib_sample --enable-enhance
ls src/
$(LIB_DIR) Makefile Makefile.am Makefile.in mod_sample.c
--> $(LIB_DIR) is created. unintended directory is created.
I got an error message when I type the make command.
the error message looks like this.
Makefile:423: /src/.deps/lib.Plo: No such file or directory
Makefile:424: /src/enhanced/.deps/lib.Plo: No such file or directory
make[1]: *** No rule to make target `/src/enhanced/.deps/lib.Plo'. Stop.
make[1]: Leaving directory `/home/user/test/mod_sample/src'
make: *** [all-recursive] Error 1
First problem is, after configure script, the $(LIB_DIR) directory is created.
Second problem is a failure in build source codes when I type the make command.
I think the libtool fail to compile when it tries to make .Plo files, but what I can't understand is that why automake tries to compile lib_sample/src/lib.c.
Because I denote the LIB_DIR path with --with-lib and --enable-enhance option, before compiling the sources in ./configure script. Therefore, automake should do not manage src/lib.c.
However, automake tries to compile lib_sample/src/lib.c and the strange message comes out.
You can see codes how I write below, and project structures in detail.
Thanks in advance.
Here in details.
There are two directories.
/home/user/test/mod_sample, (build fail)
/home/user/test/lib_sample (another source codes in here)
configure.ac (/home/user/test/mod_sample/configure.ac)
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(sample, 1.5.0)
AC_PROG_CC
AC_PROG_CXX
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE([subdir-objects])
AM_PROG_CC_C_O
LT_INIT
AC_PROG_LIBTOOL
AC_MSG_CHECKING(--with-lib)
AC_ARG_WITH([lib],
AC_HELP_STRING([--with-lib=DIR], [Set lib path ]),
[LIB_DIR=$withval]
[have_lib=yes],
[have_lib=no])
AC_MSG_RESULT($LIB_DIR)
AC_SUBST(LIB_DIR)
AC_ARG_ENABLE([[enhance]],
[AS_HELP_STRING([[--disable-enhance]], [enhance])], ,
[enable_enhance=yes])
test "x$enable_enhance" = "xno" || enable_enhance=yes
AM_CONDITIONAL([HAVE_ENHANCE], [test "x$enable_enhance" = "xyes"])
AC_CONFIG_FILES(Makefile
include/Makefile
src/Makefile)
AC_OUTPUT
top directory Makefile.am(/home/user/test/mod_sample/Makefile.am)
SUBDIRS=src include
src/Makefile.am (/home/user/test/mod_sample/src/Makefile.am)
lib_LTLIBRARIES = libmod_sample.la
libmod_sample_la_SOURCES = mod_sample.c
if HAVE_ENHANCE
libmod_sample_la_SOURCES+=$(LIB_DIR)/src/enhanced/lib.c
else
libmod_sample_la_SOURCES+=$(LIB_DIR)/src/lib.c
endif
run configure command before make
autoreconf -if
./configure --with-lib=/home/user/workspace/lib_sample --enable-enhance
the error message when I type the 'make'.
Makefile:423: /src/.deps/lib.Plo: No such file or directory
Makefile:424: /src/enhanced/.deps/lib.Plo: No such file or directory
make[1]: *** No rule to make target `/src/enhanced/.deps/lib.Plo'. Stop.
make[1]: Leaving directory `/home/user/test/mod_sample/src'
make: *** [all-recursive] Error 1
lib_sample directory structure (same file name in different directory)
/home/user/workspace/lib_sample/lib.c
/home/user/workspace/lib_sample/enhance/lib.c
lib_sample/lib.c
void lib()
{
printf("hello\n");
}
lib_sample/enhance/lib.c
void lib()
{
printf("enhance hello\n");
}
I answered this myself.
According to the reference(http://www.gnu.org/software/automake/manual/html_node/Conditional-Sources.html), a user specified variable, $(LIB_DIR) in this case, can't be used in a _SOURCES variable. However, it works fine in my case except when the variable is used with same file name and if statement. The problem is that the variable which user specified is used in a _SOURCES variable and if statement with same file name.
So, I thought there are two possible solutions. One is that I may change a file name one of them to avoid using same file name. Another is that using a variable represents 'enhance' string, which is the directory name, to remove if statement in Makefile.am.
Solution 1
mv lib_sample/enhance/lib.c lib_sample/enhance/lib_enhance.c
make
lib_LTLIBRARIES = libmod_sample.la
libmod_sample_la_SOURCES = mod_sample.c
if HAVE_ENHANCE
libmod_sample_la_SOURCES+=$(LIB_DIR)/src/enhanced/lib_enhance.c # change the file name
else
libmod_sample_la_SOURCES+=$(LIB_DIR)/src/lib.c
endif
But, I can't change the file name, the reason for this is a bit hard to explain, in short to speak, because of source code permission.
Solution 2
I solved the problem in this way.
part of configure.ac (/home/user/test/mod_sample/configure.ac)
AC_ARG_ENABLE([[enhance]],
[AS_HELP_STRING([[--disable-enhance]], [enhance])], ,
[enable_enhance=yes])
test "x$enable_enhance" = "xno" || enable_enhance=yes
AM_CONDITIONAL([HAVE_ENHANCE], [test "x$enable_enhance" = "xyes"])
AM_COND_IF([HAVE_ENHANCE], [AC_SUBST(ENHANCE, "enhance")], [AC_SUBST(ENHANCE, "")]) # Add this line
src/Makefile.am (/home/user/test/mod_sample/src/Makefile.am)
lib_LTLIBRARIES = libmod_sample.la
libmod_sample_la_SOURCES = mod_sample.c
# Use $(ENHANCE) variable to remove if statement
# $(ENHANCE) can be "enhance" or empty string.
libmod_sample_la_SOURCES+=$(LIB_DIR)/src/$(ENHANCE)/lib.c

How to migrate this Make and Autotools project with multiple source subdirectories to CMake?

I'm currently using recursive make and autotools and am looking to migrate to CMake for a project that looks something like this:
lx/ (project root)
src/
lx.c (contains main method)
conf.c
util/
str.c
str.h
etc.c
etc.h
server/
server.c
server.h
request.c
request.h
js/
js.c
js.h
interp.c
interp.h
bin/
lx (executable)
How should I go about this?
If there's never any source higher than the lx/src directory, then there's no need for the lx/CMakeLists.txt file. If there is, it should look something like this:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx)
add_subdirectory(src)
add_subdirectory(dir1)
add_subdirectory(dir2)
# And possibly other commands dealing with things
# directly in the "lx" directory
...where the subdirectories are added in library dependency order. Libraries that depend on nothing else should be added first, and then libraries that depend on those, and so on.
lx/src/CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lx_exe)
add_subdirectory(util)
add_subdirectory(js)
add_subdirectory(server)
set(lx_source_files conf.c lx.c)
add_executable(lx ${lx_source_files})
target_link_libraries(lx server)
# also transitively gets the "js" and "util" dependencies
lx/src/util/CMakeLists.txt
set(util_source_files
etc.c
etc.h
str.c
str.h
)
add_library(util ${util_source_files})
lx/src/js/CMakeLists.txt
set(js_source_files
interp.c
interp.h
js.c
js.h
)
add_library(js ${js_source_files})
target_link_libraries(js util)
lx/src/server/CMakeLists.txt
set(server_source_files
request.c
request.h
server.c
server.h
)
add_library(server ${server_source_files})
target_link_libraries(server js)
# also transitively gets the "util" dependency
Then, in a command prompt:
mkdir lx/bin
cd lx/bin
cmake ..
# or "cmake ../src" if the top level
# CMakeLists.txt is in lx/src
make
By default, the lx executable will end up in the "lx/bin/src" directory using this exact layout. You can control what directory it ends up in by using the RUNTIME_OUTPUT_DIRECTORY target property and the set_property command.
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_property
Refer to target_link_libraries libs either by CMake target name, if the lib is built as a CMake target via add_library, or by full path to the library file otherwise.
See also, the output of "cmake --help-command target_link_libraries", or any other cmake command, and the full online documentation for cmake commands found here:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_Commands
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:target_link_libraries
Steinberg VST3 library has a reusable method which recursively loops through subdirectories and adds them if they include a CMakeLists.txt file:
# add every sub directory of the current source dir if it contains a CMakeLists.txt
function(smtg_add_subdirectories)
file(GLOB subDirectories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(dir ${subDirectories})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${dir}")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
add_subdirectory(${dir})
endif()
endif()
endforeach(dir)
endfunction()
https://github.com/steinbergmedia/vst3_cmake/blob/master/modules/SMTG_AddSubDirectories.cmake

Resources