How to disable Warnings of Visual Studio 2012? - c

I have this error:
error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
and similar errors pop up when I use other old C functions.
My question is: Is there a way that these errors show up like Warnings, without actually preventing the code from compiling ?

You must define _CRT_SECURE_NO_WARNINGS in the preprocessor settings of your project, or #define _CRT_SECURE_NO_WARNINGS at the beginning of your file where you use fopen(). Or just use fopen_s() instead.

Yes, you can simply right click on "YourFile.cpp" file and choose "Properties"; Click on "Configuration Properties" and in the front part choose "No" for "SDL checks". It will consider these errors as warnings in the next compilation.
However you can prevent this property while creating a new project by unticking the "Security Development Lifecycle (SDL) checks" option.
The same for VS2013!

Related

How can I enable debug mode in a dpdk-based application?

I encounter some errors when running a dpdk-based application. I find the error occurs when invoking rte_eth_dev_configure() function provided by dpdk library. The error code is -22. However, I want the application to show more debug information so that I can quickly focus on the error part.
I did RTFM and modified $RTE_SDK/build/.config. I turned RTE_LIBRTE_ETHDEV_DEBUG to be y. But It didn't work. Where does rte_vlog() function put log messages?
Would you like to help me? Any suggestion is appreciated!
You should also change the default log level, otherwise all the debug messages will be compiled out during the compilation, i.e.:
RTE_LOG_LEVEL=RTE_LOG_DEBUG
RTE_LIBRTE_ETHDEV_DEBUG=y
Please also have a look at EXTRA_CFLAGS. You might also want to add the debug symbols and disable optimizations, i.e.:
make EXTRA_CFLAGS="-O0 -g" ...
I add CONFIG_ RTE_LIBRTE_ETHDEV_DEBUG=y to the ${RTE_SDK}/config/defconfig_{RTE_TARGET} config file and rebuild the target. It works.

Adding flags in CodeBlocks compiler [duplicate]

I've been trying to compile a simple multithreaded piece of code I found online in an effort to learn how to multithread.
To run this piece of code I need to use the compiler flags: -pthread and -std=c++0x.
But whenever I try to add the flags the build log doesn't show them being used.
I've tried some generic tips online to get these to work, but none of them worked. Can someone help?
I've tried other advice online to add compiler flags to code blocks, but when I do that and check the build log none of them appear.
Because This Question was marked as Duplicate, even if doesn't have to do with it, because there is about Linker Flag and here is about Compiler Flags, I will post My answer HERE.
You will have to go to Settings -> Compiler... and next you'll have to click on Linker Settings TAB.
On the right side you will see Other Linker Options.
There you have to type -lpthread and press OK.
You may need to click on rebuild after that.
Open your project and then go Project > Build Options > Compiler Flags .
You can tick boxes in the "Compiler Flags" tab, and you can write other options in the "Other Options" tab.
Do one or the other, e.g. don't tick the "-std=c++98" box and also put "-std=c++11" in the Other Options. This will end up in both options being passed to the compiler.
Another option instead of using the "other options" is to create a custom compiler flag. So in addition to a compiler flag, you can specify a linker flag. In the case of the -pthread (which I also was having trouble with) it looked like it needed the linker flag as well, as mentioned by Michi
One can create a new compiler flag by right clicking and selecting the new option
add options: menu->project->properties->Build targets tab->Build options button

"First defined here" error in Eclipse with C

I'm trying to compile a C program using libxml2 in Eclipse. It seems like my code doesn't have problems, but there are errors when I build my project.
The error output is in this screenshot: https://drive.google.com/file/d/0BwV-0_2diIaaQlZHM2Fwa2R0LWc/edit
Before this error, I had an “Undefined reference to” error, but it was because I forgot to link the library libxml2. Now it's the problem in the screenshot. I don't what to do.
[EDITED]
I solved my problem I just need to put -nostartfiles in the linker flags.
I solved my problem I just need to write -nostartfiles in the Linker Flags box :D
To find "Linker Flags" box go to Your Project > Properties > C/C++Build > Settings > GCC C Linker > Miscellaneous
That's it.
Thanks for help.
I don't think your solution is acceptable, I think it will lead to the same problem when your project is executed in other environment (another eclipse configuration, running it from console, etc)
That error occurs when you have defined the same function more than one time in your project, and I bet it's because you have defined the same function you already had in a library.
For example, if I have lib1.h with a function called hello() and then write the same function in your main.c (having that library linked) that problem will occur.
In fact, in your image, I can see "multiple definition of __data_start"
So I think you just have to change the problematic function name and it will be fixed.
In addition, this problem will be caused if you include the same library more than once in your program, but it can be solved using preprocessor (if you are interested in this, google it, since it would be off-topic and make my answer too long)

How can I get Eclipse to index code inside #ifdef .... #endif

I'm using eclipse to work on some c code and it is not indexing code inside conditional compilation blocks like this:
#ifdef USE_FEATURE_A
int feature_a(...) {
some = code(here);
}
#endif
How can I get eclipse to index the feature_a function?
You could tell eclipse that USE_FEATURE_A is defined. Open your project properties and go to the "C/C++ General->Paths and Symbols" page, under the "Symbols" tab click the "Add" button and put USE_FEATURE_A in the name feild and click OK.
Note: this will cause it not to index any #else sides to your preprocessor stuff... so unless they are all like the one in question you can't AFAIK, but if they are they you're good. (Eclipse contains a C preprocessor that it uses to analyize your code all the stuff above does is essentially the same as adding -DUSE_FEATURE_A to your command line so Eclipse's preprocessor will behave differently from the one in your compiler)
This is an easier and in my opinion more elegant solution to the one selected as the solution:
If someone has the same problem (as I had), this can (now?) easily be solved by going to Window->Preference->C/C++/Indexer and enable "Index all header variants".
Then click Project->C/C++ Indexer->rebuild and clean and build your project. This should resolve all error originating from preprocessor commands.
For what it's worth, getting eclipse to parse conditionally compiled code is much harder to do than would appear at first glance. I found a paper on by IBM from 2007 where they said they will prioritize for the "next release".
Handling Conditional Compilation in CDT's Core
I had this same problem, but the code conditionally eliminated by preprocessing was perfectly valid c code and I wanted it formatted... This was my solution:
1) Global find/replace of #if to #JUNKif
2) Ctrl-Shift-F to reformat the source
3) Another global find/replace of #JUNKif to #if
One way to index code under flag in Eclipse(Kepler) c/c++Editor.
You can enable the compilation flags in Eclipse editor so that code under them can be indexed.
Properties > Preprocessor Include Paths > CDT User settings Entries
Click on ADD and add the Preprocessor Macro and you can specify its value.
Best way I guess is to use the Indexer option : Project Properties>C/C++ General>Indexer.
You can choose Enable project specific settings
I prefer choosing "Use active build configuration" so that all files which are actually built in the project are indexed.
Anyhow you can also choose to index all files in the project even if they are not included in the build ...

How do I stop a command prompt from appearing in a Win32 C application?

I really have no idea why this is happening...
I created a win32 application in emacs, and whenever I make it and run it (not through the command prompt), a command prompt window pops up under the window. If I build a win32 application in Code::Blocks, and just run its default template, then it runs without a command prompt window. I looked all through the code of both and can't figure out what might cause this...
I thought it was because I included some printf() statements in there, but I didn't want them to stay there (they were for debugging), so I wrote a macro:
#define DEBUG
in main.c, and
#ifdef DEBUG
#include<stdio.h>
#define DBG printf
#else
#define DBG
#endif
in a header (included after the #define DEBUG of course).
When I undef'd DEBUG, the window still showed up... I don't know what I am doing to make it happen, what sorts of things cause a command prompt window to show up in a win32 application? I tried using all the ****Ex() windows functions instead of just CreateWindow(), etc, but that didn't change anything. I checked and re-checked the class definition and registration, to no avail, and made sure I didn't forget a printf() statement (which would have caused an error even if I did, since stdio.h isn't included unless DEBUG is defined).
This is what I included:
#include<windows.h>
#include<windowsx.h>
#include"main.h"
#include"windowproc.h"
anyone know what can cause this? I even commented out all of my stdio, DBG, printf junk, and it still showed up, and I swear there's no difference between my code and the Code::Blocks generated code, aside from my use of HANDLE_MSG and a few extra functions to split up the code.
Update
I am using MinGW 3.4.5.
using the -mwindows switch worked, thanks
Try linking with the -mwindows switch.
Your program should also have the main method read like so:
int WINAPI WinMain(
....
)
as opposed to the traditional int main().
Related threads:
Why does my QT4.5 app open a console window under Windows?
GCC / C how to hide console window?
Windows makes a difference between "console" and "Windows" applications. Console applications will always be run with an associated terminal.
See this question for details on the differences.
Don't know what compiler you are using but I know GCC needs the -mwindows option to suppress the command line window.

Resources