I'd like to test data races in C++ on windows 10(64 bit), but it seems that Visual C++ doesn't support it yet.
So, I installed Cygwin and got g++ 11.2.0, tried compiling my C++ code with -fsanitize=thread -fPIE -pie -g, but it failed with -ltsan not found error.
The doc doesn't say anything about Windows. Is it even possible to use Thread Sanitizer on Windows? If so, How?
The sanitizers you linked are implemented in Clang, not MSVC or gcc.
You can use clang with Visual Studio. To do so you need to install the appropiate toolchain.
You can run clang directly on Windows, via cygwin or via WSL.
In addition could you post your complete compile command (e.g. via godbolt.org)?
e.g.: https://godbolt.org/z/fax6o9E1f
Just use WSL and use thread sanitizer on it.
Related
For C++ development on Linux, if I install clang and use it; it actually uses libstdc++(the g++ lib). What's the use of installing the frontend compiler clang on linux then?
I should be good with gcc/g++ only on a linux machine as that's a complete toolchain!
Note: I'm not an expert in C++.
libstdc++ is a default runtime on your Linux. libc++ is not installed by default. If you link your app to libc++, you have to add it as a runtime dependency.
You are right, gcc/g++ is good for Linux, moreover its diagnostic messages are more clear, thus the compiler is better for beginners. By using clang++, you need to know the C++ standard deeper, otherwise it's difficult to get an error reason.
I'm trying to use clang10 with mingw-w64's libstdc++, since the MSVC headers don't support clang 10. I don't mind not having the new parts of the standard library, I just want to use the new language features.
I have mingw-w64 version 8.1.0 for x86_64 with POSIX threads and SEH exceptions installed and I run clang with a command:
clang++ -target x86_64-pc-windows-gnu -std=c++20 ...
Everything works OK. All the language features that should be implemented in clang 10 work, but when I throw any exception, this happens when I run the program (the program compiles OK):
Mingw-w64 runtime failure:
Unknown pseudo relocation protocol version 65536.
I tried installing mingw with SJLJ exceptions and use the -fsjlj-exceptions flag in clang, but the program doesn't even compile:
C:\Users\egst\AppData\Local\Temp\test-f4a4de.o:test.cpp:(.text+0x82): undefined reference to `__gxx_personality_sj0'
C:\Users\egst\AppData\Local\Temp\test-f4a4de.o:test.cpp:(.text+0xd9): undefined reference to `_Unwind_SjLj_Register'
C:\Users\egst\AppData\Local\Temp\test-f4a4de.o:test.cpp:(.text+0x177): undefined reference to `_Unwind_SjLj_Resume'
clang++ --version shows Target: x86_64-pc-windows-msvc. Maybe there's a version for x86_64-pc-windows-gnu that I should use instead? Is there any way to make this work at this moment, or should I wait for support from MSVC? Is there maybe any alternative besides MSVC and MinGW?
Based on #HolyBlackCat 's sugestion, I tried this with MSYS2 and it works perfectly. I simply installed MSYS2, then from the MSYS bash I installed this package. It installs everything in in ...\msys2\mingw64. You get clang 10 (+ gcc 9.3) and all the needed stl headers (still no c++20 headers like <concepts> though).
I've been trying to compile a multithread hello-world program under Cygwin using the newly introduced C++ 11 std::thread feature without success. I compiled and installed GCC 4.7.2 by myself, and the same code works without any problems under Linux with the same version of GCC. The first error I got was that the compiler did not recognize the -pthread flag. After researching on it for a while I noticed someone said on Cygwin this flag should be -lthread. I made the change and that error was gone, but another series of errors occur telling me thread is not member of std. I wonder if it's caused by the wrong configuration of the compiler during installation, or std::thread is simply not supported under Cygwin?
This looks like you did not compile the program with the appropriate standard library flag. If you want to compile for C++11 you should use:
g++ --std=c++0x -o ...
The --std flag sets the appropriate language compatibility level. If this does not help, please post the error messages you got as a source listing.
I am solving questions on Interviewstreet.com. They said they use C++ version g++ 4.6.3,C0x mode.
I am writing code on code blocks. So i want to know which version iam using in code blocks is it in C0x mode or C11 mode??
I have tried using g++ --version i got g++ TDM-2 mingw32 4.4.1.Can u tell me where i can get this kind of information.
what is the difference between C++ 0x and C++11??
You'll have to update the version of g++ to 4.6.3 (or later) if you want to use c++11 features. See this question and it's answers on how to do it for deb linux.
Then you'll have to pass --std=c++0x to the compiler in options. You should be able to easily find them in codeblocks.
what is the difference between C++ 0x and C++11??
c++0x is a synonym for c++11.
The command:
g++ --version
gives you the version of your g++ or mingw compiler. Since you got g++ TDM-2 mingw32 4.4.1 then your version is 4.4.1. If you want to use version 4.6.3 as in that web site, then you would have to update.
It wouldn't hurt to use a newer than 4.6.3 version of mingw, so please see here for the latest version. This page offers an windows installer for mingw.
After installation, you would have to configure CodeBlocks to use the newly installed compiler by looking into Compiler and debugger settings -> Toolchain executables tab and setting the paths for the compiler-related executables to the new ones.
Hope this helps.
EDIT:
Here is a small tutorial/example of what the CodeBlocks settings look like.
I have to write a c++ program, and i want to do this in vstudio 2010, because it's the most comfortable way for me. But later this code will be compiled in gcc 4.3.2 (ejudge). I can't find gcc 4.3.2 binaries for Windows, if there any ways to check correctness of gcc compilation? Or maybe anyone will help to find gcc binaries? I found this link http://tdm-gcc.tdragon.net/download but there i can't find 4.3.2 version binaries, only source code. Thanks.
MinGW, or Minimalist GNU for Windows, is a set of GNU compilers for Windows platforms. It's the easiest way to use G++ on windows platform. You could also use Cygwin, but it would be a bit of overkill.
As I recall g++ 4.3.2 was used in an older version of the Code::Blocks IDE, as the bundled compiler.
However, I'm currently unable to connect to [http://www.codeblocks.org], so I don't know if they provide downloads of older versions.