Creating Eclipse CDT using CMake on Windows - eclipse

I am trying to create a simple helloworld Eclipse CDT project using the CMake GUI. The CMake file looks like this:
cmake_minimum_required(VERSION "3.11.1")
project("HelloWorld")
add_executable("HelloWorldMain" "Main.cpp")
install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "Main.cpp" DESTINATION src)
The only c/c++ compiler I have is MSVC so I set that as the CMAKE_CXX_COMPILER but I get an error when configuring as shown here:
I know this file exists, but how do I get it to find it?

I ended up not using the GUI. Instead I used the VS x64 Native Tools Command Prompt then ran the cmake command:
cmake -G "Eclipse CDT4 - NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j8 ../

Related

cmake tools does not do same as executing cmake manually

I am developing C/C++ with Visual Studio Code using cmake and so CMake Tools extension of Visual Studio Code.
When I run cmake command manually (from build dir, just doing cmake ..), cmake configuration works but when I use CMake Tools, it fails.
I have looked at traces and the failure of CMake Tools is because of this difference:
Manually:
set(CMAKE_C_COMPILER_ARG1 -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/mydev/1.1.2/sysroots/cortexa7hf-vfp-neon-mydev-linux-gnueabi CACHE STRING Arguments to C compiler )
CMake Tools:
set(CMAKE_C_COMPILER_ARG1 /opt/mydev/1.1.2/sysroots/i686-mydevsdk-linux/usr/bin/arm-mydev-linux-gnueabi/arm-mydev-linux-gnueabi-gcc )
If I explicitly give this argument to CMake Tools, okay, it would work, but, why do I have to do that?
Why cmake just works (getting CMAKE_C_COMPILER_ARG1 from exported CC environment variable) but CMake Tools does not? If it would just execute cmake, it would work, but apparently it does not do that.
So, what is the thing that makes CMake Tools set CMAKE_C_COMPILER_ARG1 wrongly?
Is there anyway to make CMake Tools just work as cmake?

How do you change the cmake generator in Eclipse?

For some reason it forces -G Ninja when I try to build within eclipse. I would prefer Eclipse just not specify the -G option to cmake, but I can't figure out how to configure Eclipse to do that.
For exampe, this in my console window:
Building in: /home/bgass/eclipse-workspace/scomlib/build/default
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON /home/bgass/eclipse-workspace/scomlib
CMake Error: Error: generator : Ninja
Does not match the generator used previously: Unix Makefiles
Either remove the CMakeCache.txt file or choose a different binary directory.
cmake --build . -- -v
GNU Make 4.2.1
Built for x86_64-redhat-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Build complete (0 errors, 0 warnings): /home/bgass/eclipse-workspace/scomlib/build/default
In a terminal it works just fine without the generator specified.
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON /home/bgass/eclipse-workspace/scomlib
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bgass/eclipse-workspace/scomlib/build/default
I always execute cmake outside eclipse and open the generated eclipse project in Eclipse.
use -G "Eclipse CDT4 - Unix Makefiles" to specify Eclipse as the generator.
Following are the full set of Eclipse generators.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Type in cmake --help to see what generators are supported by your specific cmake version.

eclipse mingw cmake path

I get the following when trying to build a makefile in eclipse neon:
Error: Program "make" not found in PATH
followed by my full path, which begins
Error: Program "make" not found in PATH PATH=[C:/Program
Files/Java/jre1.8.0_141/bin/server;C:/Program
Files/Java/jre1.8.0_141/bin;C:/Program
Files/Java/jre1.8.0_141/lib/amd64;C:\msys64\mingw64\bin;
(it continues after this...)
However, cmake is definitely present in C:\msys64\mingw64\bin.
How can I fix this so eclipse is using the cmake.exe?
Eclipse is looking for make program not cmake. To install make on MSYS2 use the command pacman -S make. CMake is a build system generator that creates Makefiles for you. But it does not build the Makefiles itself it uses an installed make for that.

CMake android NDK project in Windows with toolchain file

I´m trying to run CMake from a Windows machine to generate an Android NDK project with a specific toolchain file. There is a tutorial on how to generate Android projects with CMake by google. Anyway I need the project to be an Eclipse project because its the only way to import it into ADT bundle. Now on the CMake UI there are more option for that:
Eclipse CDT4 - MinGW
Eclipse CDT4 - NMake
Eclipse CDT4 - Unix
Eclipse CDT4 - Ninja
The 2nd one (Eclipse CDT - NMake) is the right choice for this configuration, when i start CMake then it fail generating throwing following error:
CMake Warning at CMakeLists.txt:3 (project):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
any ideas?
You need to initialize the environment with vcsvarsall.bat(shipped with Visual Studio).
E.g. for Microsoft Visual Studio 2010 - run this "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" in the same console instance where you intend to execute your cmake command:
...>"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
Or find in Start Menu "Visual Studio Command Prompt (2010)" ("Developer Command Prompt for VS20XX" for recent versions of VS) which does this initialization for you and run cmake there.

The program can't start because cygwin1.dll is missing... in Eclipse CDT

I've had Eclipse for Java on my computer for a few years, and decided to install the CDT and learn C. I installed both MinGW and Cygwin and the CDT detects and tries to use them when I make a new project.
I choose File > New C++ Project and choose Hello World C++ Project and the CygwinGCC toolchain. I name the project "asdf" and hit "Build Debug" in the toolbar. The compiler completes without error. I hit Run and nothing happens.
Browsing to the project directory manually and running asdf.exe gives me an error saying:
"The program can't start because cygwin1.dll is missing from your computer. Try reinstalling the program to fix this problem."
The same thing happens using MinGW, only a different dll is missing.
What do I need to do to have a usable .exe?
(I'm running Windows 7 x64 and the newest version of Eclipse and the CDT.)
EDIT:
The compiler output is as follows:
**** Build of configuration Debug for project asdf ****
make all
Building file: ../src/asdf.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/asdf.d" -MT"src/asdf.d" -o"src/asdf.o" "../src/asdf.cpp"
cygwin warning:
MS-DOS style path detected: C:\Users\Shawn\Dropbox\eclipse\asdf\Debug
Preferred POSIX equivalent is: /cygdrive/c/Users/Shawn/Dropbox/eclipse/asdf/Debug
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building: ../src/asdf.cpp
Building target: asdf.exe
Invoking: Cygwin C++ Linker
g++ -o"asdf.exe" ./src/asdf.o
Finished building target: asdf.exe
This error message means that Windows isn't able to find "cygwin1.dll". The Programs that the Cygwin gcc create depend on this DLL. The file is part of cygwin , so most likely it's located in C:\cygwin\bin. To fix the problem all you have to do is add C:\cygwin\bin (or the location where cygwin1.dll can be found) to your system path. Alternatively you can copy cygwin1.dll into your Windows directory.
There is a nice tool called DependencyWalker that you can download from http://www.dependencywalker.com . You can use it to check dependencies of executables, so if you inspect your generated program it tells you which dependencies are missing and which are resolved.
You can compile with either Cygwin's g++ or MinGW (via stand-alone or using Cygwin package). However, in order to run it, you need to add the Cygwin1.dll (and others) PATH to the system Windows PATH, before any cygwin style paths.
Thus add: ;C:\cygwin64\bin to the end of your Windows system PATH variable.
Also, to compile for use in CMD or PowerShell, you may need to use:
x86_64-w64-mingw32-g++.exe -static -std=c++11 prog_name.cc -o prog_name.exe
(This invokes the cross-compiler, if installed.)
To add to this and save someone another google, just do this in cmd:
set PATH=%PATH%;C:\cygwin64\bin