I'm getting a segfault in my C program, and I thought I'd use Clangs help in figuring out why, as Valgrind isn't supported (yet).
I try to compile my program with -fsanitize=undefined to activiate runtime checks for undefined behaviour. All I'm getting is an error message which reads something like: "fsanitize doesn't support option 'undefined'". I've also tried using -fsanitize=address with the same result :/
Anyone know why this is?
It seems like -fsanitize is not supported by apple's CLang.
If you go here http://llvm.org/releases/download.html#3.4 you can get the prebuild binaries of clang, that do recognize this option.
However this is harder because then you have to use a Makefile,
IF by chance you use cmake, then you can just easily go to use makefiles.
OR replace the binaries in the Xcode.app/Contents/Developer/Toolchains/.../bin
but I don't know what can happen if you replace Apples binaries, do a backup before to be able to restore.
Honestly, I'm not myself confortable about replacing apple's binaries, because they probably added something in the clang to make it work with Xcode nicely.
Again, the GPL policy of GCC had this advantage that apple could not modify it.
-> another solution is to develop on linux,
The port to windows of CLang is on its way, but not ready yet, maybe in 3.5.
Best
Related
I installed Atom over the weekend and installed some packages to make it more functional. After installing some of the packages, I ran terminal and ran a g++ command to compile some software and the error codes and display now look a lot different. Its actually much more clear in this form what the issues are, but that's besides the point. I'm wondering if anyone might know which package might've caused this sort of change? The easiest thing to do would be be to list all of the packages I downloaded, but I downloaded quite a few and ended up uninstalling some, so I don't even have a definitive list of what they could be. I'm not even 100 percent positive that it was an Atom package that changed the g++ output, but I don't recall it looking this way before. What I'm referring to is the error message and the green arrow pointing to the exact issue. I don't believe this was the way the output looked before after trying to compile a program with issues.
I realize this is a vague request to track down, but if anyone has any idea which package might've changed the way g++ outputs errors to the screen, that would be awesome.
I'm ultimately trying to figure out how to remove whatever it was that changed it and go back to the original output, so if anyone has any suggests for maybe reverting the functionality, I would try that as well.
Apparently, I've spent a majority of my time compiling in the linux shell via g++ that I never really paid attention to the the way the error messages look in mac terminal when using g++.
After a bit of digging, I found that g++ is using clang. After looking at the clang documentation for "Expressive Diagnostics," I've come to find that these sort of markups (what Clang devs are calling "Caret Diagnostics and Range Highlighting") are normal and standard, not installed by Atom. I must've drawn that conclusion randomly out of paranoia, after installing packages and packages for Atom and only then, noticing the difference in error output between Linux shell g++ and Mac Terminal g++.
A poster named "Adam" suggests that "Homebrew" is an easier way of getting Terminal to revert back to using GCC instead of Clang, which should be close to what I'm used to with the Linux shell experience with g++
I was wondering which compiler is better to use on Windows OS (8.1) in temrs of compatibility to c++11's (and later 14) functions, liberies and features (like lambdas) and is also comfortable to use (less bugs).
I am a university student hence I'm not looking at the subject product-wise (even though I do like to code a bit more than just projects for my studies).
I am currently using eclipse luna IDE if it matters.
Notice that compiler != IDE.
VC++ is one of the most populars on Windows and depending on its version it has a good support for C++11 features. Check the list on the msdn blog to find out if there's everything you need.
Gcc is also ported to Windows and you can install MinGW to use it (4.8.1.4 at the moment of writing this). It is pretty complete on C++11.
Clang is also available for the Windows platform and it is also complete on C++11 support (plus it has good diagnostic messages), but notice that you will have to use another linker since clang doesn't ship with one (although there is an ongoing effort to write it: http://lld.llvm.org/)
All the compilers I cited above are pretty stable but, based on my experience, if you're looking for latest and greatest C++11/14/17 features, you might just want to go for gcc or clang (VC++ is slower in adding support for newest features and the compiler is undergoing a huge update to modernize). Just keep in mind that these are compilers and not just IDEs, an IDE is a front-end supporting program that uses a compiler undercover to compile files.
To set up a C++11 compiler, I suggest installing MSYS2, it has a package manager (pacman) that can install fresh versions of GCC, GDB, Clang and many libraries like SDL, Lua etc. Very easy to use too.
As far as GCC vs CLang goes - I really tried hard to make CLang work (which is presumably faster and more friendly than GCC - produces better warnings, etc.), but failed. Issues were that CLang (which comes with MSYS2) is hard-coded to use GCC linker which produces some strange linker errors when using libstdc++ (std implementation from GCC). libc++ (a new implementation designed to work with CLang) didn't worked for me on Windows either.
So you either try build CLang from sources and hope that some configuration will work with C++11 library, OR just stick with GCC which works just fine out of the box.
As IDE, I suggest to take a look at CLion. It is very comfortable (infinitely more user-friendly and intuitive than Visual Studio, IMO). Just install it and point it to the mingw64 (or mingw32) folder of MSYS2, it will auto-detect everything for you.
It only works with CMake projects though.
Can someone either explain or preferably point me toward some documentation that explains the difference between passing --clang and not passing it to the gcc compiler.
I've had to append this parameter on numerous packages when compiling and I don't know what it does, I have yet to personally encounter code that won't compile without it but other projects seem to require it. I can not find it in the man docs for gcc, so I am trying to find a little bit more about what it is, all I know is that it has to do with the LLVM.
There's no --clang option to anything. clang is another compiler for OS X and is available inside Xcode as "clang". It's another compiler similar to gcc, and is the new default compiler for OS X.
A link from the Apple Developer Website explains more.
GCC is a very well respected multi-language compiler (from what I've gathered). One thing I've not been able to definitively find out is: Is it possible to use GCC on windows without anything extra like Cygwin or MinGW?
I've learned that if you use GCC on Cygwin, there is a dependency on a DLL. If you use GCC with MinGW, you eliminate that dependency but you still must have MinGW to use GCC.
Is it possible to build GCC and utilize it by itself, completely native to Windows? Like Microsoft's Compiler? After reading around, my guess is no. But I'd still like more info, if possible.
If not, why does GCC require environments like Cygwin or MinGW? I understand this now. It is because GCC requires a Unix/POSIX environment. Why it does, it still beyond me.
I did find this and it helps but doesn't really answer my question: Why does GCC-Windows depend on cygwin?
To refine my question, I guess what I'm trying to understand why GCC can't stand on it's own -- Where I have just "GCC.exe".
For MinGW, you need MinGW in the sense that MinGW provides the implementation of the gcc language system. I don't see how your question makes sense - it's like "Can I use VC++ without installing VC++?"
To clarify: MinGW is the GCC compiler executable(s), headers and support objects. There isn't anything else. There is a related but independant package called MSYS which provides some posix utilities, but you do not need this in any way in order to use the MinGW version of GCC.
What is exactly the problem with mingw? And what is native?
mingw used to generate pretty much standalone binaries, and maybe that is even more native than MSVC's, which require msvcrt, a component that needs to be installed sometimes.
So maybe you could explain what you tried with mingw, and what the exact problem is.
To disable mingw's extra dependency simply don't use exceptions (-fno-exceptions), I haven't used cygwin so not sure.
I don't think so. I've had to compile some command line apps for people in the past and always had to use cygwin.
I think the biggest reason being posix compatibility, which is what cygwin strives to bring to Win32.
Linaro used to provide that long time ago, a GCC that runs naively on Windows without MinGW or Cygwin. I am currently using that GCC 4.9 on a Windows 10 PC to compile UEFI and it is working like charm.
https://releases.linaro.org/archive/14.09/components/toolchain/binaries/gcc-linaro-arm-none-eabi-4.9-2014.09_win32.zip
simply install wsl on your computer.
I'm working on writing a kernel, and I have a few friends working with me on the project. We've been using DJGPP to compile the project for a while, but we're having some cross-platform compatibility issues with compiling this way that have left my main Partnet on the project unable to compile on Windows XP. (DJGPP's GCC is having issues with argument lists longer than 127 on windows XP, but not having issues with the same argument lists on Vista. So, for once, Vista works better than XP at something. o.O)
Anywho, rather than try to work out some dirty hack to make the darn thing compile with DJGPP, we've decided that we want to ditch DJGPP entirely and work with a different version of GCC for windows. The trouble is, MinGW (to my knowledge) doesn't let us use NASM syntax for the assembly portions of the code, and it would be a bit of a pain to convert it all to AT&T syntax at this point. Possible of course, since its fairly early in the project, but a pain.
So now you know the issue. My question is this: What GCC compiler distro for Windows will allow us to most easily port this project to itself? Ideally, we're looking for something that can do NASM assembler syntax, not have any reliance on externel dlls (this is a kernel here, it won't have access to them) and will work consistantly on multiple versions on Windows. What are your recommendations about the best way to go about doing this, and what version of GCC for windows do you recommend?
Note that if we are going to need to convert the project to AT&T syntax that's OK, I'd just like to not do that. We're actually using NASM to assemble the assembly bits of it, and that produces a valid .o file, but MinGW isn't able to link that in for some reason. I think the inline assembly bits (maybe 5 lines) are already AT&T syntax, as required by GCC.
Thanks!
You are probably passing the wrong object type to nasm with the -f option.
I'll bet you're passing -f coff.
You will need to pass -f win32.
Build a cross-compiler.
http://wiki.osdev.org/GCC_Cross-Compiler
This is what I did when transitioning from DJGPP for development on a Windows host. I recommend the Cygwin method, as it's slightly more stable than MSYS.
Once you've done that, configure NASM to build elf32 object files, and you're good to go.
Are you using NASM compiled for DOS or for Windows? I did not look, but it is possible that there is a difference. Also, if your NASM is too old, it might not be able to generate something MinGW can understand.
A quick Google search found a tutorial on compiling x264 under MinGW, where one of the steps is to compile NASM on MinGW.
Failing that, you could try (as suggested on a comment to another answer) using objcopy.