1

I'm interested in CMake, so decided to learn about it. I followed the CMake Tutorial until the point where it states "That is all there is to it. At this point you should be able to build the tutorial", so I thought, let's try it!

Alas, it seems it wasn't all so simple. I initially attempted to run cmake -A "Unix Makefiles" after consulting cmake --help, but no luck there either. Rather, it gives me the following:

CMake Error at CMakeLists.txt:2 (project): Generator Unix Makefiles does not support platform specification, but platform Unix Makefiles was specified. CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage 

I began searching around on the Internet and found this, but it gave me the exact same error. Other answers I found seemed to be Windows-related, but myself I'm on Fedora 29.

I want to generate a makefile using CMake, any suggestions? (I have gcc and g++ installed, by the way)

8
  • What happens if you omit the -A "Unix Makefiles" argument? Do you get a different error message? Commented Feb 17, 2019 at 10:06
  • Unix Makefiles is a generator, which is specified with -G option. Why do you use -A option? (Exactly this option sets platform specification). Commented Feb 17, 2019 at 10:12
  • @Tsyvarev It was a misunderstanding, I tried with -G later (as suggested by the thing I linked later in the answer) Commented Feb 17, 2019 at 10:22
  • @FlorianWeimer assuming I specify the folder (otherwise it shows me how to use cmake), it gives me the exact same error yet again. Commented Feb 17, 2019 at 10:24
  • "I tried with -G later" - Describe this attempt: what exact command line have you tried, and exact error message you got. You definitely shouldn't got an error about "platform specification", as you don't specify -A in that case. Commented Feb 17, 2019 at 10:51

2 Answers 2

3

On Fedora, generating Unix Makefiles (e.g. Makefile, which GNU Make will be able to use) is probably the default. In general, don't specify a generator: then you'll get what makes the most sense on your installed OS. Some OS do pick a different default: FreeBSD uses Ninja, for instance.

When running CMake you may need to specify the source-directory. If CMake has been run before, successfully, you can leave off the directory. When there are no other options or arguments to CMake, you'll need to give the directory.

If you've copy-pasted the CMakeLists and C++ files from the tutorial page, this will create whatever build-system comes from the default generator:

 cmake . 

Do note that if you don't give CMake any arguments at all, then it gives you a usage string. That's why there's that . there, to build from the current directory. If you want to specify a particular generator,

 cmake -G "Unix Makefiles" . 

If you are building in a separate directory (generally a good idea)

 cmake /path/to/the/sources 

Your original error message, by the way, tells you that CMake is, by default, using the generator Unix Makefiles, which doesn't support setting a platform. The no-arguments-at-all behavior seems to have tripped you up afterwards.

Sign up to request clarification or add additional context in comments.

1 Comment

Great answer, very helpful, but I can't quite accept this answer since it wasn't the solution to my problem. :(
1

After a discussion in the comments, I realised the issue was that I had done it wrong from the start. The solution ultimately was to remove all CMake-related files (except for CMakeLists.txt and do it all over again, this time running cmake .. on its own (without any arguments) from a subdirectory.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.