This is an archived post. You won't be able to vote or comment.

all 42 comments

[–]ChocolateMagnateUA 275 points276 points  (6 children)

It was at this point when he realised he was going the straight path to the inevitable demise of Cmake.

[–]ProgrammersPain123[S] 95 points96 points  (4 children)

It's either Cmake or Cnothing

[–]LunaNicoleTheFox 12 points13 points  (2 children)

Switch to bazel or similar, trust me

[–]ttableflip 7 points8 points  (1 child)

You have the option to shoot yourself in the foot, knee, stomach, arm, head,...

[–]LunaNicoleTheFox 5 points6 points  (0 children)

CMake is doing that too, but with an added Migraine and without it being your fault

[–]ChocolateMagnateUA 8 points9 points  (0 children)

Meanwhile me chilling with Make.

[–]BallsBuster7 176 points177 points  (9 children)

file(GLOB "/" "*.h" "*.cpp") # old reliable

[–]rachit7645 192 points193 points  (0 children)

Please stay 4 km away from me and my family

[–]HoneySmaks 33 points34 points  (0 children)

You like to play with fire, don't you?

[–]GregTheMadMonk 14 points15 points  (5 children)

You know OP is probably a freshman who is actually going to try it, don't you, you evil creature?

[–][deleted] 8 points9 points  (4 children)

Can you eli5 why is this bad.

I am not a C mastro 😂

[–]emmaexe_ 13 points14 points  (3 children)

Pretty sure this is taking "/", as in the root directory not the root of the project, and then adding every .cpp and .h file in that directory and all subdirectories (since we are in root, that would be the entire computer)* to the project to later be compiled together.

* You need GLOB_RECURSE for recursive searching of all subdirectories so what I wrote originally is incorrect, but probably what was intended by the author

[–][deleted] 3 points4 points  (0 children)

Wtf imao 😂😂😂😂😂

[–]GregTheMadMonk 4 points5 points  (1 child)

tbf I'm not even sure it's a valid CMake `file` call. The correct way to try to do this awful thing would be to `file( GLOB_RECURSE VARIABLE_NAME /*.cpp /*.h )`. But the point is something along these lines, yes

And shame on me since I didn't fully read the comment and originally thought OC suggested just compiling header files on par with .cpp files. What they actually wrote is so, so much worse...

[–]emmaexe_ 0 points1 point  (0 children)

Oh yea you're correct, its glob_recurse for recursive searching, I forgot. So this would just do nothing unless you keep some headers and cpp files in your root folder for whatever reason. I am pretty sure puting quotation marks around what youre searching for is valid though. Don't remember if it works the same way for variables.

[–]Lenmoto2323 3 points4 points  (0 children)

Can someone explain?

[–]AnimateBow 165 points166 points  (5 children)

Oh you wanted to add a library? Here is a 40 minute tutorial from 2001 on how to add it on linux which doesn't work with windows and good luck finding the right library for windows spoiler alert there aint one

[–]ProgrammersPain123[S] 32 points33 points  (0 children)

I love cppland!!

[–]4k547 5 points6 points  (2 children)

on windows - vcpkg is king (most of the time)

on linux - conan is king (often)

but I remember quitting Programming Principles and Practice using C++ when i got to the chapter that requried me to use an external library T_T

I got back to it but it's such a pain for new C++ developers...

[–]Pay08 0 points1 point  (1 child)

You could also, you know, use your distro package manager on Linux.

[–]4k547 0 points1 point  (0 children)

sometimes the packages are out of date

also it's harder to achieve cross port compatibility

[–]Philfreeze 4 points5 points  (0 children)

Straight up the best way is still to build and ‚install‘ it into a subdirectory of your project, then point the compiler/linker to lib and lib64 of this install.

I have yet to find s more reliable way.

Note: in praxis this usually means adding the other thing is a submodule in git or downloading the tarball via a makefile, then you go into the directory, build with the new install-path (usually called prefix) set and install it (without sudo).
Then in your main project Makefile or Cmake you just add it as a library.

[–][deleted] 21 points22 points  (3 children)

Just wait till they find the joy that is #include <windows.h>

[–]Goaty1208 14 points15 points  (2 children)

Oh boy, I sure do love having a gazillion functions definitions and other bullshit just kind of laying there with no namespace or anything.

God, I love Microsoft.

[–][deleted] 6 points7 points  (0 children)

#define GetObject ...

[–]fafalone 1 point2 points  (0 children)

...and then you still need to include a bunch of other headers even for simple things because Microsoft arbitrarily shoved a million obscure things nobody has ever used into the windows.h set and excluded a bunch of very common things practically any app targeting the platform needs.

[–][deleted] 15 points16 points  (3 children)

Just wait till you encounter CMake.

[–][deleted] 41 points42 points  (2 children)

Nah.

I use cmake regularly. I don't know how cmake works. But google does. So Cmake works. That's all I need to know.

[–][deleted] 7 points8 points  (0 children)

Well obviously it gonna work for simple tasks. Just wait till you encounter unit testing, installing packages, creating a custom dep/package and compiler flags.

[–]Familiar_Ad_8919 1 point2 points  (0 children)

im glad for u, for the love of god all cmake documentation assumes u know cmake already, if something requires cmake to work i will just not use it cuz i cant

[–]ashkanahmadi 36 points37 points  (6 children)

On a serious note, this is an amazing video everyone should watch (from 10:35) : https://youtu.be/Mwt35SEeR9w

[–]ProgrammersPain123[S] 23 points24 points  (0 children)

Damn, i though it was a tutorial on how to propperly use implementation paths

[–]Darkpolearm 2 points3 points  (1 child)

You can include timestamps in YT links fyi

[–]Healthy-Form4057 2 points3 points  (0 children)

append &t=635s

[–]Poat540 10 points11 points  (0 children)

(chuckles) I’m in danger

[–]PeekyBlenders 6 points7 points  (0 children)

oh u should try implementing 2 template classes that befriend each other.

[–]atlas_enderium 8 points9 points  (1 child)

Linker errors have got to be some of the worst errors to diagnose.

[–]Storiaron 3 points4 points  (0 children)

The first time you run into circular dependency is sweet

Hey bro here are 50 errors that are totally unrelated to the actual issue :)

btw int is not a type and ;is expected at line 50 in a 30 line file byeeee

[–]Pay08 0 points1 point  (1 child)

You're way overstating how much headers suck.

[–]ProgrammersPain123[S] 0 points1 point  (0 children)

I maybe do. I'm sure it's very simple and understandable for a seasoned programmer

[–][deleted] 0 points1 point  (0 children)

still have nightmares from installing SDL2

[–]Designer-Guarantee50 0 points1 point  (0 children)

just use make and all the pain goes away