Pragma ignoring comment [-Werror=unknown-pragmas] - c++

I'm trying to make function which will return version from FileVersionInfo,
so far i built funtcion, but i have issue when i want to include version.lib
#pragma comment(lib, "version.lib")
I have tried to link, libversion.a, something like this
#pragma comment(lib, "libversion.a")
but, again compiler was returning error like first time
Pragma ignoring comment [-Werror=unknown-pragmas]
I have tried, many combinations from internet, i cant even remember all of them. I'm using MinGW compiler.
Thanks for your time i appricitate it :)

"This pragma to link libraries from C++ source code is only supported by MSVC"
Switched compiler from gcc/g++ to MSVC, that's only solution :(

Related

win32++ library sample code results in undefined reference error

I know I asked this yesterday already but the suggested solution in this thread:
error LNK1120: 1 unresolved external - VS13 C
Did not work :/
I am getting this error:
CMakeFiles\testproject.dir/objects.a(main.cpp.obj): In function
`Win32xx::LoadCommonControls()':
PATH/lib/Win32xx891/include/wxx_wincore.h:2844: undefined reference to
`__imp_InitCommonControls'
PATH/lib/Win32xx891/include/wxx_wincore.h:2849: undefined reference to
`__imp_InitCommonControls'
while trying to run example code from the win32++ library. I have tried adding
#pragma comment(lib, "comctl32.lib")
To my header as was suggested in the thread I mentioned but that didn't work. They also said that you can solve it by linking the comctl32 library, which appearently isnt loaded and causes the issue, by adding -L -lcomctl32 to my program arguments (I think thats how to do it, correct me if im wrong). That didnt help either. If you know what the problem is please help me.
EDIT:
steps:
create project (c++ 14)
download win32++ library files
add them with cmake (I called include_directories(), is that enough?)
https://pastebin.com/w59ibVEZ
run program with "-lcomctl32" as program argument
rip
#pragma comment(lib, "comctl32.lib") is for MSVC, it doesn't do anything in MinGW (or GCC for that matter).
Symbol InitCommonControls is defined in libcomctl32.a which comes with MinGW, so you just need to link against by using linker flag -lcomctl32.
Make sure to tell CMake it's a linker flag and not a compiler flag.

Why some top level competitive programmers use #pragma?

why they use this before#include<bits/stdc++.h>
mainly I've been using #include ...
Now I'm seeing these lines on a cpp program so I became curious.
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("Ofast")//Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
These are indications to the compiler to change its behaviour as if you had passed the equivalent command line flags. For programming competitions, you often submit source code rather than a binary - it's then built and tested using a system you don't control (and can't set the command line on). Putting these settings in as #pragma lines lets you control settings you might not otherwise be able to do in the competition environment.

Turn warnings into error only within supplied diff

At a company I used to work at, the build system was set up to turn warnings into errors only within changed code. It worked by supplying generating a diff (typically between the branch you were trying to merge and master and then supplying that diff to some compilation tool, and the tool would produce warnings only within the supplied diff.
This was great as it allowed you to e.g. deprecate some function, and have the build system prevent people from introducing new uses of that function, and then remove old usages of that function later.
Unfortunately, I didn't look at the setup closely enough before I left the company, and don't know how to replicate it. My question: How can I replicate this setup?
Question is tagged Clang but I would also be interested in answers that use tooling from other compilers.
If I had to implement that, my first idea would be:
Get merged file.
Analyze diff to figure out which regions were changed.
Generate a new file and inject #pragma directives1 that locally enable/disable warnings around the changed regions.
Also inject #line directives to make it look like warnings/errors are coming from the original file.
Compile modified file and save compiler warnings/errors.
Delete modified file.
Present compiler diagnostics to the user.
1 E.g. https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas for GCC.
Clang supports GCC's #pragma diagnostic.
For example:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
// ... changed code here ...
#pragma GCC diagnostic pop
MSVC also has something similar:
#pragma warning(push, 3)
// ... changed code here ...
#pragma warning(pop)

Is there a GCC pragma to switch C++11 on and off?

I have some headers that fight with C++11 but I'd like to use features like initializer lists in my code. My research says that you can enable newer features at the command-line only, like:
g++ -std=c++11
What I'd really like is to put in my code:
#pragma CXX11_OFF
#include <old.hpp>
#pragma CXX11_ON
vector<int> v {1,2,3};
I haven't been able to find such a pragma. Does it exist?
No. Such a pragma does not exist.
You can find a list of all pragmas GCC supports in ยง 6.61 of the manual.
#pragma GCC diagnostic warning "-std=c++11"
This line adds a cpp 11 flag to compiler.
I don't know if there exists such a pragma. But turning C++11 on and off during the same compilation unit looks akward to me. Perhaps you should place the "old" part inside a dll and import it then in the "new" part. Then you can only compile the new part with c++11 enabled
Since such a pragma does not exist, my suggestion is to rely on make/cmake for picking the "right" files based on a compilation flag.

C++ Disabling warnings on a specific include

I'm wondering if there's a way to disable all warnings on a specific file (for example, using a preprocessor directive).
I'm using CImg.h and I want to get rid of the warnings involving that code.
I'm compiling both with VS (the version for Windows) and gcc (the Linux one), so I would like to have a generic way...
Thanks!
You can do it using #pragma in Microsoft compiler:
http://msdn.microsoft.com/en-us/library/2c8f766e%28VS.80%29.aspx
Something like this:
#pragma warning (push, 0)
//....header file
#pragma warning (pop)
Can't help you with gcc compiler, some info here: Selectively disable GCC warnings for only part of a translation unit?
EDIT EDIT Try push, 0.
Look into #pragma warning.