-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
link errors with 3.2.0 #64
Comments
Thanks for the bug report! I'm happy to make this small change if it fixes the issue, but first I want to understand better what the issue is exactly, since I have not encountered it myself. I tried to reproduce this now by creating a dummy project, compiling individual object files, and then inking them, but it worked without any issues on every system I tested it in, including Ubuntu 22.04 with GCC 12.0.1. Are you able to supply a minimal working example of the error so I can test it myself? Also, can you explain why this error happens, and why does making these variables |
Ok just run make.sh in https://github.com/reder2000/thread-pool-rr if you have g++ |
I have the same errors, as @reder2000 commented, adding This is what clang-tidy says:
This is the failing check: |
Here is a small example: https://godbolt.org/z/cenrrh4ex |
Thanks for the information @reder2000 and @krupkat! So the issue seems to be that if the header file is included in two different translation units, then everything in the header file will be defined separately in each unit. When the two units are linked, this will cause an ODR (One Definition Rule) violation since there is now more than one definition for these variables overall. This does not apply to classes (as long as these conditions are satisfied) which is why the classes defined in Anyway, to solve this, I think I will just move the two offending variables into the The fix will be released soon. I'm closing this issue meanwhile. Also, @krupkat, which arguments are you using with clang-tidy? Because I have it set up to run automatically in VS Code, but it did not show me this error during development, and still doesn't show it even for the two examples attached here. |
Using global variables is not that scary. That's how it's done in the STL for endl. |
Yeah, and I guess that's why I initially defined them as global variables here as well. But now I realize it's not a good idea. Consider for example someone who uses |
Whoever |
Haha, I agree ;) (Although I often use that when I teach C++, because it makes code a lot cleaner and thus easier to understand for beginners. But I would never use it in actual code.) |
This is what I currently use:
Thanks for the quick replies! |
Thanks, that works! |
Another option would be to put all the implementation stuff (and global variables) under a This is how the stb libs work (see stb_image.h for example). |
Thanks! But the general trend in C++ is to avoid using macros whenever possible, because they are notoriously prone to errors. I believe C++17 introduced the |
The following two lines cause link error (using Visual Studio + mingw64 or remote ubuntu g++12) because of multiple defined symbols :
Direct compilation (ubuntu g++ or msvc) don't trigger linker problems.
However, changing these lines to
seems more correct, don't hurt already working builds, and fixes the linking error.
The text was updated successfully, but these errors were encountered: