jeudi 25 juin 2015

How to extract the source filename without path and suffix at compile time?

Using both gcc with -std=c11 and g++ with -std=c++14.

E.g. for a file named src/dir/Hello.cxx it should expand to something like e.g.:

const char basename[] = "Hello";

or

const char basename[] = getStaticBasename(__FILE__);

as were getStaticBasename() is a macro (for C sources) or constexpr function (for C++ sources) which results to "Hello".

I have to avoid splitting the string from __FILE__ at runtime, because the path and suffix must not be compiled into the executable in any way.

The solution must be without dependencies to huge libraries such as boost.

As I have no makefiles, solutions like this cannot be used in my case.

Did one have a solution for that?

Aucun commentaire:

Enregistrer un commentaire