OpenCV 3.0 source code installation troubleshooting - c++

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} )

Related

CMake + MSys2 undefined references to everything (including c++ runtime)

I'm playing around with developing a cross-platform C++ project. Things build fine on Linux, but on Windows (10) + MSys2 I've run into a strange issue. Compile works fine (picks up my include dirs, etc.), but linking fails with all sorts of undefined reference errors to a static imported library I have, and even the C++ runtime.
I've tried setting CMAKE_C[XX]_COMPILER, CMAKE_MAKE_PROGRAM, but the output from the configuration step is always the same:
$ cmake ..
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /mingw64/bin/CC.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: <....>
As mentioned earlier the compile works, but linking the executable fails spectacularly. Here is my minimal working example:
$ cat ../CMakeLists.txt
project(example)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable(example
main.cpp
)
Here is an sample of the output (the rest is omitted for brevity):
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.cpp.obj:main.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'
Adding -v to cmake produces the following commands.
Compile:
/mingw64/bin/CC.exe -std=gnu++17 -o CMakeFiles/example.dir/main.cpp.obj -c /home/.../Development/minex/main.cpp
Link:
/mingw64/bin/CC.exe CMakeFiles/example.dir/main.cpp.obj -o example
CC.exe seems off... and it's used if I set the CXX compiler flag or not...
I also tried generating "MSYS2 Makefiles" but that also fails (doesn't know the generator).
I can reproduce the output by running
$ CC main.cpp -o example
while
$ g++ main.cpp -o example
works fine.
CMake version is 3.18.4.
Edit: This is the entire output of running make VERBOSE=1 (using mingw64-cmake seems to produce the same output, except the 'entering directory' and 'leaving directory' paths are absolute windows paths):
$ cat log
/usr/bin/cmake.exe -S/home/<...>/Development/minex -B/home/<...>/Development/minex/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake.exe -E cmake_progress_start /home/<...>/Development/minex/build/CMakeFiles /home/<...>/Development/minex/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/<...>/Development/minex/build'
make -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/depend
make[2]: Entering directory '/home/<...>/Development/minex/build'
cd /home/<...>/Development/minex/build && /usr/bin/cmake.exe -E cmake_depends "Unix Makefiles" /home/<...>/Development/minex /home/<...>/Development/minex /home/<...>/Development/minex/build /home/<...>/Development/minex/build /home/<...>/Development/minex/build/CMakeFiles/example.dir/DependInfo.cmake --color=
Dependee "/home/<...>/Development/minex/build/CMakeFiles/example.dir/DependInfo.cmake" is newer than depender "/home/<...>/Development/minex/build/CMakeFiles/example.dir/depend.internal".
Dependee "/home/<...>/Development/minex/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/<...>/Development/minex/build/CMakeFiles/example.dir/depend.internal".
Scanning dependencies of target example
make[2]: Leaving directory '/home/<...>/Development/minex/build'
make -f CMakeFiles/example.dir/build.make CMakeFiles/example.dir/build
make[2]: Entering directory '/home/<...>/Development/minex/build'
[ 50%] Building CXX object CMakeFiles/example.dir/main.obj
/mingw64/bin/CC.exe -std=gnu++17 -o CMakeFiles/example.dir/main.obj -c /home/<...>/Development/minex/main.cpp
[100%] Linking CXX executable example
/usr/bin/cmake.exe -E cmake_link_script CMakeFiles/example.dir/link.txt --verbose=1
/mingw64/bin/CC.exe CMakeFiles/example.dir/main.obj -o example
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x23): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x32): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.rdata$.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_[.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_]+0x0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/example.dir/main.obj:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example.dir/build.make:103: example] Error 1
make[2]: Leaving directory '/home/<...>/Development/minex/build'
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/example.dir/all] Error 2
make[1]: Leaving directory '/home/<...>/Development/minex/build'
make: *** [Makefile:103: all] Error 2
Solution:
I was setting CMAKE_CXX_COMPILER wrong :/. I was doing it from memory, and I just did
CMAKE_CXX_COMPILER=... cmake ..
not
cmake .. -DCMAKE_CXX_COMPILER=...
However! It's still weird that CC is used to successfully compile cpp files, but it can't link the object files.
If you are using mingw64 compiler in MSYS2 make sure you are using mingw64 version of cmake too.
Using cmake not aligned with gcc e.g.:
MINGW64
# which gcc
/mingw64/bin/gcc
MINGW64
# which cmake
/usr/bin/cmake
Will led to following error when running cmake:
...
-- The CXX compiler identification is GNU 10.2.0
System is unknown to cmake, create:
Platform/MINGW64_NT-10.0-19041 to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
...
and linker error in build step.
So make sure you install mingw64 version of cmake:
MINGW64
pacman -S mingw-w64-x86_64-cmake
You need to close terminal and open it again after cmake is installed. Then make sure you have aligned versions of gcc and cmake installed:
MINGW64
# which gcc
/mingw64/bin/gcc
MINGW64
# which cmake
/mingw64/bin/cmake
Now cmake should work properly.
You have these errors because you are trying to compile/link c++ program with a c compiler. For example the two undefined references you are mentioning are part of libstdc++. It is used by default when using g++ but not with CC. If you want to use CC you have to add it manually -lstdc++.
The easiest way is to compile and link c++ programs by using g++.
For some reason the /mingw64/bin/CC.exe is considered as the CXX compiler and the working detection is skipped. to avoid the skipp of the working detection you can add set(CMAKE_CXX_COMPILER_WORKS 1). to modify the compiler it self you can set CMAKE_CXX_COMPILER as explained in CMAKE_CXX_COMPILER or set CXX as explained in CXX . be careful to clean the cache.

How to fix "ld: symbol(s) not found for architecture x86_64" using C++, CMake and Tensorflow?

I created a test project in C ++ using TensorFlow with CMake. But I have an error:
ld: symbol(s) not found for architecture x86_64
I think, I have an error in my CMake files. When I try compile via the terminal with gcc tensortest.cpp -ltensorflow -o tf, everything works fine.
I have two CMake files.
FindTensorFlow.cmake:
# Locates the tensorFlow library and include directories.
include(FindPackageHandleStandardArgs)
unset(TENSORFLOW_FOUND)
find_path(TensorFlow_INCLUDE_DIR
NAMES
tensorflow
HINTS
/usr/local/include/tensorflow)
find_library(TensorFlow_LIBRARY
NAMES
libtensorflow_framework.1.14.0.dylib
libtensorflow_framework.1.dylib
libtensorflow_framework.dylib
libtensorflow.1.14.0.dylib
libtensorflow.1.dylib
libtensorflow.dylib
HINTS
/usr/local/lib)
# set TensorFlow_FOUND
find_package_handle_standard_args(TensorFlow DEFAULT_MSG TensorFlow_INCLUDE_DIR TensorFlow_LIBRARY)
# set external variables for usage in CMakeLists.txt
if(TENSORFLOW_FOUND)
set(TensorFlow_LIBRARIES ${TensorFlow_LIBRARY})
set(TensorFlow_INCLUDE_DIRS ${TensorFlow_INCLUDE_DIR})
endif()
# hide locals from GUI
mark_as_advanced(TensorFlow_INCLUDE_DIR TensorFlow_LIBRARY)
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(TensorFlowTest)
set(CMAKE_CXX_STANDARD 14)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
find_package(TensorFlow REQUIRED)
include_directories(${TensorFlow_INCLUDE_DIRS} ${TensorFlow_LIBRARIES})
add_executable(TensorFlowTest main.cpp)
target_link_libraries(TensorFlowTest ${TensorFlow_INCLUDE_DIRS} ${TensorFlow_LIBRARIES})
And one main.cpp
#include <stdio.h>
#include <tensorflow/c/c_api.h>
int main() {
printf("Hello from TensorFlow C library version %s\n", TF_Version());
return 0;
}
When reload project, I have a CMake message:
-- Found TensorFlow: /usr/local/include
-- Configuring done
WARNING: Target "TensorFlowTest" requests linking to directory "/usr/local/include". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /Users/neikr/CLionProjects/TensorFlowTest/cmake-build-debug
And when compiling:
Scanning dependencies of target TensorFlowTest
[ 50%] Building CXX object CMakeFiles/TensorFlowTest.dir/main.cpp.o
[100%] Linking CXX executable TensorFlowTest
Undefined symbols for architecture x86_64:
"_TF_Version", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [TensorFlowTest] Error 1
make[2]: *** [CMakeFiles/TensorFlowTest.dir/all] Error 2
make[1]: *** [CMakeFiles/TensorFlowTest.dir/rule] Error 2
make: *** [TensorFlowTest] Error 2
Update
I tried make with VERBOSE=1 and I get this output:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -S/Users/neikr/CLionProjects/TensorFlowTest -B/Users/neikr/CLionProjects/TensorFlowTest --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_progress_start /Users/neikr/CLionProjects/TensorFlowTest/CMakeFiles /Users/neikr/CLionProjects/TensorFlowTest/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/TensorFlowTest.dir/build.make CMakeFiles/TensorFlowTest.dir/depend
cd /Users/neikr/CLionProjects/TensorFlowTest && /Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_depends "Unix Makefiles" /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest /Users/neikr/CLionProjects/TensorFlowTest/CMakeFiles/TensorFlowTest.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/TensorFlowTest.dir/build.make CMakeFiles/TensorFlowTest.dir/build
[ 50%] Linking CXX executable TensorFlowTest
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -E cmake_link_script CMakeFiles/TensorFlowTest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/TensorFlowTest.dir/main.cpp.o -o TensorFlowTest -Wl,-rpath,/usr/local/lib /usr/local/lib/libtensorflow_framework.1.14.0.dylib
Undefined symbols for architecture x86_64:
"_TF_Version", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [TensorFlowTest] Error 1
make[1]: *** [CMakeFiles/TensorFlowTest.dir/all] Error 2
make: *** [all] Error 2
Also, I tried adding message("TensorFlow_LIBRARIES: ${TensorFlow_LIBRARIES}") to the end of my CMake and I get this message:
TensorFlow_LIBRARIES: /usr/local/lib/libtensorflow_framework.1.14.0.dylib
Based on your print-out from the message() command, it is more clear what is going on. In your FindTensorFlow.cmake file, the find_library() call only finds one library (libtensorflow_framework.1.14.0.dylib), which is expected behavior:
Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.
When more than one value is given to the NAMES option this command by default will consider one name at a time and search every directory for it.
Thus, once find_library() finds the libtensorflow_framework library, the search stops. If you want to also find libtensorflow.dylib, which may help with your link error, you have to specify another find_library() call, using a different TensorFlow_ variable. So changing that section of your FindTensorFlow.cmake to something like this should help:
find_library(TensorFlow_LIBRARY
NAMES
libtensorflow.1.14.0.dylib
libtensorflow.1.dylib
libtensorflow.dylib
HINTS
/usr/local/lib)
find_library(TensorFlow_FRAMEWORK_LIBRARY
NAMES
libtensorflow_framework.1.14.0.dylib
libtensorflow_framework.1.dylib
libtensorflow_framework.dylib
HINTS
/usr/local/lib)
# set TensorFlow_FOUND
find_package_handle_standard_args(TensorFlow DEFAULT_MSG
TensorFlow_INCLUDE_DIR
TensorFlow_LIBRARY
TensorFlow_FRAMEWORK_LIBRARY
)

Linking boost_numpy3 with CMAKE

TL;DR When updating from CMake 3.10 to CMake 3.11.1 on archlinux, the following configuration line:
find_package(Boost COMPONENTS python3 COMPONENTS numpy3 REQUIRED)
leads to CMake linking against 3 different libraries
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- python3
-- numpy3
-- python
instead of the previous behaviour:
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- python3
-- numpy3
resulting in a linker error.
I use CMake to build a piece of software that relies on Boost python, and, since a couple of days ago, it seems that the line
find_package(Boost COMPONENTS numpy3 REQUIRED)
is no longer sufficient for CMake to understand that it should link the program against the Boost python3 library, and it uses the Boost library python instead.
Here is a minimal working example to reproduce what I am talking about.
test.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
}
CMakeList.txt
set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(PythonLibs 3 REQUIRED)
find_package(Boost COMPONENTS numpy3 REQUIRED)
add_executable (test test.cpp)
target_link_libraries(test ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
With this configuration of CMake, a linker error will occur, and the error persists when I change the line adding numpy to
find_package(Boost COMPONENTS python3 COMPONENTS numpy3 REQUIRED)
Here is the result of cmake . && make:
/home/rastapopoulos/test $ cmake .
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- numpy3
-- python
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.11)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rastapopoulos/test
/home/rastapopoulos/test $ make
/usr/bin/cmake -H/home/rastapopoulos/test -B/home/rastapopoulos/test --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/rastapopoulos/test/CMakeFiles /home/rastapopoulos/test/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/rastapopoulos/test'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory '/home/rastapopoulos/test'
cd /home/rastapopoulos/test && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/rastapopoulos/test /home/rastapopoulos/test /home/rastapopoulos/test /home/rastapopoulos/test /home/rastapopoulos/test/CMakeFi
les/test.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/rastapopoulos/test'
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory '/home/rastapopoulos/test'
[ 50%] Linking CXX executable test
/usr/bin/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/test.dir/test.o -o test -lboost_numpy3 -lboost_python -lpython3.6m
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_Size'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyUnicodeUCS4_FromEncodedObject'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyFile_FromString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_Type'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyInt_Type'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_FromString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyUnicodeUCS4_AsWideChar'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyInt_AsLong'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_InternFromString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyClass_Type'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyString_AsString'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyInt_FromLong'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/../../../../lib/libboost_python.so: undefined reference to `PyFile_AsFile'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.dir/build.make:90: test] Error 1
make[2]: Leaving directory '/home/rastapopoulos/test'
make[1]: *** [CMakeFiles/Makefile2:71: CMakeFiles/test.dir/all] Error 2
make[1]: Leaving directory '/home/rastapopoulos/test'
make: *** [Makefile:87: all] Error 2
Has anyone experienced a similar problem and managed to solve it? I use cmake 3.11.1, boost 1.66.0-2, and run an updated version of Archlinux.
This bug is due to an invalid dependency description in FindBoost.cmake
set(_Boost_NUMPY_DEPENDENCIES python)
This has been fixed at https://github.com/Kitware/CMake/commit/c747d4ccb349f87963a8d1da69394bc4db6b74ed
Please use latest one, or you can rewrite it manually:
set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})
CMake 3.10 does not properly support Boost 1.66. The Boost dependencies are hard-coded and if they chance, CMake has to adopt.
Delete the build directory and reconfigure. The configure step uses cached variables which prevents re-detection with the newer routines.

How to link Boost library with CMake (on a cluster if boost is in non-standard location)?

I have a strange problem, when I try to build a simple Boost test program on a cluster.
On my machine, everything works just fine.
First the example:
//main.cpp
#include <iostream>
#include <string>
#include "boost/program_options.hpp"
namespace po = boost::program_options;
int main( int argc , char* argv[] ) {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("greet", po::value<std::string>()->default_value("World"), "the greeting")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
std::cout << "Hello, " << vm["greet"].as<std::string>() << "!" << std::endl;
return 0;
}
And the CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(boost_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost COMPONENTS program_options)
set(SOURCE_FILES main.cpp)
if(Boost_FOUND)
add_executable(boost_test ${SOURCE_FILES})
target_include_directories(boost_test PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(boost_test PRIVATE ${Boost_LIBRARIES})
endif(Boost_FOUND)
I use cmake like
cmake -G "Unix Makefiles" /path/to/code
make
The error I get is a undefined reference error during linking:
Linking CXX executable boost_test
CMakeFiles/boost_test.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x6d): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
CMakeFiles/boost_test.dir/main.cpp.o: In function `boost::program_options::variables_map::operator[](std::string const&) const':
main.cpp:(.text._ZNK5boost15program_options13variables_mapixERKSs[_ZNK5boost15program_options13variables_mapixERKSs]+0x1f): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::string const&) const'
and so on ...
So I thought that maybe the installation of boost is not correct and I tried to write a makefile myself.
boost-test-1: ../code/main.cpp
g++ ../code/main.cpp -o boost-test-1 -lboost_program_options
boost-test-2: ../code/main.cpp
g++ ../code/main.cpp -o boost-test-2 /some/fancy/cluster/path/certainly/non/standard/Boost/lib/libboost_program_options.so
Both ways to build the program work fine. But what cmake is doing is basically the following: first, build a object file, second link the object file and the library together and that fails.
boost-test-3: ../code/main.cpp
/usr/bin/c++ -I/some/fancy/cluster/path/certainly/non/standard/Boost/include -std=c++11 -o main.cpp.o -c ../code/main.cpp
/usr/bin/c++ -std=c++11 main.cpp.o -o boost-test-3 /some/fancy/cluster/path/certainly/non/standard/Boost/lib/libboost_program_options.so
As already mentioned, on my computer all described ways to build the program work, but on the cluster, the cmake way unfortunately fails. The problem is that I have another larger project that uses cmake and I am looking for a way to build it on that particular cluster.
Do you have any idea what could cause the problem and how to solve it?
Thank you!
Update: This is the whole output of the build process. I shortened the paths to cmake and boost to "path/to/cmake" and "path/to/boost" to make it shorter and better readable, but it is the same long path as described above.
$ cmake -G "Unix Makefiles" ../code/
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- 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
-- Boost version: 1.61.0
-- Found the following Boost libraries:
-- program_options
-- Boost include directories (Boost_INCLUDE_DIRS): /path/to/Boost/include
-- Link directories for Boost libraries (Boost_LIBRARY_DIRS): /path/to/Boost/lib
-- Boost component libraries to be linked (Boost_LIBRARIES): /path/to/Boost/lib/libboost_program_options.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/test/build
$ make VERBOSE=1
/path/to/CMake/bin/cmake -H/home/test/code -B/home/test/build --check-build-system CMakeFiles/Makefile.cmake 0
/path/to/CMake/bin/cmake -E cmake_progress_start /home/test/build/CMakeFiles /home/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/test/build'
make -f CMakeFiles/boost_test.dir/build.make CMakeFiles/boost_test.dir/depend
make[2]: Entering directory `/home/test/build'
cd /home/test/build && /path/to/CMake/bin/cmake -E cmake_depends "Unix Makefiles" /home/test/code /home/test/code /home/test/build /home/test/build /home/test/build/CMakeFiles/boost_test.dir/DependInfo.cmake --color=
Dependee "/home/test/build/CMakeFiles/boost_test.dir/DependInfo.cmake" is newer than depender "/home/test/build/CMakeFiles/boost_test.dir/depend.internal".
Dependee "/home/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/test/build/CMakeFiles/boost_test.dir/depend.internal".
Scanning dependencies of target boost_test
make[2]: Leaving directory `/home/test/build'
make -f CMakeFiles/boost_test.dir/build.make CMakeFiles/boost_test.dir/build
make[2]: Entering directory `/home/test/build'
[ 50%] Building CXX object CMakeFiles/boost_test.dir/main.cpp.o
/usr/bin/c++ -I/path/to/Boost/include -std=c++11 -o CMakeFiles/boost_test.dir/main.cpp.o -c /home/test/code/main.cpp
[100%] Linking CXX executable boost_test
/path/to/CMake/bin/cmake -E cmake_link_script CMakeFiles/boost_test.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 CMakeFiles/boost_test.dir/main.cpp.o -o boost_test /path/to/Boost/lib/libboost_program_options.so
CMakeFiles/boost_test.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x6d): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
CMakeFiles/boost_test.dir/main.cpp.o: In function `boost::program_options::variables_map::operator[](std::string const&) const':
main.cpp:(.text._ZNK5boost15program_options13variables_mapixERKSs[_ZNK5boost15program_options13variables_mapixERKSs]+0x1f): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::string const&) const'
CMakeFiles/boost_test.dir/main.cpp.o: In function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)':
main.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0x76): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::vector<std::string, std::allocator<std::string> > const&)'
CMakeFiles/boost_test.dir/main.cpp.o: In function `boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>)':
main.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairISsSsERKSsEE[_ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairISsSsERKSsEE]+0x33): undefined reference to `boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>)'
CMakeFiles/boost_test.dir/main.cpp.o: In function `std::vector<std::string, std::allocator<std::string> > boost::program_options::to_internal<std::string>(std::vector<std::string, std::allocator<std::string> > const&)':
main.cpp:(.text._ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE[_ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE]+0x46): undefined reference to `boost::program_options::to_internal(std::string const&)'
CMakeFiles/boost_test.dir/main.cpp.o:(.rodata._ZTVN5boost15program_options11typed_valueISscEE[_ZTVN5boost15program_options11typed_valueISscEE]+0x40): undefined reference to `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, bool) const'
CMakeFiles/boost_test.dir/main.cpp.o: In function `boost::program_options::typed_value<std::string, char>::name() const':
main.cpp:(.text._ZNK5boost15program_options11typed_valueISscE4nameEv[_ZNK5boost15program_options11typed_valueISscE4nameEv]+0x32): undefined reference to `boost::program_options::arg'
CMakeFiles/boost_test.dir/main.cpp.o: In function `boost::program_options::typed_value<std::string, char>::xparse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&) const':
main.cpp:(.text._ZNK5boost15program_options11typed_valueISscE6xparseERNS_3anyERKSt6vectorISsSaISsEE[_ZNK5boost15program_options11typed_valueISscE6xparseERNS_3anyERKSt6vectorISsSaISsEE]+0x7a): undefined reference to `boost::program_options::validate(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, std::string*, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [boost_test] Error 1
make[2]: Leaving directory `/home/test/build'
make[1]: *** [CMakeFiles/boost_test.dir/all] Error 2
make[1]: Leaving directory `/home/test/build'
make: *** [all] Error 2
Thank you Amadeus, Someprogrammerdude and Tsyvarev for leading me in the right direction here :)
In fact, it was a compiler issue: The default compiler on the cluster was gcc-4.8.5, which cannot handle the latest Boost versions. Therefore, we loaded a module for gcc-5.4 but /usr/bin/gcc was still gcc-4.8.5. When we set the cxx compiler for cmake to gcc-5.4 the build process still failed, since we also use CUDA and per default the host code is not forwarded to the cxx compiler but the c compiler, which was still gcc-4.8.5. So after setting CUDA_HOST_COMPILER to CMAKE_CXX_COMPILER it works fine now.

Linking error of BLAS with CMake

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)