LibTorch with CMake via Eclipse in Windows:Terminated exit value 390 - c++

I used cmake4eclipse to build torch C++ version 1.0 stable in Windows 10. Basically, I have the following CMakeLists.txt to build the mnist example:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(mnist)
set(CMAKE_PREFIX_PATH "C:/rl/libtorch/share/cmake/Torch")
set(Torch_DIR "C:/rl/libtorch")
find_package(Torch REQUIRED)
option(DOWNLOAD_MNIST "Download the MNIST dataset from the internet" ON)
if (DOWNLOAD_MNIST)
message(STATUS "Downloading MNIST dataset")
execute_process(
COMMAND python ${CMAKE_CURRENT_LIST_DIR}/download_mnist.py
-d ${CMAKE_BINARY_DIR}/data
ERROR_VARIABLE DOWNLOAD_ERROR)
if (DOWNLOAD_ERROR)
message(FATAL_ERROR "Error downloading MNIST dataset: ${DOWNLOAD_ERROR}")
endif()
endif()
set(CMAKE_BUILD_TYPE Debug)
add_executable(mnist mnist.cpp)
target_compile_features(mnist PUBLIC cxx_range_for)
set_property(TARGET mnist PROPERTY CXX_STANDARD 14)
target_link_libraries(mnist ${TORCH_LIBRARIES})
Then, I load this along with the mnist.cpp and download_mnist.py files in a folder and start a project in eclipse IDE for C/C++, version 2018-09 (4.9.0). In project_properties->C/C++ Build->Tool Chain Editor, I set CMake Builder (GNU Make) and select MinGW GCC. Then, in project_properties->C/C++ General->Preprocessor Include Paths Macros etc.->Providers I select CMAKE_EXPORT_COMPILE_COMMANDS Parser [Shared] and move it up, as it is explained here.
Then, I can compile the mnist project without any error. But, when I run it get <terminated> (exit value 390) a.exe [some address]. I tried to debug this code to find out the problem, but I cannot see the debug screen, and instead I get:
Running the debug mode to the end results in a same error.
I can run mnist.cpp in Linux without any problem, though I use cmake -G "Eclipse CDT4 - Unix Makefiles" ./ to create a eclipse project. I did not know how I can use cmake -G "Eclipse CDT4 - Unix Makefiles" ./ in Windows and I used cmake4eclipse and I believe I have missed a step in dealing with the CMakeLists.txt file in windows. I appreciate any help or comments.
Thanks,
Afshin

I asked same question in torch git, and today I got an answer for that. It seems that for now, we will not be able to run Libtorch through Eclipse with MinGw. Here is the answer that I got from torch git page:
"I don't think you could build that with MinGW because the code is written in c++ and MinGW is not abi-compatible with MSVC. So I think you may need to compile with MSVC. And also in MSVC, the configuration debug and release could not be mixed. So you will have to choose Release as we only provide library with the Release configuration."
See more details in:
https://github.com/pytorch/pytorch/issues/15711

Related

AUTOMOC set to true makes fail cmake build

I'm at the very first day of Qt + Cmake and Conan, trying to make things work. I'm not using qmake because I'll integrate everything into a bigger project using cmake.
By following QT's tutorial, I figured out that I need to compile QT macros, and for that there's a useful AUTOMOC CMake property, as suggested here.
The point is that it's making me fail cmake builds.
My conanfile.txt:
[requires]
qt/5.15.2
[generators]
cmake
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(qttest)
set(CMAKE_CXX_STANDARD 20)
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC TRUE)
set (PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
with the following output:
CMake Warning (dev) in CMakeLists.txt:
AUTOGEN: No valid Qt version found for target qttest. AUTOMOC disabled.
Consider adding:
find_package(Qt<QTVERSION> COMPONENTS Core)
to your CMakeLists.txt file.
This warning is for project developers. Use -Wno-dev to suppress it.
ouch, but adding the find doesn't make things better:
CMake Warning at CMakeLists.txt:6 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Actually the project compiles, Qt is there in its conan dir:
matteo#MacBook-Pro-de-matteo 96a68a791abfc7a246f2bc28aa2f6fc210be0f9f % cd ~/.conan/data/qt
matteo#MacBook-Pro-de-matteo qt % ls
5.15.2 6.2.2
matteo#MacBook-Pro-de-matteo qt %
how could I enable it, or make things easier to compile it along with cmake?
You need to tell CMake, where to find Qt.
So, as CMake suggests by itself:
find_package(Qt5 COMPONENTS Core)
for the most basic stuff, you might want to add some of the other components later.
Depending on the system you are working on and your Qt installation, you need to tell CMake where to search for the package configuration files (second error message). CMake has some default directories, where it looks for these files, but obviously, there is none. On Linux, this can be solved by installing Qt with a package manager (this will install the CMake config files to one of the Qt default locations). If you are on Windows or if you installed Qt to a different location, this can be solved by providing the path with the PREFIX_PATH-variable.
cmake -B $BUILD_DIR -S $SOURCE_DIR -DCMAKE_PREFIX_PATH=$QT_INSTALL_PATH/5.15.2/$ARCHITECTURE $OTHER_OPTIONS
(You can have different versions installed in the same installation path, that's why Qt adds an other folder with the version number. And you can have different compilers/architectures. On Windows for example, you might have a mingw73_32 and a msvc2017 folder to choose.)
As already mentioned in the comments, a project is no CMake target. CMake targets are either libraries (add_library), executables (add_executable) or custom targets (add_custom_target); the project is not. If you want to set the AUTOMOC property target wise, that's ok and even suggested by CMake, but you can also set it globally by using:
set(CMAKE_AUTOMOC ON)

How do I designate which compiler is called when running cmake + make?

I'm trying to compile a c++ project with cmake and make on OSX but it looks like make is using CXX or clang when I want to use g++ (gcc) so I can follow the answer here to tell the compiler where to find header files (#includes) for tbb used in the project: Need help getting intel TBB working?
brew list shows that I have up to date versions of cmake, make, gcc, and swig installed.
Here's the project I'm trying to compile for reference: https://github.com/nmoehrle/mvs-texturing/blob/master/README.md
I came across this related answer and was able to get the project working! MacOS, CMake and OpenMP
I updated the cmakelists.txt with the following commands to set llvm as the compiler. Note, I needed to update the llvm file path to match the version number I have installed.
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/5.0.1/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/5.0.1/include")
Then I was also having issues with OpenMP so I added this section to configure the OpenMP include directories and link directories.
if (OPENMP_FOUND)
include_directories("${OPENMP_INCLUDES}")
link_directories("${OPENMP_LIBRARIES}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif(OPENMP_FOUND)
I'm a novice dev and wish I had more insight into why this worked but it fixed my issues!

How to use SFML libraries with Clion on Windows10

i'm trying to use SFML's library with CLion for a school project. I'm still not confident with programming and i am new to Clion.
After having download the library from SFML official site i read some tutorials, but i am a bit confused:
https://www.sfml-dev.org/tutorials/2.4/
Infact in the Getting Started section there are two voice that concern me: "Compiling with Cmake" and "..Code::Blocks (MinGW).
Well i tryed both but with no results, then i landed here.
I saw a topic that helped a bit configure SFML for clion (windows)
so i tried to follow the steps suggested.
The library is in C:\SFML-2.4.2
I copied FindSFML.cmake in SFMLProjects, located in C:\Users\Ludovico\ (the same path of the folder ClionProjects)
Then i gave it a try
cmake_minimum_required(VERSION 3.6)
project(provaSfml)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(provaSfml ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/SFMLProjects")
link_directories(C:/SFML-2.4.2/bin)
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(provaSfml ${SFML_LIBRARIES})
endif ()
These are the error messages
"C:\Program Files (x86)\JetBrains\CLion 2016.3.2\bin\cmake\bin\cmake.exe" - DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Ludovico\CLionProjects\provaSfml
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SFML", but
CMake did not find one.
Could not find a package configuration file provided by "SFML" with any of
the following names:
SFMLConfig.cmake
sfml-config.cmake
Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
"SFML_DIR" to a directory containing one of the above files. If "SFML"
provides a separate development package or SDK, be sure it has been
installed.
I'm thinking i did some mistakes even in the organization of folder...
can someone tell me some advice in order to clean the mess i have in my head?
What can i do to fix these problems?

Include soci in cmake on windows

I have a HelloWorld project in JetBrains CLion and set up boost so I can build it fine.
I've managed to build soci using cmake and make with mingw outside the HelloWorld project.
For boost I used:
include(FindBoost)
find_package(Boost 1.55.0 COMPONENTS system filesystem)
How do I include the soci library in my cmake? Is there a similar method for including soci? I don't know where to start?
UPDATE
A bit further I think.
I added the following to my cmake options:
-D CMAKE_MODULE_PATH=D:\Development\Tools\lib\soci-3.2.2\cmake\modules
and this to my CMakeLists.txt:
find_package(Soci)
if(${SOCI_FOUND})
target_link_libraries(HelloWorld ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN})
else()
message(WARNING "SOCI NOT FOUND")
endif()
I still get SOCI NOT FOUND though but at least the soci variables turns up in the cmake cache.
This is obviously very late, but it worked for me:
target_link_libraries(HelloWorld soci_core soci_mysql)
I must admit I shame for my country mates because they provide so crapy CMakeLists.txt for SOCI lib. In order to mitigate they bad works, I wrote following intsturctions how to use SOCI in CMake based projects. I do it on Linux KDE Neon 5.16.5 (based on: Ubuntu 18.04 LTS), but on Windows probably you have only fix paths. This probalby will work. I am not 100% sure because I just start my project within I want to use SOCI.
This is obviously very late, but it probably works:
I build and install soci like this:
cmake "/home/szyk/!-EnergoKod/!-Libs/3rdparty/soci" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Release
cmake "/home/szyk/!-EnergoKod/!-Libs/3rdparty/soci" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
sudo make install
I add to my project CMakeLists.txt:
set(SOCI_SOURCE_DIR "$ENV{HOME}/!-EnergoKod/!-Libs/3rdparty/soci")
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
find_package(Soci)
list(APPEND LIBS ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN})
# Link libraries
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
That is generates good looking output:
Soci found: Looking for plugins
* Plugin mysql not found.
* Plugin odbc not found.
* Plugin postgresql not found.
* Plugin sqlite3 found /usr/local/lib/x86_64-linux-gnu/libsoci_sqlite3.so.
Found Soci: /usr/local/include/soci

How to build google's C++ libphonenumber library for Win32

Some developers on our team are using the Java and C# versions of libphonenumber, a normalization library for international phone numbers.
They claim it is wonderful/magical/etc.
Unfortunately, being a Win32 C++ developer, my simple mind can't quite grasp all the wonder and magic of the CMake, boost, and host of other libraries and I can't build the library at all.
Can someone provide some hints ot tips or URLs to help point me in the right direction so that we can build this project and make use of it?
The current stumbling block is when trying to run CMake (following the instructions in the very short readme) I get the following error message:
> -- Could NOT find Boost
> -- Configuring incomplete, errors occurred!
I thought I set BOOST_ROOT correctly, but apparently either I set it wrong or I am missing other env vars.
How can I build this library?
We use VS 2008, but I also have VS 2010 on my machine. I would be happy to get a build with either one.
Your CMake may be outdated wrt to the Boost version you installed. Check the file FindBoost.cmake located in the CMake Modules directory. It must contain a section like this:
set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
"1.46.1" "1.47" "1.47.0"
"1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42"
"1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37"
"1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0"
"1.34" "1.33.1" "1.33.0" "1.33")
You can try to pass BOOST_INCLUDEDIR and BOOST_LIBRARYDIR to the compiler; this way you can totally bypass the cmake module search.
Change Boost_ADDITIONAL_VERSIONS in FindBoost.cmake, step that you've already done
Change the CMakeLists.txt from \libphonenumber\cpp, change the line find_package (Boost 1.40.0 COMPONENTS thread)
into
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF) //since CMake 2.8.3
find_package (Boost 1.47.0 COMPONENTS thread)
3. Run mkdir build in \libphonenumber\cpp, cd build
4. Run cmake -G "your generator" -DBOOST_ROOT="you_path_to_boost_147_0 folder,", ex: cmake -G "Visual Studio 10" ../ -DBOOST_ROOT="E:\libphonenumber\cpp\3rdparty"
Try to compile it using cygwin, it is like a standard UNIX build environment but running on Windows. It usually is a lot easier to compile open source libraries using it than using Visual Studio.