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

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!!)

Related

How to compile srlua (or a link to the binaries)

Related:
How to compile srlua?
How do I Make an executable Lua script using srlua?
The first link is the exact question I am asking here. However, the sole answer is unsatisfactory as it assumes multiple things, namely that the OP is already using Cmake (a fact disproved by the OP's comment on the answer). The second link seems to already be most of the way through a tutorial, and while a link to precompiled binaries for both srlua.exe and srglue.exe are provided, the link no longer contains binaries but instead the source.
I have found several other threads on various websites all asking the same thing, but all of them either assume that you essentially already know how, or explain nothing (many have potentially helpful links, but they are old and no longer work).
I have already tried to compile srlua, and got a srglue.exe, but when I tried srlua.c I ended up with a list of undefined references (such as "lua_type" or "lua_getfield").
lua_getfield, lua_type, lua_settop, lua_getfield, lua_type, lua_settop, lua_pushstring, lua_pushinteger, lua_call, lua_pushfstring, lua_load, lua_tolstring, lua_tointeger, lua_touserdata, luaL_openlibs, lua_createtable, lua_pushstring, lua_rawseti, lua_setfield, luaL_checkstack, lua_pushstring, lua_call, lua_tolstring, luaL_callmeta, lua_type, lua_type, lua_typename, lua_pushfstring, luaL_newstate, lua_pushcclosure, lua_pushcclosure, lua_pushinteger, lua_pushlightuserdata, lua_pcall, lua_tolstring, lua_close
My question is this:
How does one use a C compiler (I know the basics of gcc) to compile srlua specifically? Or, if anyone has a functioning link to either precompiled binaries or a tool to compile the binaries, could they share it?
Important: I am on Windows. Thus, I cannot just use make. I must actually compile the .c files to .exe files. I am asking how. If you simply provide links to threads with the aforementioned problems, you are not helping. If you give an answer that assumes in-depth prior knowledge of a particular tool that does not have good documentation, you are not being helpful. If you tell me tools to use, but not the specific procedure for compiling srlua, you are not being helpful. If there is a better place for this, tell me and I can move it there.
I don't know any Windows pre-compiled binaries for srLua.
To compile srLua, you should first install the Mingw compiler to use GCC as a C compiler : you can install TDM-GCC (https://jmeubank.github.io/tdm-gcc) or http://winlibs.com.
You can then open a Console prompt. Enter the "gcc" command to be sure that the compiler is working (and that the PATH is correctly set).
Then go to the directory you extracted the srLua source files and type the command :
mingw32-make
Cross your fingers and it should compile everything :)
When linking, you should include the Lua libraries with the -l Switch : -llua54 for Lua 5.4 library for examples.
I found this already compiled release on webarchive, it's kinda old but works:
https://web.archive.org/web/20130721014948/http://www.soongsoft.com/lhf/lua/5.1/srlua.tgz

How to detect that F# program is compiled on Mono?

I am trying to make some F# code conditional based on compile-time environment and can't find any OS-specific definitions that F# compiler would recognise. #if MONO doesn't work. Is there any way to detect OS at compile-time for F#?
I don't think there is any out-of-the box way of doing this. You will need to define your own symbol such as MONO and call the compiler with --define:MONO when building the Mono version.
That said, I would be a bit careful about this - there is no clear concept of "compiled for Mono" in F# and .NET. When you compile F# code, you always get a dll or exe that you can run anywhere and nothing prevents you from copying one build output and running it in another environment.
There is a standard way of detecting where the program is running at runtime using:
Type.GetType("Mono.Runtime") != null
You might have good reasons for wanting two separate builds, but it might be worth considering whether you can just make the appropriate choices at runtime (that probably does not work if you rely on some Windows-specific libraries such as WinForms charting).

How does an ide compile code?

Thinking about NetBeans or Eclipse I was wondering how an IDE compiles code when you click run. Does it open a command line in the background to compile it? How exactly does it work?
Each IDE will have it's own approach for how they actually achieve compilation. Usually they will have their own compilers or wrappers around existing compilers to which they delegate actual compilation.
Eclipse comes with a built in compiler of its own:
How does Eclipse compile classes with only a JRE?
I don't actually personally know much about how other ones achieve the compilation in any detail; somebody else may provide a better answer in that regard.
IDEs use compilers. That's actually the difference between them.
For instance, Code::Blocks uses MinGW Compiler which is a port of the GCC set of compilers.
Every compiler has its own method, some use their own wrappers and ports for known compilers. (See Codeblocks)
I also noticed that some basic IDEs out there, just run the simple command line using gcc, clang, etc and let you pass parameters from an option window.

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.

Compiling libexif as static lib with Visual Studio 2010 - then linking from Visual C++ project

Is it possible to compile libexif with Visual Studio 2010? I have been trying to do so and have been running into a whole slew of problems. I cannot find any information about whether anybody has successfully done this before. I know I can use MinGW to compile the library, but I am in a situation where I need it to be compiled with Visual Studio and then need to link to it from a Visual C++ app. Is this possible?
To answer your question: Yes it is possible... but it is a bit of a hack. Libexif uses functions that MSVC has chosen not to implement. See my working example VS2010 project below (if you don't like downloading files then skip to my explanation of what needed changing to get it to work below):
https://www.dropbox.com/s/l6wowl8pouux01a/libexif-0.6.21_CompiledInVS2010%2BExample.7z?dl=0
To elaborate, the issues that needed a "hack" (as hinted in the LibExif readme-win32.txt documentation) are:
Libexif uses inline in several places which is not defined in VS for C, only C++ (see this)
Libexif uses snprintf extensively in the code which is not defined in VS (see here)
You need to create the config.h yourself without a ./configure command to help you. You could read through the script but most of it doesn't make sense for Windows VS2010.
You will need to define GETTEXT_PACKAGE because it's probably setup in the configure file. I just choose UTF-8, whether that is correct or not I'm not sure.
There was a random unsigned static * that needed to be moved from a .c file to the .h file as C in VS doesn't allow you to create new variables inside functions in the particular way they were trying to do.
Read the "readme-win32.txt" file. Advice is:
hack yourself a build system somehow. This seems to be the Windows way of doing things.
Don't get your hopes up. The *nix way of doing things is the configuration script that needs to be run first. It auto-generates source files to marry the library to the specific flavor of *nix. The configuration script is almost half a megabyte. Three times as much code as in the actual .c files :) You cannot reasonably get that working without MinGW so you can execute the script. Once you got that done, you've got a better shot at it with a VS solution. As long as it doesn't use too much C99 specific syntax.

Resources