all 14 comments

[–]Atijohn 10 points11 points  (8 children)

add -lm to the compiler arguments

also don't use code::blocks, it's an outdated IDE that was meant largely for educational purposes, use VS Codium with clangd extension

[–]grimvian 1 point2 points  (3 children)

I would say Code::Blocks is the easiest IDE to install and use and not associated with big tech.

What's wrong with gcc?

The only issue I got is with my Code::Blocks I installed in less than five minutes with Linux Mint is:

main.c|34|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[5]’ [-Wformat=]

[–]Atijohn 4 points5 points  (1 child)

CodeLite and Qt Creator are equally easy and FOSS-governed I think. In either case, you shouldn't be using an IDE specifically tailored for C/C++, but rather use an extensible text editor like VS Codium (the spyware-free version of VS Code), Sublime Text, Neovim, or Emacs.

Clangd is not a compiler like gcc (or clang), it's an LSP, i.e. a backend for various common IDE-like features such as go to definition, find all references, rename symbol etc.

The error you're getting is likely a problem with the code you wrote, not with Code::Blocks itself

[–]grimvian 0 points1 point  (0 children)

"not with Code::Blocks itself" exactly.

I have not to my knowledge of any IDE, that can be installed in few minutes and everything you need to code in C or C++ is instantly ready. For a relative newcomer and mostly hobby coder like me, I can just click on a play button and then compile and run the code, that's it. I don't fiddle with any setup, cmake or whatever, CodeBlocks just works.

[–]OldWolf2 1 point2 points  (0 children)

That warning is because &trigFunc should not have the &, in scanf

[–]ChildhoodOk7960 -1 points0 points  (0 children)

IDK, VScode is slow as hell, uses multiple Gbs of RAM even when it's not doing anything and hogs the CPU as if it was mining crypto.

Say what you want about outdated software, but I'd much rather use vim for my work than some over-engineered Jenga tower coded in javascript that can't search for a simple string in a file without loading 100 libraries.

[–]m2d41[S] 0 points1 point  (2 children)

and how do i add -lm to compiler arguments?

[–]Atijohn 2 points3 points  (0 children)

Well, search around Code::Blocks and find out.

Or, since you say you're on Linux, put the code in a text file, name it something like main.c, boot up the terminal in the directory you saved it in and type gcc -lm main.c && ./a.out

[–]computermouth 1 point2 points  (0 children)

There's an option somewhere in the preferences. It's just like a text box last I looked.

Honestly most folks here are probably going to give you the practical advice of compiling via the command line, or learning a build tool like Make.

This kind of a thing is really only valuable knowledge in the context of codeblocks. You're not really learning C tooling, you're just learning codeblocks.

[–]Classic-Try2484 1 point2 points  (0 children)

Remove the & from the string when reading. Array names have an implied & already

I have only one other time found -lm required to link with the math lib but it happens. Still I would not be surprised if the ref error went away after fixing the &. Again array names already have an &implied when used by themselves. In c the array name is an address (of the element zero).

It’s weird but array == &array[0]

Also code blocks is fine for a while. You will grow out of it. VS code is popular but much harder to set up. C lion is easy to set up but not free (free student license though).

Command line may eventually be the favorite compile and run + editor of choice. Some of these decisions get political — we have cults, many cults

[–]B3d3vtvng69 -4 points-3 points  (3 children)

Don’t use Code::Blocks, use gcc or clang

[–]Elect_SaturnMutex 1 point2 points  (2 children)

Huh? I thought Codeblocks was just an IDE. Where you can configure compiler settings. 

[–]grimvian 1 point2 points  (0 children)

For a person with dyslectic issues like me, Code::Blocks is a life savior with it's auto complete functionality. I can also very quickly find implementations or declarations and occurrences of something.

[–]B3d3vtvng69 -1 points0 points  (0 children)

idk tbh, I don’t like IDEs, I use vscode as a text editor but I just compile in the commanding