Code driven compilation - fetching unresolved symbols from code - compilation

I try to write simple application that helps C/C++ code development; it looks for missing objects/functions and automatically includes one of standard C/C++ headers. I assume there're no external libs, so no name collision is possible.
First approach I thought about is to run compilation process ( gcc / clang ) from another C code and fetch missing symbols. If it's stupid, tell me. So: how can I fetch a list of unresolved symbols without hard-coded gcc output parsing?
If for one of these compiler is a lib that helps code-driven compilation, please write.
Thanks! :)
Adam

The comprehensive talk with GCC geeks lead me to https://developer.mozilla.org/en-US/docs/Dehydra/Using_Dehydra
Problably there's no easier way to do it. The best idea is to include all the headers (GCC will remove unused) or just parse the output, cause probably Dehydra can't do everything I would like it to do.

Related

Is there any way to blacklist a folder from address sanitizer when using GCC?

So I have enabled -fsantize=address to write a good program.
However, quite a bit of issues was being caught by other libraries that are not written by me (for ex, /lib64/...so)
I looked into -fsantize-blacklist option but seems like it's only available for clang not for GCC.
I know you can blacklist specific functions in your source code. But to be honest, that is not the ideal way as I wouldn't know which function will cause the issue ahead of time.
Is there any way to prevent GCC from processing address sanitizer for files under a specific folder?
Please help :(
Unfortunately fsanitize-blacklist has been rejected by GCC maintainers several times and there's no equivalent option. You could add Clang support or use -fsanitize-recover=address together with export ASAN_OPTIONS=log_path=path/to/logs to collect errors from all libraries and then filter the ones that are relevant.

How can I hook the preprocessor in Clang, XCode, and MSVS? (GCC works)

I'm using an external preprocessor (pyexpander) for my cross-platform/cross-IDE c++ project*. GCC already works nicely with the -no-integrated-cpp -B${PWD} option. I could manually preprocess each file into a specific temp dir, then compile the processed files. But is there a better way? Specifically, I'd love to hook the native preprocessors so IDE-level code analysis is happy (code completion and error checking). Any hints how I can achieve this would be much appreciated.
*"But why not use c++ macros?" They can't do macro-macros and I need that.
*"But why not use m4?" Because python happens to already be a requirement for this codebase, and m4 seems to not come with MSVS and thus would be yet another requirement/point of failure. I would still have to resolve the original preprocessor problem.
*"But why not use language something_better?" Because I have no choice in the matter. (Though I would love to use nim all the way!!)

What is happening when you set a compilation path?

I understand it is somehow making a connection so that a compiler when envokes connects a source code to whatever libraries that it needs to.
But what is going on a more technical level, or better put what do I need to know in order to confidentally compile code.
I'm working with C++ and MinGW, and have started to look into build files and stuff for Sublime Text 2 (Have learned mostly under unix, or Java + eclipse so far). But what I don't understand what is adding a compiler to your path do for you?
Do I need to add it for every folder I want to compile from? Or is it system wide? I'm really learning this stuff for the first time, we we're never showed how to set up development environments or even deploy code on other systems.
You probably mean include paths and library paths in the compiler:
include paths: where the compiler will look for headers; and
library paths: where the linker, invoked by the compiler, will look for binary libraries to finish building your project.
If that is the case, look here for a gentle explanation.
Basically, what is happening is that the compiler looks in certain places for symbols defined by the operating system and other libraries installed system-wide.
In addition to those paths, you need to tell the compiler where to find the symbols defined in your own project.
You may also mean something related to installing the compiler itself or configuring the editor to use it.
In that case, what is happening is that you need to tell the build system where to find the executable for the compiler.
Basically, what is probably happening is that your editor wants to know where the compiler is so that it can provide real time feedback on your code. Adding the compiler to the system path will usually, but not always, solve your problem.
In more detail:
A C++ build is a rather complex tool chain, involving determining dependencies, preprocessing, compiling, and linking. There are tools that automate that tool chain, and those tools are in turn wrapped into the functionality of modern IDEs like Eclipse, Visual C++, or Sublime Text 2. You many need to tell your editor where to find the tools it uses to provide you with those services.

Floating point operations in GCC

Anyone knows where can I find the floating functions for non FPU processor (SH-3) called __mulsf3, __divsf3, __addsf3, __subsf3, __ltsf2 and __floatsisf. I read that those functions are in libgcc but linking against libgcc does not work. Also I read that SH3 devs moved those functions to another lib (maybe libfloat or libgcc_os).
Anyone has a clue? I would prefer to have a look at the source.
Thanks!
If I'm not mistaken, many of these are generated during GCC's build process and they are highly dependent on system and architecture.
What I do know for sure it that LLVM's compiler-rt strives to provide an alternative. The sources are located here:
http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/
The implementation details have changed over time, but they're supposed to be in libgcc. However, SH being a multilib system, maybe you're trying to link to the wrong libgcc?

Cygwin gcc is adding an underbar "_" prefix to my symbols. Where can I find documentation on this behavior?

I am trying to compile a gcc project on cygwin for the first time. The build is failing, because an underbar is being prefixed to all symbols. This is causing a symbol mismatch to the GLIB library (installed via CYGWIN package management system) which does not have the leading underbar. Is this tendency to place a leading underbar documented in some place?
Use -fleading-underscore and/or -fno-leading-underscore to get the behaviour you want. This question has a lot of information related to what you're doing.
Cygwin's compiler does this because Visual C++ does. They're trying to minimize the number of needless differences between the two, to aid linking code built with one to code built with the other. There are often other things that prevent you from using Cygwin code with Visual C++ and vice versa, but this isn't one of them.

Resources