(Sorry for bad English, I'm German)
Hello programmers,
I'm desperately trying to cross compile a program (using OpenCV) on my linux(fedora) x86_x64 laptop for a linux(raspian) Raspberry pi 3.
I'm following this tutorial (https://solderspot.wordpress.com/2016/02/04/cross-compiling-for-raspberry-pi-part-ii/) and a simple std::cout << "test\n"; program compiles and works fine with the following CMakeLists.txt:
cmake_minimum_required (VERSION 2.8)
project (CVS)
find_package(OpenCV REQUIRED)
SET(COMPILE_DEFINITIONS -Werror)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DHOST_ROBO_DIR=/home/username/Dropbox/Roboter)
include_directories(SYSTEM ${PIROOT}/opt/vc/include ${PIROOT}/opt/vc/include/interface/vcos/pthreads ${PIROOT}/opt/vc/include/interface/vmcs_host/linux )
link_directories( ${PIROOT}/opt/vc/lib )
add_executable (CVS ../source/main.cpp)
The Problem comes with OpenCV...
If I use the CMakeLists.txt from above it generates (for obvious reasons) many "undefined reference" errors eg.: "undefined reference to `cv::waitKey(int)'"
If I add "target_link_libraries( CVS ${OpenCV_LIBS} )" or "target_link_libraries(CVS -lopencv_core)" to the CMakeLists.txt make produces the following error:
/home/username/pidev/piroot/usr/local/lib/libopencv_core.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)#GLIBCXX_3.4.20'
If I replace "SET(TOOLROOT ${PITOOLS}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64)" in ~/pidev/pi-toolchain.cmake with "SET(TOOLROOT ${PITOOLS}/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf)" I got the following error:
[username#MSI-Linux msi]$ cmake -DCMAKE_TOOLCHAIN_FILE=~/pidev/pi-toolchain.cmake .
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler
"/home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/username/Dropbox/Roboter/raspySync/CVS/cvs5-6/msi/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_b1abe/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_b1abe.dir/build.make
CMakeFiles/cmTC_b1abe.dir/build
gmake[1]: Verzeichnis
„/home/username/Dropbox/Roboter/raspySync/CVS/cvs5-6/msi/CMakeFiles/CMakeTmp“
wird betreten
Building C object CMakeFiles/cmTC_b1abe.dir/testCCompiler.c.o
/home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
--sysroot=/home/username/pidev/piroot
-Wl,-rpath-link,/home/username/pidev/piroot/opt/vc/lib
-Wl,-rpath-link,/home/username/pidev/piroot/lib/arm-linux-gnueabihf
-Wl,-rpath-link,/home/username/pidev/piroot/usr/lib/arm-linux-gnueabihf
-Wl,-rpath-link,/home/username/pidev/piroot/usr/local/lib -o
CMakeFiles/cmTC_b1abe.dir/testCCompiler.c.o -c
/home/username/Dropbox/Roboter/raspySync/CVS/cvs5-6/msi/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_b1abe
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b1abe.dir/link.txt
--verbose=1
/home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
--sysroot=/home/username/pidev/piroot
-Wl,-rpath-link,/home/username/pidev/piroot/opt/vc/lib
-Wl,-rpath-link,/home/username/pidev/piroot/lib/arm-linux-gnueabihf
-Wl,-rpath-link,/home/username/pidev/piroot/usr/lib/arm-linux-gnueabihf
-Wl,-rpath-link,/home/username/pidev/piroot/usr/local/lib
CMakeFiles/cmTC_b1abe.dir/testCCompiler.c.o -o cmTC_b1abe -rdynamic
/home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld:
cannot find crt1.o: No such file or directory
/home/username/pidev/pitools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld:
cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_b1abe.dir/build.make:97: die Regel für Ziel
„cmTC_b1abe“ scheiterte
gmake[1]: *** [cmTC_b1abe] Fehler 1
gmake[1]: Verzeichnis
„/home/username/Dropbox/Roboter/raspySync/CVS/cvs5-6/msi/CMakeFiles/CMakeTmp“
wird verlassen
Makefile:126: die Regel für Ziel „cmTC_b1abe/fast“ scheiterte
gmake: *** [cmTC_b1abe/fast] Fehler 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "/home/username/Dropbox/Roboter/raspySync/CVS/cvs5-6/msi/CMakeFiles/CMakeOutput.log".
See also "/home/username/Dropbox/Roboter/raspySync/CVS/cvs5-6/msi/CMakeFiles/CMakeError.log".
[username#MSI-Linux msi]$
I would be thankful if anyone could answer one of these questions:
- How can I cross-compile a program that uses OpenCV commands
- Why is there an "undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)#GLIBCXX_3.4.20'" and a "The C compiler ... is not able to compile a simple test program."
- Would it be bad or REALLY bad style if I add a something like this in the program:
namespace std
{
void __throw_out_of_range_fmt(char const*, ...)
{
std::cout << "throw out of range error\n";
}
}
Heres my ~/pidev/pi-toolchain.cmake:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(DEVROOT $ENV{HOME}/pidev)
SET(PIROOT ${DEVROOT}/piroot)
SET(PITOOLS ${DEVROOT}/pitools)
SET(TOOLROOT ${PITOOLS}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64)
# specify the cross compiler
SET(CMAKE_C_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_SYSROOT ${PIROOT})
SET(CMAKE_FIND_ROOT_PATH ${PIROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(FLAGS "-Wl,-rpath-link,${PIROOT}/opt/vc/lib -Wl,-rpath-link,${PIROOT}/lib/arm-linux-gnueabihf -Wl,-rpath-link,${PIROOT}/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,${PIROOT}/usr/local/lib")
UNSET(CMAKE_C_FLAGS CACHE)
UNSET(CMAKE_CXX_FLAGS CACHE)
SET(CMAKE_CXX_FLAGS ${FLAGS} CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS ${FLAGS} CACHE STRING "" FORCE)
The "cannot find crt1.o: No such file or directory"-error is a known problem with the "arm-rpi-4.9.3-linux-gnueabihf"-toolchain, see 4.9 toolchain issue #50.
The "`std::__throw_out_of_range_fmt(char const*, ...)#GLIBCXX_3.4.20'"-error is related to gcc 4.8, see std::__throw_out_of_range_fmt(char const*, …)#GLIBCXX_3.4.20'. I'm not quite sure why this happens to you, since I was able to build opencv with the "gcc-linaro-arm-linux-gnueabihf-raspbian-x64"-toolchain.
Maybe you have some luck with the way I did it: How do I cross compile OpenCV for the Raspberry Pi with additional modules (highgui…)
Example CMakeLists.txt
project(Test)
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 11)
aux_source_directory(. SRC_LIST)
find_package(OpenCV REQUIRED)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
Invoke cmake like this:
cmake -D CMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE -D PIROOT=$MOUNT_DIR -D TOOLROOT=$TOOLCHAIN ..
Related
I recently changed to Linux Mint Debian Edition and cannot include boost to Clion using cmake. Yesterday I tried every option I could find, including on stackoverflow, but nothing has worked yet.
Boost has been installed using: sudo apt -y install libboost-filesystem-dev
This is a version I found in this thread: How to include external library (boost) into CLion C++ project with CMake?
which supposedly worked, but it didn't.
cmake_minimum_required(VERSION 3.22)
project(boost_project)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(boost_project main.cpp)
if(Boost_FOUND)
target_link_libraries(boost_project ${Boost_LIBRARIES})
endif()
The Cmake output message is:
CMake Error at /app/extra/clion/bin/cmake/linux/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR system filesystem)
I've gone through dozens of threads but so far nothing has worked. Has anyone suggestions of what's wrong?
EDIT:
So I've de-installed Clion and re-installed it with snap, since I read in another thread that it was an issue with installing Clion through the software center. Now I can include boost with no problem, but building it reveals the compiler still doesn't like using it.
#include <iostream>
#include "boost/asio.hpp"
boost::asio::io_service io_s;
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
: && /usr/bin/c++ -g CMakeFiles/BoostTest.dir/main.cpp.o -o BoostTest && :
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_event::posix_event()': /usr/include/boost/asio/detail/impl/posix_event.ipp:42: undefined reference to pthread_condattr_setclock'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_thread::~posix_thread()': /usr/include/boost/asio/detail/impl/posix_thread.ipp:35: undefined reference to pthread_detach'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_thread::join()': /usr/include/boost/asio/detail/impl/posix_thread.ipp:42: undefined reference to pthread_join'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)': /usr/include/boost/asio/detail/impl/posix_thread.ipp:59: undefined reference to pthread_create'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_signal_blocker::posix_signal_blocker()': /usr/include/boost/asio/detail/posix_signal_blocker.hpp:43: undefined reference to pthread_sigmask'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()': /usr/include/boost/asio/detail/posix_signal_blocker.hpp:50: undefined reference to pthread_sigmask'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The solution to the first problem, cmake not finding boost, had nothing to do with cmake but Clion. Installing Clion with flatpak can apparently cause this error. To fix it I just needed to de-install Clion and re-install it with snap.
The second issue was cmake not finding several thread related includes. For that cmake needed
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
to be added. I found this solution in these threads:
linking errors for boost for visual studio linux project
Undefined reference to pthread_create in Linux
The complete and working cmake looks like this now:
cmake_minimum_required(VERSION 3.22)
project(boost_project)
message(STATUS "start running cmake...")
find_package(Boost COMPONENTS system)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
set(CMAKE_CXX_STANDARD 14)
add_executable(boost_project main.cpp)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
target_link_libraries(boost_project ${Boost_LIBRARIES})
i want to use virtual camera on linux with obs studio. i see this package https://github.com/CatxFish/obs-v4l2sink
i ran
sudo apt install qtbase5-dev
sudo apt install libobs-dev
git clone --recursive https://github.com/obsproject/obs-studio.git
git clone https://github.com/CatxFish/obs-v4l2sink.git cd obs-v4l2sink mkdir build && cd build cmake -DLIBOBS_INCLUDE_DIR="../../obs-studio/libobs" -DCMAKE_INSTALL_PREFIX=/usr ..
when i ran cmake -DLIBOBS_INCLUDE_DIR="../../obs-studio/libobs" -DCMAKE_INSTALL_PREFIX=/usr ..
i got error
`-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (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/arp/obs-v4l2sink/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_a18d3/fast && /usr/bin/make -f CMakeFiles/cmTC_a18d3.dir/build.make CMakeFiles/cmTC_a18d3.dir/build
make[1]: Entering directory '/home/arp/obs-v4l2sink/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_a18d3.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTC_a18d3.dir/testCCompiler.c.o -c /home/arp/obs-v4l2sink/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_a18d3
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a18d3.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_a18d3.dir/testCCompiler.c.o -o cmTC_a18d3
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_a18d3.dir/build.make:87: cmTC_a18d3] Error 1
make[1]: Leaving directory '/home/arp/obs-v4l2sink/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_a18d3/fast] Error 2
CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project)
CMake Error at CMakeLists.txt:2 (project): No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred! See also "/home/arp/obs-v4l2sink/build/CMakeFiles/CMakeOutput.log". See also "/home/arp/obs-v4l2sink/build/CMakeFiles/CMakeError.log".
i have seen some articles. but nothing changes.
anyone can help me?
I'm trying to create a dynamic library on Windows but I have a problem with Boost, I keep getting this error
1>LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_66.lib'
The thing is, according to this http://www.boost.org/doc/libs/1_66_0/more/getting_started/windows.html#header-only-libraries the two librairies are supposed to be header only header only
the cmake i'm using
cmake_minimum_required(VERSION 3.8)
project(mod_autoindex)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
SET (BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_66_0")
SET (BOOST_INCLUDEDIR "${BOOST_ROOT}/boost")
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
include_directories(${Boost_INCLUDE_DIR})
include_directories("../../include")
include_directories("../../include/sza")
include_directories("./include")
file(GLOB_RECURSE CPP_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hpp)
set(SOURCE_FILES ${CPP_SRCS} ${HEADERS})
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME})
Any idea of wrang am i doing wrong ?
cmake output for cmake . -G "Visual Studio 15 2017 Win64"
-- The C compiler identification is MSVC 19.11.25547.0
-- The CXX compiler identification is MSVC 19.11.25547.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- filesystem
-- system
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/theo/Desktop/cpp_zia/modules/mod_autoindex
So the solution generation seems to work fine, but after that, when I try to build MSBuild mod_autoindex.sln i get the following error
LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-1_65_1.lib' [C:\Users\theo\
Desktop\cpp_zia\modules\mod_autoindex\mod_autoindex.vcxproj]
#update here is my current cmake
cmake_minimum_required(VERSION 3.8)
project(mod_autoindex)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")
set(BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_65_1")
set(Boost_ADDITIONAL_VERSIONS 1.65.1)
set(BOOST_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS filesystem REQUIRED)
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
include_directories(${Boost_INCLUDE_DIR})
include_directories("../../include")
include_directories("../../include/sza")
include_directories("./include")
file(GLOB_RECURSE CPP_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hpp)
MESSAGE( STATUS "BOOST libraries: " ${Boost_LIBRARIES} )
add_library(${PROJECT_NAME} SHARED ${CPP_SRCS} ${HEADERS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
Many Boost libraries indeed are header only, but filesystem is not.
Instead of doing things manually I would use the CMake way of adding library dependencies by using the appropriate find_package module:
set(BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_65_1")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
...
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
Boost binaries for your compiler can be downloaded at https://sourceforge.net/projects/boost/files/boost-binaries/
If CMake does not find your Boost installation (CMake 3.10.2 versions FindBoost.cmake module does know about versions up to Boost 1.65.1) you can try to add before the find_package call
set(Boost_ADDITIONAL_VERSIONS 1.66.0)
but
Boost changed its naming scheme starting from version 1.66.0. CMake up to version 3.10.2 does not know this scheme and therefore cannot handle it. You need to use Boost 1.65.1 instead.
Edit according to the comment by #ComicSansMS:
Do not hardcode the Boost path to your CMakeLists.txt instead set it per environment variable BOOST_ROOT or provide it as argument to your CMake call.
So go to your project path (the path where your CMakeLists.txt is stored)
mkdir build
cd build
and either do
set BOOST_ROOT=C:\Program Files (x86)\boost\boost_1_65_1
cmake .. -G "Visual Studio 15 2017"
or call
cmake .. -G "Visual Studio 15 2017" -DBOOST_ROOT="C:\Program Files (x86)\boost\boost_1_65_1"
Later you can use the buildmode of CMake to build your entire project
cmake --build . --target ALL_BUILD --config Release -- /nologo /verbosity:minimal /maxcpucount
I am trying to get a Fortran 90 program to compile under Windows. I have already successfully done so under Linux.
I am using the 'Babun' windows shell, which is basically a wrapper for cygwin: https://github.com/babun/babun
When I try and run cmake, I get the following:
-- The Fortran compiler identification is GNU
-- Check for working Fortran compiler: /usr/bin/gfortran.exe
-- Check for working Fortran compiler: /usr/bin/gfortran.exe -- broken
CMake Error at /usr/share/cmake-2.8.9/Modules/CMakeTestFortranCompiler.cmake:40 (MESSAGE):
The Fortran compiler "/usr/bin/gfortran.exe" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: /cygdrive/d/Users/bob/code/vasa/build/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make.exe "cmTryCompileExec674739544/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec674739544.dir/build.make
CMakeFiles/cmTryCompileExec674739544.dir/build
make[1]: Entering directory
'/cygdrive/d/Users/bob/code/vasa/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report
/cygdrive/d/Users/bob/code/vasa/build/CMakeFiles/CMakeTmp/CMakeFiles
1
Building Fortran object
CMakeFiles/cmTryCompileExec674739544.dir/testFortranCompiler.f.o
/usr/bin/gfortran.exe -c
/cygdrive/d/Users/bob/code/vasa/build/CMakeFiles/CMakeTmp/testFortranCompiler.f
-o CMakeFiles/cmTryCompileExec674739544.dir/testFortranCompiler.f.o
Linking Fortran executable cmTryCompileExec674739544.exe
/usr/bin/cmake.exe -E cmake_link_script
CMakeFiles/cmTryCompileExec674739544.dir/link.txt --verbose=1
/usr/bin/gfortran.exe -Wl,--enable-auto-import
CMakeFiles/cmTryCompileExec674739544.dir/testFortranCompiler.f.o -o
cmTryCompileExec674739544.exe
-Wl,--out-implib,libcmTryCompileExec674739544.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
gfortran: fatal error: -fuse-linker-plugin, but cyglto_plugin.dll not found
compilation terminated.
CMakeFiles/cmTryCompileExec674739544.dir/build.make:83: recipe for target
'cmTryCompileExec674739544.exe' failed
make[1]: *** [cmTryCompileExec674739544.exe] Error 1
make[1]: Leaving directory
'/cygdrive/d/Users/bob/code/vasa/build/CMakeFiles/CMakeTmp'
Makefile:117: recipe for target 'cmTryCompileExec674739544/fast' failed
make: *** [cmTryCompileExec674739544/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:9 (enable_language)
What package does this cyglto_plugin.dll belong to? What dependencies am I missing?
Thanks!
I trying to get a cmake build system working on linux. The project contains a bunch of executables and two libraries. One of the executables is first built as a library, then that library is linked with the object file containing the man subroutine. This was done because the rest of the executables depend on that library. The tricky part is that the main subroutine is defined inside a module that the rest of sources depend on so this needs to be compiled before the rest of the sources. The effect is that the main subroutine gets added to the resulting library. This seems to work fine on Mac OS X but, the linking state fails on Linux.
The cmake file for the failing part looks like
cmake_minimum_required (VERSION 2.8)
# Create an empty variable to hold all the source files.
set (vmec_sources "")
# Add subdirectory for all the sources.
add_subdirectory (Sources)
add_library (vmec STATIC ${vmec_sources})
add_dependencies (vmec stell)
# Define an executable and link all libraries.
add_executable (xvmec ${CMAKE_CURRENT_SOURCE_DIR}/Sources/General/vmec_main.f)
add_dependencies (xvmec vmec)
target_link_libraries (xvmec vmec stell)
if ((NOT ${NETCDF_C} STREQUAL "") AND (NOT ${NETCDF_F} STREQUAL ""))
target_link_libraries (xvmec ${NETCDF_C} ${NETCDF_F})
endif ()
When running cmake, everything configures fine and generates a make file when I run make Mac OS X everything works fine. When I run make on Linux it fails.
The output from the make VERBOSE=1 On Linux produces
Linking Fortran executable ../build/bin/xvmec
cd /home/user/reconstruction/VMEC2000 && /usr/bin/cmake -E cmake_link_script CMakeFiles/xvmec.dir/link.txt --verbose=1
/usr/bin/gfortran -cpp -D NETCDF -I /usr/include CMakeFiles/xvmec.dir/Sources/General/vmec_main.f.o -o ../build/bin/xvmec -rdynamic ../build/lib/libvmec.a ../build/lib/libstell.a /usr/lib/libnetcdf.so /usr/lib/libnetcdff.so
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortranbegin.a(fmain.o): In function `main':
(.text+0x26): undefined reference to `MAIN__'
collect2: ld returned 1 exit status
make[2]: *** [build/bin/xvmec] Error 1
make[2]: Leaving directory `/home/user/reconstruction'
make[1]: *** [VMEC2000/CMakeFiles/xvmec.dir/all] Error 2
make[1]: Leaving directory `/home/user/reconstruction'
make: *** [all] Error 2
On Mac OS X, I get
Linking Fortran executable ../build/bin/xvmec
cd /Users/user/repo/trunk/VMEC2000 && "/Applications/CMake 2.8-8.app/Contents/bin/cmake" -E cmake_link_script CMakeFiles/xvmec.dir/link.txt --verbose=1
/usr/local/bin/gfortran -framework Accelerate -cpp -D DARWIN -D NETCDF -I /Users/user/NetCDF/include -O3 -ftree-vectorize -m64 -march=native -fomit-frame-pointer -falign-functions -mfpmath=sse CMakeFiles/xvmec.dir/Sources/General/vmec_main.f.o -o ../build/bin/xvmec ../build/lib/libvmec.a ../build/lib/libstell.a /Users/user/NetCDF/lib/libnetcdf.dylib /Users/user/NetCDF/lib/libnetcdff.dylib
"/Applications/CMake 2.8-8.app/Contents/bin/cmake" -E cmake_progress_report /Users/user/repo/trunk/CMakeFiles 100
[100%] Built target xvmec
The link line looks like it is linking all the same stuff in the correct order so I don't understand why this is failing on Linux.
Turns out I had the wrong file listed as containing the main method. It seems that later versions of gfortran can link 'MAIN__' from a inside a library while gfortran-4.4 cannot.