#Projects not compiling (Build error)

1 messages · Page 1 of 1 (latest)

warm brook
#

Im trying to compile my individual main classes, but its not allowing for some reason and its giving me a build error each time i try to run a class

mint sandalBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

warm brook
#

this is my directory

pale prism
#
  1. Main is not a class, it's a function
warm brook
#

what do you mean? what should i do then?

pale prism
#

Somehow, you need to specify that you want to build several different executables, one from each main.c file

#

Probably this can be done from settings somewhere

#

Or, by adding a target in some cmakelists file

naive horizon
#

You can have multiple targets in one cmake project

warm brook
#

how can i do that tho?

naive horizon
#

But the OP has a cmake file for each project.
That works too ofc.

#

I am confused, btw.
Are you working out how to build all targets?
Or just "butler"?

warm brook
#

each main class you see is a seperate project, which i want to compile individually

naive horizon
#

Okay, that clears that up.
And right now your "butler" project won't build.
Can you share the CMakeLists.txt?

warm brook
#

which one ?

naive horizon
#

This is pure guesswork so please excuse if I am off the mark...
I am guessing that you have configured CLion to use the "Unix Makefile" generator for your projects?

I say this, because

*** target pattern contains no `%'.  Stop.

Suggests a problem with the generated make files.
If true, then this is still surprising. I would expect this to have been tested thoroughly by the cmake community.

You could try switching to the "Ninja" generator.
But you may have to install Ninja-build first.

As you are on MACOS, I can provide no guidance other than confirming that Ninja is available on MACOS.
Requires Homebrew??

https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages

GitHub

a small build system with a focus on speed. Contribute to ninja-build/ninja development by creating an account on GitHub.

warm brook
#

im on mac tho

#

cmake_minimum_required(VERSION 3.29)
project(CPS1011-Labs)

add_subdirectory("Lab 1")
add_subdirectory("Lab 2")


cmake_minimum_required(VERSION 3.29)
project("Lab 1")

add_subdirectory("Butler")
add_subdirectory("Feet to Fathoms")
add_subdirectory("Functions")
add_subdirectory("Inventory")
add_subdirectory("Pets")


cmake_minimum_required(VERSION 3.29)
project(Butler C)

set(CMAKE_C_STANDARD 11)

add_executable(Butler main.c)

these are some of my cmakelist files

naive horizon
#

Just the one for "Butler" please

#

But it appears this is it?

cmake_minimum_required(VERSION 3.29)
project(Butler C)

set(CMAKE_C_STANDARD 11)

add_executable(Butler main.c)
warm brook
#

cmake_minimum_required(VERSION 3.29)
project(Butler C)

set(CMAKE_C_STANDARD 11)

add_executable(Butler main.c)

#

yep

naive horizon
#

Not sure how to best to help you along.
I don't have CLion. I wish I did.

#

I can guide you through building your project from the terminal.
Also not sure how comfortable you are with that.
Plus, even if we got you unstuck on building your project, you still want to be able to do that from CLion.
At least going forward.

warm brook
#

I tried a bit using the terminal but tbh i rather not use the terminal ahah.

naive horizon
#

Can you find this screen in CLion?

warm brook
#

a profiles tab?

naive horizon
#

I really think I should butt out and let a CLion expert guide you further.
Issue is; they are scarce.

warm brook
#

yeah starting to believe the same

#

im not sure why they are tho

#

cause clion is quite sleek

naive horizon
#

No doubt, but it does nom your memory.

warm brook
#

ahhh that it does, quite a heavy application....it 4.36gb on its own

naive horizon
#

If you find that screen I showed you, or something similar, try selecting "Ninja" or "default-ninja" or whatever.

warm brook
#

alr thank you

naive horizon
#

If you have CLion on your system, then my hope is that it also installed Ninja along with it.

warm brook
#

hahah I dont really know what that is

naive horizon
#

That's a looong boring story.

#

(not really boring)

warm brook
#

is it long and boring enough to learn at uni and have a whole unit about it?

naive horizon
#

It's part and parcel of cmake.

warm brook
#

ohh i see

naive horizon
#

CMake is not a build system. You cannot build an EXE using CMake alone.
CMake generates a build system that can.

For some lucky people, it can generate project files that you can load directly into your IDE, like Visual Studio.
But for those not so lucky there is Ninja.

Ninja can leverage any compiler you may have and build the EXE.
But you need to tell Ninja what compiler to use.

For someone like me (embedded) I need to provide more instructions to Ninja than you care to learn about today.
But I am guessing that - within CLion - this is all taken care of.

warm brook
#

Do you think it has anything to do with this?

warm brook
naive horizon
#

Go into the "CMake" menu at the bottom of "Tools".
What can you see there?

warm brook
naive horizon
#

Nah, not it.

#

What if you right-click on your project in the Project View pane (left of the screen)

warm brook
#

this??

#

I FOUND IT!!

naive horizon
#

Cool!

#

Is "Ninja" listed as an option in the "Generator" combo?

warm brook
#

yep

naive horizon
#

Try that.
After all that fuss, this had better work 🤞

#

You may need to "Clean" your solution though.

warm brook
#

which one?

#

just ninja?

naive horizon
#

Just "Ninja" yes

warm brook
#

YAY IT WORKED!!!

naive horizon
#

Thank God!

warm brook
#

You are incredible!!!

#

thank you so much!

#

I have been trying to solve this for idk how much time

naive horizon
#

I am probably more relieved than you.

warm brook
#

bahahah im not so sure how it worked but thankfully it worked

warm brook
naive horizon
#

Because I was working on pure hunches.

#

I am still surprised that the "Unix Makefiles" (your default until now) did not work.

#

But you're better off with Ninja anyway.
So all good.

warm brook
#

Thanks again! Ill look deeper to this ninja stuff cause it saved me from doing a bunch of seperate projects and still lost how it functions

naive horizon
#

If you build from the command line then it's a mere matter of

cmake -G Ninja -B build.dir
warm brook
#

building means to add things to my repo?

naive horizon
#

But, as said, you really want to be able to do builds from within CLion.

naive horizon
warm brook
#

oh yeah i was refering to that..... Im really new to this

#

but our professor assumed we knew all of this

naive horizon
#

Hah!

warm brook
#

has been such a pain. I cant thank you enough honestly

naive horizon
#

Well, you've learned something.
I learned something.
And you got unstuck.

#

Happy to have been of help.
Good luck with the rest of the assignment.

warm brook
#

Appreciate it!

mint sandalBOT
#

@warm brook Has your question been resolved? If so, type !solved :)

warm brook
#

!solved

mint sandalBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

warm brook
#

@naive horizon I have the same problem again not sure whats happening now. I just tired to create a new folder

#

everytime i reload it create a cmake-debug folder into excersise 2 for some reason

#

its also saying that it cannot find a cmake project

#

ok i managed to fix it since the main.cpp was a .cpp extension and not a .c Still tho for me to be allowed to build i need to create that debug folder and the other mains arent working ;( now

naive horizon
warm brook
#

mmm not really

warm brook
#

still getting this error

#

but for the folder called excerscise 2 it compiles

#

even tho i re-directed the folder and am on ninja and cleaned the folder

clear thicket
#

and its looking for main.c

#

:)

warm brook
#

they are all main.c ;(

clear thicket
#

I was hallucinating things var

naive horizon
naive horizon
#

Pure speculation on my part.... that CMakeLists.txt has something like this

project(Exercise4 LANGUAGES C)
#...
add_executable(Exercise3 main.c)
#

In other words; C&P error.

warm brook
#

sorry for the wait....I opened clion again and magicaly everything is working again. im not sure how but it worked.....Could it maybe because I opened a folder before (which is called it github) instead of the project folder

clear thicket
#

Yeah you need a cmakelist at the root for CLion to work i think

warm brook
#

I do have a root cmakelist tho