user3340553
user3340553

Reputation: 11

Define compilation flags (C++11 and optimization) via macro

I want for my program to use C++11 standard and O3 optimization. Normally I would just use compilation flags: -std=c++11 and -O3, but I have to send sourcefile to a remote server where it is compiled automatically. So basically the only thing that comes to my mind is to use some neat macro. I am pretty sure it is possible to define optimization that way cause I saw it somewhere, but still I cannot remember how it looked like.

Upvotes: 1

Views: 499

Answers (1)

What you're asking for is outside the C++ spec.

So if it were supported at all--anywhere--it would be supported via pragmas. I don't know of any pragma to say "compile as C++11", so I'd call that a lost cause. There do seem to be some optimization pragmas out there:

http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

But bear in mind that using a #pragma is entirely outside of the spec. If the compiler hits one, it can do anything it likes and still be standard. That includes launching video games (and this has been done)

So long story short: if this is a requirement for you, then you need to tell whoever this is providing your compilation service that you need certain compiler settings for your program.

Upvotes: 3

Related Questions