exercism / cpp

Exercism exercises in C++.
https://exercism.org/tracks/cpp
MIT License
251 stars 205 forks source link

Cmake error :generator: Ninja #250

Closed parvpareek closed 5 years ago

parvpareek commented 5 years ago

I opened hello-world folder using visual studio's cmake in File>Open>Cmake. In the terminal i wrote -`

cmake -G "Visual Studio 15" -DBOOST_INCLUDEDIR:PATH=C:\lib\boost_1_66_0.

` It showed an error in the ide which was as follows -

Severity Code Description Project File Line Suppression State Error CMake Error: Error: generator : Ninja Does not match the generator used previously: Visual Studio 15 2017 Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory. c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\Avi-parv\CMakeBuilds\54b55018-480c-1b33-a81d-1f236c8d7337\install\x64-Debug (default)" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visualstudio\2017\professional\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "C:\Users\Avi-parv\Exercism\cpp\hello-world" returned with exit code: 1 CMake Error: Error: generator : Ninja Does not match the generator used previously: Visual Studio 15 2017 Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory. C:\Users\Avi-parv\Exercism\cpp\hello-world\Does not match the generator used previously

In the terminal this error was shown -

CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.12/Modules/FindBoost.cmake:2044 (message): Unable to find the requested Boost libraries.

Boost version: 1.66.0

Boost include path: C:/lib/boost_1_66_0

Could not find the following static Boost libraries:

      boost_unit_test_framework
      boost_date_time

No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost. Call Stack (most recent call first): CMakeLists.txt:14 (find_package)

-- Configuring incomplete, errors occurred! See also "C:/Users/Avi-parv/Exercism/cpp/hello-world/CMakeFiles/CMakeOutput.log".

C:\Users\Avi-parv\Exercism\cpp\hello-world>C:\lib\boost_1_66_0 'C:\lib\boost_1_66_0' is not recognized as an internal or external command, operable program or batch file.


Someone please help

KevinWMatthews commented 5 years ago

Hi @parvpareek,

Thanks for posting the error message. I don't have a Visual Studio setup myself, unfortunately, so it is very helpful.

We recently changed the CMake generator to Ninja. It looks like Visual Studio is complaining about this:

CMake Error: Error: generator : Ninja
Does not match the generator used previously

The error message suggests a solution:

Either remove the CMakeCache.txt file and
CMakeFiles directory or choose a different
binary directory.

Does Visual Studio provide a way to clear the CMake cache? That may be the easiest path forward. If so, please try it, re-run CMake, and post the output.

You could also try to find and manually remove:

There may be a second error related to finding Boost libraries, but we should probably fix the generator issue first.

parvpareek commented 5 years ago

Yes. I did manually remove cmakecache as suggested by the compiler. I even downloaded the folder once again but it still didnt work. I have already spent more than 7 hours trying to solve it

parvpareek commented 5 years ago

I had opened another issue in which I have mentioned everything in detail. https://github.com/exercism/cli/issues/839 Please check it out.

KevinWMatthews commented 5 years ago

Hi @parvpareek ,

Will do.

I looked more closely at the CMake generator changes that I mentioned previously - I don't think they can have an effect on your system. There's likely something else going on.

arcuru commented 5 years ago

@parvpareek Unfortunately you're hitting two known issues, both of which we're working on fixing.

  1. Visual Studio instructions. The ones we have are very out of date. With VS 2017 (which you have) it will handle CMake files for you, you do not need to run CMake yourself. See https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio
  2. Boost. We're getting rid of it precisely because it is a nightmare to use on many platforms. The core exercises I will be fixing today, but it will take me at least a month to finish all the rest of the exercises. Exercism will save the version of each exercise you initially download from the website, so you'll need to go on exercism.io to the Exercise page and click "Update exercise to the latest version" that will show up below the exercise description.

With a non-boost exercise all you need to do is:

  1. Download the exercise.
  2. Open Visual Studio 2017 or higher (With Visual C++ tools for CMake installed as described from the link).
  3. Open the exercise folder.
  4. Run "Build the solution." and the test will execute with the build, output going to the build window. Since the test runs during the build, VS will say it is a build failure if one of the tests fail, and the test failure messages will be in the build output window.

I tested that just now.

parvpareek commented 5 years ago

Thanks. That will be so easy. I can wait for 1 month. I am learning OpenGL for now. I don't, know what I would have done if it were not for this issue.

arcuru commented 5 years ago

Hi @parvpareek, more than half of the exercises are now in this new format, so feel free to start working on them. #253 lists all the exercises with the new versions that will work for you. The unchanged exercises are all later in the track, so unless you work very quickly you won't get to them until I port those over next weekend :)

I am still working on updating the documentation, but my description above should be able to get you started. Please let me know if you have issues using that.

parvpareek commented 5 years ago

@patricksjackson I still don't understand. How am I supposed to compile it? image image

parvpareek commented 5 years ago

image Cant build. image

Cant compile. Does it have something to do with this- image ?

arcuru commented 5 years ago

That's a boost error, you need to update to the latest version of the exercise.

  1. Delete the hello-world folder from your computer.
  2. Go to exercism.io and update the problem to the latest version.
    • Go to https://exercism.io/my/tracks/cpp
    • Click on the problem.
    • There should be a button at the bottom of the page called "Update this exercise to the latest version". If not try to continue anyways.
  3. Use the exercism cli to download the problem again.

The newly downloaded problem should be the new version without Boost (the hello_world_test.cpp file will have #include "test/catch.hpp" at the top.

parvpareek commented 5 years ago

I tried downloading the newer version thrice and it still includes boost. image What is up? .

KevinWMatthews commented 5 years ago

Hi @parvpareek , you're right - that's still the Boost file.

Patrick's instructions look accurate. Two thoughts:

Either of these could prevent the new test file from being downloaded properly.

Ezhidzee commented 1 year ago

I had a similar error. My CMakeList.txt looks like

cmake_minimum_required(VERSION 3.24)
project(your_target_name)

set(CMAKE_CXX_STANDARD 20)

add_executable(your_target_name main.cpp)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
        GIT_TAG 0817715923c9705e68994eb52ef9df3f6845beba)
FetchContent_MakeAvailable(cpr)

target_link_libraries(your_target_name PRIVATE cpr::cpr)

And the problem was that when I created a project in CLion, it set up a CMake profile like this screen

Then I ran cmake generation and everything worked fine, but after restarting ide i got this:

CMake Error: Error: generator : MinGW Makefiles Does not match the generator used previously: Ninja
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

So the solution was to recreate the project with the Ninja generator initially set in the CMake profile settings like this screen

DomenicoPL commented 11 months ago

I resolved it by looking for all the CMake (folders) and files (including the CMakeCache) and removed them. After that I ran it again and it worked