safeseh gs on g++ - visual-studio

I want to compile a c++ file. I'm following a tutorial, in this tutorial, the file is compiled with Visual Studio, and I don't have it. I want to do the same with g++. In the tutorial, use the /GS and /SafeSEH from VS. I want to know how compile my file with those flags with g++ compiler.
Sorry if my question is simple, I never used g++ before. And sorry for my english. Thank you.

So first things first:
/GS actually performs "buffer security checks" which attempt to
automatically detect buffer overflows and terminate your application
before such overflows can be exploited.
/SAFESEH embeds a list of all the structured exception handlers
inside the executable so that the operating system can detect if
unauthorized handlers have been installed in an attempt to hijack
execution.
Now to answer your question: g++ implements a feature similar to /GS. You can compile your code with -fstack-protector-all to enable it. If you are curious you can look at the gcc manpages or use google for more details. g++ doesn't implement structured exception handling (it's a Microsoft extension) and so there's nothing similar to /SAFESEH in g++.
The good news are that unless the example you are working through is designed to demonstrate the extra protection /GS and /SAFESEH afford, compiling the code without them shouldn't be a problem at all. I'd be willing to bet that you can ignore those two options and just compile without them and things will be fine.
If you are interested in getting Visual Studio, you can get the free "Express" versions from Microsoft. Check out the website, here: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products
I hope this helps.

Related

debugging ex_bad_access with gdb in c++

I'm compiling code from the command line with g++ on Mac OSX and have an error when I run my code that results in an EXC_BAD_ACCESS
I've seen that the most helpful way to debug this kind of error is with Zombie objects that don't deallocate when released and then complain when code tries to release them.
However, it seems that NSZombie options are available in Xcode/Objective C.
So my question is there any way to use this functionality/equivalent in programs simply compiled code like
g++ file1.cpp -g -o executable
debugged with
gdb executable
Thanks.
Zombie objects are a concept of Objective-C, not C++, and relate to reference counting issues, which C++ doesn't use (unless you count smart pointers and Enabling Zombies won't help you with that anyway).
So, to answer your question; No, there is no way to use that functionality.
If you want to find the issue then you'll need to use a debugger.

What compilers support CUDA

I found some problem with Visual Studio. My project that use openMP multithreading was twice slow on Visual Studio 2010, than on Dev-C++ , Now I wrote my other project that uses CUDA technology , I think that my project works slow because of Visual Studio, so I need some other compiler that will support CUDA , my questions are:
is Dev-C++ support CUDA?
what compilers support CUDA except Visual Studio?
if there are a lot compilers supporting CUDA what will give best speed for application?
The CUDA Toolkit Release Notes list the supported platforms and compilers.
Well I think it's the other way around. The thing is, there is a driver called nvcc. it generates device code and host code and sends the host code to a compiler. It should be a C compiler and it should be in the executable path. (EDIT: and it should be gcc on Linux and cl on Windows and I think I should ignore mac as the release note did(?))
nvcc Compiler Info reads:
A general purpose C compiler is needed by nvcc in the following
situations:
During non-CUDA phases (except the run phase), because these phases will be forwarded by nvcc to this compiler
During CUDA phases, for several preprocessing stages (see also 0). On Linux platforms, the compiler is assumed to be ‘gcc’, or ‘g++’ for linking. On Windows platforms, the compiler is assumed to be ‘cl’. The
compiler executables are expected to be in the current executable
search path, unless option -compiler-bin-dir is specified, in which
case the value of this option must be the name of the directory in
which these compiler executables reside.
And please don't talk like that about compilers. Your code is in a way that works better with Dev-C++. What is generated is an assembly code. I don't say that they don't make any difference, but maybe 4 to 5%, not 100%.
And absolutely definitely don't blame the compiler for your slow program. It is definitely because of inefficient memory access and incorrect use of different types of memory.

How do I generate symbol information to use with Linux version of Intel's VTune Amplifier?

I am using Intel VTune Amplifier XE 2011 to analyze the performance of my program. I want to be able to view the source code in the analysis results, and the documentation says I need to provide the symbol information. Unfortunately, it does not state how to generate that symbol information when compiling my program. In the Windows version of VTune all I had to do was provide the ".pdb" file that Microsoft Visual Studio would generate. Is there a similar kind of file I can create using g++ to provide this symbol information?
Have you tried compiling with -g ? Normally that is all you need to generate symbolic data for debuggers, profilers, etc.
Incidentally, for profiling on Linux, Zoom from RotateRight.com is a lot more user-friendly than VTune. (UPDATE: Zoom is unfortunately no longer supported. Use perf for simple profiling.)
The most "classic" way to get an executable to contain the debug information with GCC is to specify the "-g" command line option as mentioned by the other posters. This does not incur any performance hit since debug information resides in ELF sections which are not part of the code or data segment. That is, the .debug* sections are not mapped into the memory during normal program execution, it's only the debug time when the debugger gets them in.
Another useful consideration for any developer working on production software is to use separate debug information files. That assumes compiling the program with "-g" as described above and then using objcopy utility to copy out the ELF sections containing debug information into a separate file and adding a link from the original binary file to the separate debug information file. This is extremely useful for being able to store the debug information for the bits you released to a customer so that post-mortem debugging is possible. And of course, for performance profiling on the release bits, too.
gcc -g <your stuff> should be all that's necessary. However I used an older version.
The command line options for the newer stuff is here
EDIT:
This SO answer is probably more valuable than anything here.

how to obtain VC++ compiler-style help on GCC G++ compile/link errors (on linux)

I'm using VC++ as professional developer for more than 10 years and it has been good to me, now I'm trying to broaden my horizons and learn C++ development on Linux.
On Windows things are simple, VC++ does it all (editing, project management, help, debugging), but on linux things are different, you have assemble your development environment from different tools.
I'm still trying to tie things together, and one thing I still haven't figured out is how to decipher GCC (G++) errors when compiling/linking C++ apps on Linux (although I realize GCC is multi-platform, I'll refer to my linux experience here only).
In VC++, things are very clear: If during compilation VC++'s compiler encounters error in program, it will create new entry in 'output' window with the 'compiler error ID'. Example:
c:\projectA\fileB.cpp(38) : error C2228: left of '.cout' must have class/struct/union
From here, you can click on the line in question in 'output' window, press F1, and 'Microsoft Document Browser' app will start (if it wasn't started already), which will load MSDN help file describing compile error connected to the compiler error ID (in example it's C2228), usually with sample you can check out to figure out what's wrong with your code. If you don't have MDB installed, you can always search on the web for C2228 and get the same help page, optionally finding other people's web pages describing their experience with this error.
The same thing is with linking, you'll get 'linker error ID' (e.g. LNK1123), which you can use to find help either locally or on web.
Try as I might, I can't find this kind of functionality in GCC's G++. All I can see is bunch of less experienced GCC developers asking another bunch of more experienced GCC developers to analyze their code based on descriptive compiler/linker errors with no associated error IDs.
Is there tool(set) that provides VC++ compiler-style help on GCC G++ compile/link errors for linux?
You may try to use qtcreator. At least it can show the errors in a more comprehensive way comparable to the VC++, that is, it can locate the error position and highlight the error line and variables.
If you can an alternative might be to use Clang instead. It gives much better error messages than g++. It compiles most code these days (but it still a work in progress). Highly recommended.
Alternatively (as another poster has mentioned) you could use an IDE such as Eclipse to capture the error messages, though I don't think that adds anything beyond taking you to the line number on double-click.

C(++) Compiler Transition - Make DJGPP go away please

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.

Resources