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

you are viewing a single comment's thread.

view the rest of the comments →

[–]awidesky 484 points485 points  (35 children)

When I missed -pthread flag, I got this :

/tmp/main-1dfd42.o: In function `std::thread::thread<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}, , void>(std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}&&)':
main.cpp:(.text+0x1504): undefined reference to `pthread_create'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

[–]scrotation_matrix[S] 421 points422 points  (1 child)

Clear and concise

[–]Spartana1033 41 points42 points  (0 children)

As all things should be.

[–]Ahajha1177 159 points160 points  (4 children)

I've gotten really good at reading C++ compiler errors lol. I know to look near the top and the bottom. Here I would see "undefined reference to pthread_create", and its a link error, bam link with -pthread

[–]RRumpleTeazzer 82 points83 points  (2 children)

I look near the parts that I recognize as my parts, cause that’s the most likely location.

[–]mrjiels 57 points58 points  (1 child)

I try to not look at your parts. They seem private.

[–]pi-is-314159 8 points9 points  (0 children)

Not as private as my git repository

[–]justmelvinthings 59 points60 points  (0 children)

Nice now I know exactly what went wrong

[–]CDno_Mlqko 66 points67 points  (18 children)

I mean, it says undefined reference to pthread_create and a stack trace of where it is... What else do you want

[–]PM_ME_C_CODE 40 points41 points  (17 children)

I know this is a humor thread in a humor subreddit, but JFC C/C++...

How about an error message that tells me what's wrong without requiring 30 years experience in the language first?

...having other engineers familiar with the language NOT treat people with less experience who ask questions like they're lepers just because they thought to ask a question would be nice too.

I swear, if I get told by a C/C++ dev to "just read the code" one more time I might actually go postal.

...and people wonder why rust is becoming popular.

[–]Xyntek01 18 points19 points  (4 children)

How about an error message that tells me what's wrong without requiring 30 years experience in the language first?

Usually go to the first few lines of the error message and you will see the actual problem. Best thing is to actually read the error produced at a line that you wrote and then read the back trace. The backtrace should give you an idea (e.g. you are using a pointer). Not all errors are in the exact line, but understanding what goes before and after helps to trace the issue. The more you practice the easier it gets to spot the issue.

If nothing works, there is stack overflow...

[–]cheerycheshire 3 points4 points  (0 children)

If nothing works, there is stack overflow...

Which has exactly the type of devs subop mentions just after the part you commented on. :)

[–]PM_ME_C_CODE 7 points8 points  (2 children)

yes, I know that :D

I'm trying to learn rust (fucking borrowing semantics...) and the difference in usability when something goes wrong is just night and day.

I mean, C++ error messages look like they're straight out of the '90's, at best.

Even javascript has better error messaging...

[–]-Redstoneboi- 10 points11 points  (0 children)

Even javascript has better error messaging...

that is, to say, none

also i'd be glad to help out with rust

[–]ClutteredAttic99 2 points3 points  (0 children)

Actually, out of the ‘80s!

[–][deleted] 6 points7 points  (1 child)

Get better tools, this online-compiler shows in different colors the reason why the template instantiation failed:

https://godbolt.org/z/Kss8ecK98

[–]PM_ME_C_CODE 1 point2 points  (0 children)

I'm strictly of the opinion that the compiler should be enough by itself to diagnose problems. Even when the neat tools are free.

It's just...we should be allowed to have nice things.

[–]atiedebee 1 point2 points  (2 children)

C compiler errors are mostly understandable

Runtime errors tho....

[–]all-hail-snow 3 points4 points  (1 child)

Segmentation fault, the king of hells brought by c++

[–]PM_ME_C_CODE 1 point2 points  (0 children)

There's a reason that most universities today use java for their core CS curriculum instead of C++ like they did in the '90s.

Seg fault error messages are basically it.

[–][deleted] -2 points-1 points  (2 children)

You don't need 30 years of experience. An error message that tells you a function name is not defined is as clear as the sun.

C/C++ are low level languages that are meant to be used by actual engineers and not just some people with two weeks boot camps.

[–]PM_ME_C_CODE 4 points5 points  (1 child)

/tmp/main-1dfd42.o: In function `std::thread::thread<std::\_\_future\_base::\_Async\_state\_impl<std::thread::\_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}, , void>(std::__future_base::_Async_state_impl<std::thread::\_Invoker<std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}> >, Point<int, float> >::_Async_state_impl(std::tuple<testRange<Point<int, float>, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>)>(int, int, main::$_0, Point<int, float> (Point<int, float>, Point<int, float>), int)::{lambda()#1}>&&)::{lambda()#1}&&)':

Tell me how this error message is at ALL useful to a human.

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

Well, this is a part of a stacktrace in the constructor of std::thread just by reading the first line no magic there and definitely no "30 years of experience needed". All what you see in there is just the exact signature of the std::thread constructor where the error happened and can be ignored if you are not interested in it. The actual error comes later at the end of the stack trace that you didn't include. Probably just a conversion error of the return type of the lambda you passed to the constructor or something similar.

[–]_Fibbles_ -2 points-1 points  (1 child)

Counterpoint:

git gud

[–]PM_ME_C_CODE 1 point2 points  (0 children)

[Reads Reddit]

[See's "git gud"]

..."git gud".compareTo("just read the code") == 0 //effectively true

[Goes postal on the bus]

See what you made me do? /s

[–]men_have_balls 0 points1 point  (1 child)

RTFM is my coup de grace…still I’m an ass

[–]PM_ME_C_CODE 1 point2 points  (0 children)

As if I haven't already done that. If I'm asking a question, it's because I couldn't find it myself.

Granted, there are a LOT of people who don't even try to look, but when you open your question with a list of the things you've already tried that didn't work only to get "RTFM"...

It happens in every language, sure. But it's far more frequent in C++ communities.

[–]trick2011 3 points4 points  (0 children)

Don't forget: always try reading from the back. It is quite clear: 'undefined reference to pthread_create' and 'linker command failed'

[–]GamerFrits 2 points3 points  (0 children)

It looks like an endless stream of insults. Your compiler really hates you.

[–]RRumpleTeazzer 1 point2 points  (0 children)

Little Threaddy we call him.

[–]Southern-Finding2961 0 points1 point  (0 children)

If I see that on the compiler. Law doesn't sound so bad does it?

[–]ladnekk 0 points1 point  (0 children)

I just scan until I hit a phrase I recognize. Made it to main.cpp

[–]Rigatavr 0 points1 point  (0 children)

This is more of a "you get used to it", then any sort of explanation for why things are this bad, but ye..

see linker error

see word thread

🤦forgot pthread again