Linking error of BLAS with CMake - c++

I have the following CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (MTSOS)
# Select flags.
set(CMAKE_C_FLAGS "-std=c99")
# Blas library
find_package( BLAS REQUIRED )
include_directories(${BLAS_INCLUDE_DIR})
add_executable (test_MTSOS test_MTSOS.c barrier_front.c dynamics_front.c
MTSOS.c csparse.c)
# Linking CImg dependencies.
target_link_libraries (test_MTSOS m blas ${BLAS_LIBRARIES})
When I run cmake .. :
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- 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
-- 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
-- Looking for dgemm_
-- Looking for dgemm_ - found
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- A library with BLAS API found.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jabuntu14/Desktop/MTSOS/build
However, when I try to compile with make:
Scanning dependencies of target test_MTSOS
[ 20%] Building C object CMakeFiles/test_MTSOS.dir/test_MTSOS.c.o
[ 40%] Building C object CMakeFiles/test_MTSOS.dir/barrier_front.c.o
/home/jabuntu14/Desktop/MTSOS/barrier_front.c: In function ‘so_barrier’:
/home/jabuntu14/Desktop/MTSOS/barrier_front.c:83:25: warning: implicit declaration of function ‘dsyr’ [-Wimplicit-function-declaration]
dsyr(uplo, &u_size, &alpha, &Df[i*U_size], &one, A, &u_size);
^
[ 60%] Building C object CMakeFiles/test_MTSOS.dir/dynamics_front.c.o
[ 80%] Building C object CMakeFiles/test_MTSOS.dir/MTSOS.c.o
/home/jabuntu14/Desktop/MTSOS/MTSOS.c: In function ‘so_MakeA’:
/home/jabuntu14/Desktop/MTSOS/MTSOS.c:1561:13: warning: implicit declaration of function ‘dgemv’ [-Wimplicit-function-declaration]
dgemv(chn, &m_m, &n_m, &one, &M_dynamics[i*State_size*State_size], &m_m, &S_prime[i*State_size], &p_m, &zero, datam, &p_m);
^
[100%] Building C object CMakeFiles/test_MTSOS.dir/csparse.c.o
Linking C executable test_MTSOS
CMakeFiles/test_MTSOS.dir/barrier_front.c.o: In function `so_barrier':
barrier_front.c:(.text+0x4a7): undefined reference to `dsyr'
CMakeFiles/test_MTSOS.dir/MTSOS.c.o: In function `so_MakeA':
MTSOS.c:(.text+0x5e41): undefined reference to `dgemv'
MTSOS.c:(.text+0x5ee4): undefined reference to `dgemv'
MTSOS.c:(.text+0x5f87): undefined reference to `dgemv'
collect2: error: ld returned 1 exit status
make[2]: *** [test_MTSOS] Error 1
make[1]: *** [CMakeFiles/test_MTSOS.dir/all] Error 2
make: *** [all] Error 2
So I am having a linking problem but I cannot figure out why. Any help is welcome. Thanks!!
NOTE: Working under Ubuntu 14.04 with GCC. In the .c files I have included #include "cblas.h" as I saw in other websites.
EDIT: running make VERBOSE=1 the output is:
jabuntu14#ubuntu:~/Desktop/MTSOS/build$ make VERBOSE=1
/usr/bin/cmake -H/home/jabuntu14/Desktop/MTSOS -B/home/jabuntu14/Desktop/MTSOS/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/jabuntu14/Desktop/MTSOS/build/CMakeFiles /home/jabuntu14/Desktop/MTSOS/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/jabuntu14/Desktop/MTSOS/build'
make -f CMakeFiles/test_MTSOS.dir/build.make CMakeFiles/test_MTSOS.dir/depend
make[2]: Entering directory `/home/jabuntu14/Desktop/MTSOS/build'
cd /home/jabuntu14/Desktop/MTSOS/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jabuntu14/Desktop/MTSOS /home/jabuntu14/Desktop/MTSOS /home/jabuntu14/Desktop/MTSOS/build /home/jabuntu14/Desktop/MTSOS/build /home/jabuntu14/Desktop/MTSOS/build/CMakeFiles/test_MTSOS.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/jabuntu14/Desktop/MTSOS/build'
make -f CMakeFiles/test_MTSOS.dir/build.make CMakeFiles/test_MTSOS.dir/build
make[2]: Entering directory `/home/jabuntu14/Desktop/MTSOS/build'
Linking C executable test_MTSOS
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_MTSOS.dir/link.txt --verbose=1
/usr/bin/cc -std=c99 CMakeFiles/test_MTSOS.dir/test_MTSOS.c.o CMakeFiles/test_MTSOS.dir/barrier_front.c.o CMakeFiles/test_MTSOS.dir/dynamics_front.c.o CMakeFiles/test_MTSOS.dir/MTSOS.c.o CMakeFiles/test_MTSOS.dir/csparse.c.o -o test_MTSOS -rdynamic -lm -lblas -lf77blas -latlas
CMakeFiles/test_MTSOS.dir/barrier_front.c.o: In function `so_barrier':
barrier_front.c:(.text+0x4a7): undefined reference to `dsyr'
CMakeFiles/test_MTSOS.dir/MTSOS.c.o: In function `so_MakeA':
MTSOS.c:(.text+0x5e41): undefined reference to `dgemv'
MTSOS.c:(.text+0x5ee4): undefined reference to `dgemv'
MTSOS.c:(.text+0x5f87): undefined reference to `dgemv'
collect2: error: ld returned 1 exit status
make[2]: *** [test_MTSOS] Error 1
make[2]: Leaving directory `/home/jabuntu14/Desktop/MTSOS/build'
make[1]: *** [CMakeFiles/test_MTSOS.dir/all] Error 2
make[1]: Leaving directory `/home/jabuntu14/Desktop/MTSOS/build'
make: *** [all] Error 2

The functions in standard blas libraries are
dgemv_
Instead of
dgemv
As shown in your error, notice the trailing underscore.
So you probably have something in your code calling dgemv() instead of dgemv_(), change that and then you should be fine.
(I had the same issue where the code I was using had some like #define dgemv_ dgemv)

Related

Unable to make ROS2 package (but used to be able to)

I am having trouble making a ros2 package for the Robotis Open manipulator. I was able to run this and am able to run this on a virtual machine, but my main machine is now not able to build these packages anymore. I have reinstall foxy a number of times and the results are still the same.
These are the commands I am using:
colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=ON --packages-select dynamixel_sdk_custom_interfaces
Although a simple colcon build also gives me the same errors I wanted to see if making it verbose would help me identify the issue.
Here are the results I got:
Starting >>> dynamixel_sdk_custom_interfaces
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ament_cmake: 0.9.9 (/opt/ros/foxy/share/ament_cmake/cmake)
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3")
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Found builtin_interfaces: 1.0.0 (/opt/ros/foxy/share/builtin_interfaces/cmake)
-- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
-- Found rosidl_adapter: 1.2.1 (/opt/ros/foxy/share/rosidl_adapter/cmake)
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")
-- Found FastRTPS: /opt/ros/foxy/include
-- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
-- Found rosidl_default_generators: 1.0.1 (/opt/ros/foxy/share/rosidl_default_generators/cmake)
-- Found PythonInterp: /usr/bin/python3 (found version "3.8.10")
-- Found ament_cmake_ros: 0.9.2 (/opt/ros/foxy/share/ament_cmake_ros/cmake)
-- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
-- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3.5")
-- Found python_cmake_module: 0.8.1 (/opt/ros/foxy/share/python_cmake_module/cmake)
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found suitable version "3.8.10", minimum required is "3.5")
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using PYTHON_INCLUDE_DIRS: /usr/include/python3.8
-- Using PYTHON_LIBRARIES: /usr/lib/x86_64-linux-gnu/libpython3.8.so
-- Found PythonExtra: .so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces
/usr/bin/cmake -S/home/mainuser/colcon_ws/src/DynamixelSDK/dynamixel_sdk_custom_interfaces -B/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/CMakeFiles /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces//CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
/usr/bin/make -f CMakeFiles/dynamixel_sdk_custom_interfaces__cpp.dir/build.make CMakeFiles/dynamixel_sdk_custom_interfaces__cpp.dir/depend
/usr/bin/make -f CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/build.make CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/depend
make[1]: *** No rule to make target 'dynamixel_sdk_custom_interfaces__py/CMakeFiles/dynamixel_sdk_custom_interfaces__py.dir/all', needed by 'CMakeFiles/dynamixel_sdk_custom_interfaces__python.dir/all'. Stop.
make[1]: *** Waiting for unfinished jobs....
make[2]: Entering directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
cd /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mainuser/colcon_ws/src/DynamixelSDK/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/src/DynamixelSDK/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/CMakeFiles/dynamixel_sdk_custom_interfaces__cpp.dir/DependInfo.cmake --color=
make[2]: Entering directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
[ 2%] Generating C code for ROS interfaces
/usr/bin/python3 /opt/ros/foxy/share/rosidl_generator_c/cmake/../../../lib/rosidl_generator_c/rosidl_generator_c --generator-arguments-file /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/rosidl_generator_c__arguments.json
make[2]: Leaving directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
/usr/bin/make -f CMakeFiles/dynamixel_sdk_custom_interfaces__cpp.dir/build.make CMakeFiles/dynamixel_sdk_custom_interfaces__cpp.dir/build
make[2]: Entering directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
[ 5%] Generating C++ code for ROS interfaces
/usr/bin/python3 /opt/ros/foxy/share/rosidl_generator_cpp/cmake/../../../lib/rosidl_generator_cpp/rosidl_generator_cpp --generator-arguments-file /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/rosidl_generator_cpp__arguments.json
make[2]: Leaving directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
[ 5%] Built target dynamixel_sdk_custom_interfaces__cpp
cd /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mainuser/colcon_ws/src/DynamixelSDK/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/src/DynamixelSDK/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
/usr/bin/make -f CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/build.make CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/build
make[2]: Entering directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
[ 10%] Building C object CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/srv/detail/get_position__functions.c.o
[ 10%] Building C object CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/msg/detail/set_position__functions.c.o
/usr/bin/cc -DRCUTILS_ENABLE_FAULT_INJECTION -DROS_PACKAGE_NAME=\"dynamixel_sdk_custom_interfaces\" -Ddynamixel_sdk_custom_interfaces__rosidl_generator_c_EXPORTS -I/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/rosidl_generator_c -isystem /opt/ros/foxy/include -fPIC -Wall -std=gnu11 -MD -MT CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/msg/detail/set_position__functions.c.o -MF CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/msg/detail/set_position__functions.c.o.d -o CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/msg/detail/set_position__functions.c.o -c /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/rosidl_generator_c/dynamixel_sdk_custom_interfaces/msg/detail/set_position__functions.c
/usr/bin/cc -DRCUTILS_ENABLE_FAULT_INJECTION -DROS_PACKAGE_NAME=\"dynamixel_sdk_custom_interfaces\" -Ddynamixel_sdk_custom_interfaces__rosidl_generator_c_EXPORTS -I/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/rosidl_generator_c -isystem /opt/ros/foxy/include -fPIC -Wall -std=gnu11 -MD -MT CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/srv/detail/get_position__functions.c.o -MF CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/srv/detail/get_position__functions.c.o.d -o CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/srv/detail/get_position__functions.c.o -c /home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces/rosidl_generator_c/dynamixel_sdk_custom_interfaces/srv/detail/get_position__functions.c
[ 12%] Linking C shared library libdynamixel_sdk_custom_interfaces__rosidl_generator_c.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/link.txt --verbose=1
/usr/bin/cc -fPIC -shared -Wl,-soname,libdynamixel_sdk_custom_interfaces__rosidl_generator_c.so -o libdynamixel_sdk_custom_interfaces__rosidl_generator_c.so CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/msg/detail/set_position__functions.c.o CMakeFiles/dynamixel_sdk_custom_interfaces__rosidl_generator_c.dir/rosidl_generator_c/dynamixel_sdk_custom_interfaces/srv/detail/get_position__functions.c.o -Wl,-rpath,/opt/ros/foxy/lib: /opt/ros/foxy/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_c.so /opt/ros/foxy/lib/libbuiltin_interfaces__rosidl_typesupport_c.so /opt/ros/foxy/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_cpp.so /opt/ros/foxy/lib/libbuiltin_interfaces__rosidl_typesupport_cpp.so /opt/ros/foxy/lib/libbuiltin_interfaces__rosidl_generator_c.so /opt/ros/foxy/lib/librosidl_typesupport_introspection_cpp.so /opt/ros/foxy/lib/librosidl_typesupport_introspection_c.so /opt/ros/foxy/lib/librosidl_typesupport_cpp.so /opt/ros/foxy/lib/librosidl_typesupport_c.so /opt/ros/foxy/lib/librosidl_runtime_c.so /opt/ros/foxy/lib/librcpputils.so /opt/ros/foxy/lib/librcutils.so -ldl
make[2]: Leaving directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
[ 12%] Built target dynamixel_sdk_custom_interfaces__rosidl_generator_c
make[1]: Leaving directory '/home/mainuser/colcon_ws/build/dynamixel_sdk_custom_interfaces'
make: *** [Makefile:149: all] Error 2
--- stderr: dynamixel_sdk_custom_interfaces
make[1]: *** No rule to make target 'dynamixel_sdk_custom_interfaces__py/CMakeFiles/dynamixel_sdk_custom_interfaces__py.dir/all', needed by 'CMakeFiles/dynamixel_sdk_custom_interfaces__python.dir/all'. Stop.
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:149: all] Error 2
---
Failed <<< dynamixel_sdk_custom_interfaces [1.42s, exited with code 2]
Summary: 0 packages finished [1.63s]
1 package failed: dynamixel_sdk_custom_interfaces
1 package had stderr output: dynamixel_sdk_custom_interfaces
This used to work for me as I mentioned above. I attempted to debug my ros2 packages in visual code and might have altered some settings (I don't remember editing system settings though, just settings in visual code) but either way, it was working, but now isn't and I can't think of anything that caused it or a way to solve it. Any help would be appreciated. The only solution I see now is reinstalling the operating system which I would prefer not to at this point.

cmake find_package for libxml2 doesn't return valid header directories

I'm on ubuntu and I've installed gcc, cmake, libxml2-dev and I've this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
find_package(LIBXML2 CONFIG)
include_directories(${LIBXML2_INCLUDE_DIRS})
link_libraries(${LIBXML2_LIBRARY})
add_executable(testusage testusage.cpp)
I run "cmake ." OK, and then make VERBOSE=1 it gives compilation error:
Scanning dependencies of target testusage
[ 50%] Building CXX object CMakeFiles/testusage.dir/testusage.cpp.o
/home/a/proj/mynet/mytest/cpp3p/useXml2/testusage.cpp:1:9: fatal error: libxml/parser.h: no such file or directory
#include<libxml/parser.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/testusage.dir/build.make:62: recipe for target 'CMakeFiles/testusage.dir/testusage.cpp.o' failed
make[2]: *** [CMakeFiles/testusage.dir/testusage.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testusage.dir/all' failed
make[1]: *** [CMakeFiles/testusage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Seems that "include_directories" didn't add any "-I" option into Makefile. How could I fix it?
Works fine for me, as soon as I use find_package(LibXml2) instead of find_package(LIBXML2 CONFIG). According to cmake-documentation, the config-mode tries to find a configuration-file, provided by the package:
Config mode search attempts to locate a configuration file provided by
the package to be found. A cache entry called _DIR is
created to hold the directory containing the file. By default the
command searches for a package with the name . If the
NAMES option is given the names following it are used instead of
. The command searches for a file called
Config.cmake or -config.cmake
for each name specified. A replacement set of possible configuration
file names may be given using the CONFIGS option.
So it seems to me, as if libxml2 does not provide such a config-file.
testusage.cpp
#include <iostream>
#include <libxml/parser.h>
int main(void)
{
xmlParserNodeInfo info;
std::cout << std::hex << &info << std::endl;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
find_package(LibXml2)
include_directories(${LIBXML2_INCLUDE_DIRS})
link_libraries(${LIBXML2_LIBRARY})
add_executable(testusage testusage.cpp)
calling and building it
$ cmake .
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.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
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.4")
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test/build
$ make --trace
Makefile:176: target 'cmake_check_build_system' does not exist
/usr/bin/cmake -H/tmp/test -B/tmp/test/build --check-build-system CMakeFiles/Makefile.cmake 0
Makefile:83: update target 'all' due to: cmake_check_build_system
/usr/bin/cmake -E cmake_progress_start /tmp/test/build/CMakeFiles /tmp/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
CMakeFiles/Makefile2:67: target 'CMakeFiles/testusage.dir/all' does not exist
make -f CMakeFiles/testusage.dir/build.make CMakeFiles/testusage.dir/depend
CMakeFiles/testusage.dir/build.make:112: target 'CMakeFiles/testusage.dir/depend' does not exist
cd /tmp/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/test /tmp/test /tmp/test/build /tmp/test/build /tmp/test/build/CMakeFiles/testusage.dir/DependInfo.cmake --color=
Scanning dependencies of target testusage
make -f CMakeFiles/testusage.dir/build.make CMakeFiles/testusage.dir/build
CMakeFiles/testusage.dir/build.make:62: update target 'CMakeFiles/testusage.dir/testusage.cpp.o' due to: ../testusage.cpp /usr/include/libxml2/libxml/SAX.h /usr/include/libxml2/libxml/SAX2.h /usr/include/libxml2/libxml/dict.h /usr/include/libxml2/libxml/encoding.h /usr/include/libxml2/libxml/entities.h /usr/include/libxml2/libxml/globals.h /usr/include/libxml2/libxml/hash.h /usr/include/libxml2/libxml/list.h /usr/include/libxml2/libxml/parser.h /usr/include/libxml2/libxml/threads.h /usr/include/libxml2/libxml/tree.h /usr/include/libxml2/libxml/valid.h /usr/include/libxml2/libxml/xlink.h /usr/include/libxml2/libxml/xmlIO.h /usr/include/libxml2/libxml/xmlautomata.h /usr/include/libxml2/libxml/xmlerror.h /usr/include/libxml2/libxml/xmlexports.h /usr/include/libxml2/libxml/xmlmemory.h /usr/include/libxml2/libxml/xmlregexp.h /usr/include/libxml2/libxml/xmlstring.h /usr/include/libxml2/libxml/xmlversion.h CMakeFiles/testusage.dir/flags.make
/usr/bin/cmake -E cmake_echo_color --switch= --green --progress-dir=/tmp/test/build/CMakeFiles --progress-num=1 "Building CXX object CMakeFiles/testusage.dir/testusage.cpp.o"
[ 50%] Building CXX object CMakeFiles/testusage.dir/testusage.cpp.o
/usr/bin/c++ -I/usr/include/libxml2 -o CMakeFiles/testusage.dir/testusage.cpp.o -c /tmp/test/testusage.cpp
CMakeFiles/testusage.dir/build.make:95: update target 'testusage' due to: CMakeFiles/testusage.dir/link.txt CMakeFiles/testusage.dir/testusage.cpp.o CMakeFiles/testusage.dir/build.make /usr/lib/x86_64-linux-gnu/libxml2.so
/usr/bin/cmake -E cmake_echo_color --switch= --green --bold --progress-dir=/tmp/test/build/CMakeFiles --progress-num=2 "Linking CXX executable testusage"
[100%] Linking CXX executable testusage
/usr/bin/cmake -E cmake_link_script CMakeFiles/testusage.dir/link.txt --verbose=
/usr/bin/cmake -E cmake_echo_color --switch= --progress-dir=/tmp/test/build/CMakeFiles --progress-num=1,2 "Built target testusage"
[100%] Built target testusage
/usr/bin/cmake -E cmake_progress_start /tmp/test/build/CMakeFiles 0
$ ./testusage
0x7ffe0c7a5360

CMAKE Error /usr/bin/cc -- broken

I am trying to compile a simple .cpp file but when i issue cmake .. its throw error
-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- Check for working C compiler: /usr/bin/cc
-- **Check for working C compiler: /usr/bin/cc -- broken**
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/user/jagdish/hello/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec3772316685/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec3772316685.dir/build.make
CMakeFiles/cmTryCompileExec3772316685.dir/build
make[1]: Entering directory `/home/user/jagdish/hello/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/home/user/jagdish/hello/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object
CMakeFiles/cmTryCompileExec3772316685.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTryCompileExec3772316685.dir/testCCompiler.c.o
-c /home/user/jagdish/hello/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec3772316685
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec3772316685.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTryCompileExec3772316685.dir/testCCompiler.c.o -o
cmTryCompileExec3772316685 -rdynamic
collect2: error: ld terminated with signal 11 [Segmentation fault]
make[1]: *** [cmTryCompileExec3772316685] Error 1
make[1]: Leaving directory `/home/user/jagdish/hello/CMakeFiles/CMakeTmp'
make: *** [cmTryCompileExec3772316685/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
-- Configuring incomplete, errors occurred!
See also "/home/user/jagdish/hello/CMakeFiles/CMakeOutput.log".
See also "/home/user/jagdish/hello/CMakeFiles/CMakeError.log".

OpenCV 3.0 source code installation troubleshooting

I installed OpenCV3.0 using the source code obtained from itseez github repo. I set the install prefix as /home/ubuntu/installed_libs/. All went well. I even set ldconfig path in /etc/ld.so.conf.d/local.conf and then sudo ldconfig.
However in my project (CMake) I cannot find the newly installed directory.
When I do cmake ../ in the build directory it throws the following error.
I did some changes as suggested in the answers.
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR /home/ubuntu/installed_libs/share/OpenCV)
find_package( OpenCV )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBRARIES} )
message(STATUS "OpenCV_FOUND=${OpenCV_FOUND}")
message(STATUS "OpenCV_INCLUDES=${OpenCV_INCLUDE_DIR}")
message(STATUS "OpenCV_LIBRARIES=${OpenCV_LIBRARIES}")
message(STATUS "OpenCV_DEFINATIONS=${OpenCV_DEFINATIONS}")
message(STATUS "OpenCV_DIR=${OpenCV_DIR}")
Now cmake happens successfully.
$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- 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
-- 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
-- Found CUDA: /usr/local/cuda (found suitable exact version "6.5")
-- OpenCV_FOUND=1
-- OpenCV_INCLUDES=
-- OpenCV_LIBRARIES=opencv_videostab;opencv_videoio;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_hal;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudaobjdetect;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_core;opencv_calib3d
-- OpenCV_DEFINATIONS=
-- OpenCV_DIR=/home/ubuntu/installed_libs/share/OpenCV
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/ctry/opencvtest/build
However, when I do a make, I get an error :
Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
Linking CXX executable DisplayImage
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `main':
DisplayImage.cpp:(.text+0x94): undefined reference to `cv::imread(std::string const&, int)'
DisplayImage.cpp:(.text+0x108): undefined reference to `cv::namedWindow(std::string const&, int)'
DisplayImage.cpp:(.text+0x14e): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x15e): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [DisplayImage] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2
I know this is a linking error. How should I fix this?
Verbose make display incase it is helpful.
$ make VERBOSE=1
/usr/bin/cmake -H/home/ubuntu/ctry/opencvtest -B/home/ubuntu/ctry/opencvtest/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/ubuntu/ctry/opencvtest/build/CMakeFiles /home/ubuntu/ctry/opencvtest/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/ubuntu/ctry/opencvtest/build'
make -f CMakeFiles/DisplayImage.dir/build.make CMakeFiles/DisplayImage.dir/depend
make[2]: Entering directory `/home/ubuntu/ctry/opencvtest/build'
cd /home/ubuntu/ctry/opencvtest/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ubuntu/ctry/opencvtest /home/ubuntu/ctry/opencvtest /home/ubuntu/ctry/opencvtest/build /home/ubuntu/ctry/opencvtest/build /home/ubuntu/ctry/opencvtest/build/CMakeFiles/DisplayImage.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/ubuntu/ctry/opencvtest/build'
make -f CMakeFiles/DisplayImage.dir/build.make CMakeFiles/DisplayImage.dir/build
make[2]: Entering directory `/home/ubuntu/ctry/opencvtest/build'
Linking CXX executable DisplayImage
/usr/bin/cmake -E cmake_link_script CMakeFiles/DisplayImage.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o -o DisplayImage -L/usr/local/cuda/lib -rdynamic /home/ubuntu/installed_libs/lib/libopencv_videostab.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_videoio.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_video.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_ts.a /home/ubuntu/installed_libs/lib/libopencv_superres.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_stitching.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_shape.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_photo.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_objdetect.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_ml.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgproc.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgcodecs.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_highgui.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_hal.a /home/ubuntu/installed_libs/lib/libopencv_flann.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_features2d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudev.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudawarping.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudastereo.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaoptflow.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaobjdetect.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudalegacy.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaimgproc.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudafilters.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudafeatures2d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudacodec.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudabgsegm.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaarithm.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_core.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_calib3d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudawarping.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_objdetect.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudafilters.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudaarithm.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_features2d.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_ml.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_highgui.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_videoio.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgcodecs.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_flann.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_video.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_imgproc.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_core.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_cudev.so.3.0.0 /home/ubuntu/installed_libs/lib/libopencv_hal.a -ldl -lm -lpthread -lrt -lcudart -lnppc -lnppi -lnpps -lcufft -lcudart -lnppc -lnppi -lnpps -lcufft -Wl,-rpath,/usr/local/cuda/lib:/home/ubuntu/installed_libs/lib
CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o: In function `main':
DisplayImage.cpp:(.text+0x94): undefined reference to `cv::imread(std::string const&, int)'
DisplayImage.cpp:(.text+0x108): undefined reference to `cv::namedWindow(std::string const&, int)'
DisplayImage.cpp:(.text+0x14e): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x15e): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [DisplayImage] Error 1
make[2]: Leaving directory `/home/ubuntu/ctry/opencvtest/build'
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make[1]: Leaving directory `/home/ubuntu/ctry/opencvtest/build'
make: *** [all] Error 2
You should check the output of:
ldconfig -p | grep -i opencv
pkg-config --cflags opencv
pkg-config --libs opencv
If nothing is listed, then you ldconfig may configured incorrectly. If the system-installed version of OpenCV is listed, it may be a problem of the search order.
In either case, you could try to configure the CMAKE_MODULE_PATH of your project DisplayImage, which is searched by CMake before standard system locations. So, assuming your in your build directory of DisplayImage is $SRC_DIR/build, configure your project like this
cmake -DCMAKE_MODULE_PATH="/home/ubuntu/installed_libs/<OpenCV directory>" <other options> ..
Also interesting: what happens in the background of find_package().
You can add
set(OpenCV_DIR /home/ubuntu/installed_libs/share/OpenCV)
to your CMakeLists, so it looks something like
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR /home/ubuntu/installed_libs/share/OpenCV)
find_package( OpenCV REQUIRED 3.0 )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

CMake to Makefile - Makefile gives `collect2: error: ld returned 1 exit status`

I am trying to familiarize my self with Cmake by following this example:
In short I have this c++ code . I want to generate a makefile for this code using Cmake and then run the makefile. Unfortunately the Makefile generated gives out an error. I am using Windows 7
Here is the code that I am using
File: main.cpp
#include "ToDo.h"
int main( int argc, char** argv)
{
ToDo list;
return 0;
}
File: ToDo.h
#ifndef TODO_H
#define TODO_H
class ToDo
{
public:
ToDo();
~ToDo();
};
File:ToDo.cpp
#include "ToDo.h"
ToDo::ToDo()
{
}
ToDo::~ToDo()
{
}
#endif // TODO_H
This my CMakeLists.txt
project("To Do List")
add_executable(toDo main.cpp ToDo.cpp)
Here is what I am doing in cygwin
admin#US01WKS03044 /cygdrive/c/CmakeTest/build
$ cmake -G "Unix Makefiles" ..
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: C:/cygwin64/bin/cc
-- Check for working C compiler: C:/cygwin64/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working CXX compiler: C:/cygwin64/bin/c++.exe
-- Check for working CXX compiler: C:/cygwin64/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - failed
-- Configuring done
-- Generating done
-- Build files have been written to: C:/CmakeTest/build
admin#US01WKS03044 /cygdrive/c/CmakeTest/build
$ ls
cmake_install.cmake CMakeCache.txt CMakeFiles Makefile
admin#US01WKS03044 /cygdrive/c/CmakeTest/build
$ make VERBOSE=1
"C:/Program Files (x86)/CMake/bin/cmake.exe" -HC:/CmakeTest -BC:/CmakeTest/build --check-build-system CMakeFiles/Makefile.cmake 0
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_start C:/CmakeTest/build/CMakeFiles C:/CmakeTest/build/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/cygdrive/c/CmakeTest/build'
/usr/bin/make -f CMakeFiles/toDo.dir/build.make CMakeFiles/toDo.dir/depend
make[2]: Entering directory `/cygdrive/c/CmakeTest/build'
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_depends "Unix Makefiles" C:/CmakeTest C:/CmakeTest C:/CmakeTest/build C:/CmakeTest/build C:/CmakeTest/build/CMakeFiles/toDo.dir/DependInfo.cmake --color=
Dependee "C:/CmakeTest/build/CMakeFiles/toDo.dir/DependInfo.cmake" is newer than depender "C:/CmakeTest/build/CMakeFiles/toDo.dir/depend.internal".
Dependee "C:/CmakeTest/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/CmakeTest/build/CMakeFiles/toDo.dir/depend.internal".
Scanning dependencies of target toDo
make[2]: Leaving directory `/cygdrive/c/CmakeTest/build'
/usr/bin/make -f CMakeFiles/toDo.dir/build.make CMakeFiles/toDo.dir/build
make[2]: Entering directory `/cygdrive/c/CmakeTest/build'
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report C:/CmakeTest/build/CMakeFiles 1
[ 50%] Building CXX object CMakeFiles/toDo.dir/main.cpp.o
C:/cygwin64/bin/c++.exe -o CMakeFiles/toDo.dir/main.cpp.o -c C:/CmakeTest/main.cpp
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E cmake_progress_report C:/CmakeTest/build/CMakeFiles 2
[100%] Building CXX object CMakeFiles/toDo.dir/ToDo.cpp.o
C:/cygwin64/bin/c++.exe -o CMakeFiles/toDo.dir/ToDo.cpp.o -c C:/CmakeTest/ToDo.cpp
Linking CXX executable toDo.exe
"C:/Program Files (x86)/CMake/bin/cmake.exe" -E remove -f CMakeFiles/toDo.dir/objects.a
C:/cygwin64/bin/ar.exe cr CMakeFiles/toDo.dir/objects.a #CMakeFiles/toDo.dir/objects1.rsp
C:/cygwin64/bin/c++.exe -Wl,--whole-archive CMakeFiles/toDo.dir/objects.a -Wl,--no-whole-archive -o toDo.exe -Wl,--out-implib,libtoDo.dll.a -Wl,--major-image-version,0,--minor-image-version,0
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.33-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
/usr/src/debug/cygwin-1.7.33-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
make[2]: *** [toDo.exe] Error 1
make[2]: Leaving directory `/cygdrive/c/CmakeTest/build'
make[1]: *** [CMakeFiles/toDo.dir/all] Error 2
make[1]: Leaving directory `/cygdrive/c/CmakeTest/build'
make: *** [all] Error 2
Why did the Makefile fail ?
The error means that the compiler is looking for WinMain as the entrypoint of your executable, instead of the classic main, and it can't find it.
As I don't use cygwin, can't really say why that is (WinMain is specific to windows gui apps, if I'm not mistaking), but you could to rename main to WinMain and see if it works. Or see http://log4aj.blogspot.ro/2010/11/cygwin-gcc-undefined-reference-to.html.