Tag Archives: C

Causes and solutions of black frame flashback after debugging visual studio 2017

After debugging, the black box flashes back, and the following error is displayed.

The reason:
Debugging mode at this time, the program will not be suspended, so the window will not continue to open state. So when the black box appears, it goes away.
Solution logic:
Causes the program to pause in a wait state.
Some compilers, such as Visual 6.0, perform this function automatically at the end of code execution.
Solutions:
Method 1: As shown in Figure 1, add a statement before the return statement: system (” pause “); System (” Pause “); Call the system pause command.
,
Method 2: getchar () before the return statement;

Either of the above methods can be used.
So it runs successfully.

The solution of configuring OpenGL in vs2017

I’ve just tried to mesh the sphere using OpenGL in the last two days. The solution to configure OpenGL in VS2017 is as follows:
Running is the link of https://blog.csdn.net/xdg_blog/article/details/52864872 code, the following need library file is also for this code, need to add other library method.
 
1. Download glut in the website, website link: https://www.opengl.org/resources/libraries/glut/.

2. The downloaded file is as follows:

A. Put the two lib files Glut.lib and Glut32.lib into the directory:
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ Lib \x86
B. Put Glut. DLL and Glut32.dll into a directory: C:\Windows\syswow64
Under 64-bit Windows: 64-bit EXE and DLL are in the directory C :\ Windows \ System32, and 32-bit EXE and DLL are in the directory C :\ Windows \ SYSWOW64. So note that registering a 32-bit OCX or DLL on a Win64-bit system requires copying the 32-bit OCX or DLL to the C :\ Windows \syswow64\ directory. C :\ Windows \ SYSWOW64 \ REGSVR32 XXXXXXXX. OCX or DLL.)
C. In the directory: D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ Include, create a new folder GL and put the header file in GL folder.
3. In VS2017, the configuration is as follows. First create a new C ++ project, then open the toolbar: Project ->; Properties:
A. general – & gt; Character set – & gt; Is not set

B. Linker ->; Conventional – & gt; Add the library directory, add OpenGL library file directory and its own library file directory. Write the path where the two lib files are placed.
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ Lib
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ Lib \x86

C. Linker ->; Input – & gt; Attach dependencies. Add the individual lib files from OpenGL (Glut.lib and Glut32.lib are the only ones added here), separated by English keyboard semicolons.

Note: There are other ways on the web to set: linker ->; System – & gt; Subsystem – & gt; SUBSYSYTEM: WINDOWS. But I’ve tried setting this to not work, so just leave it unset by default. (Although I don’t know why ~
Finally all the way down to determine the configuration of good ~

Vc2010 configuring OpenGL environment

Glut32.Lib Glut32.dll and Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h Glut.h
2, the glut. H in the C:/Program Files/Microsoft SDKs/Windows/AA/Include/gl v7.0 directory; GLUT32. lib: C:/Program Files /Microsoft SDKS /Windows/ V7.0a/lib Glut32.dll is placed in the C:/WINDOWS/system32 directory
3. Create a new empty project in VS2010 and select Win32 Console Project
 
4. Add a.cpp file to the project with the following contents:
# include “stdafx. H”
#include< gl/glut.h>
 
Void myDisplay (void)
{
GlClear (GL_COLOR_BUFFER_BIT);
GlRectf (0.5-0.5 f to 0.5 f, f, 0.5 f);
GlFlush ();
}
Int _tmain(int argc, _TCHAR* argv[])
{
GlutInitDisplayMode (GLUT_RGB | GLUT_SINGLE);
GlutInitWindowPosition (100, 100);
GlutInitWindowSize (400, 400);
GlutCreateWindow (” the first OpenGL program “);
GlutDisplayFunc (& amp; myDisplay);
GlutMainLoop ();
Return 0;
}
5. Set the IDE environment: project->; new Property-> Configuration propertites-> linker-> Input-> Additional dependencies
OpenGL32. lib GLUT32. lib, apply, confirm.
 
 
6. F5, Start Debugging, you should see a window with a white square in the middle.

The language of C__ FILE__ 、__ LINE__ And line

Original link:
 
http://hi.baidu.com/419836321/blog/item/fcf5ceec484681cfb31cb1f7.html
 
 
 
 

__FILE__ is used in C to indicate the filename of the source file in which the statement is written, for example (test.c) :

    #include < stdio.h> int main() { printf(“%s\n”,__FILE__); }

GCC compiler generates a.out. After execution, the output is:

test.c

Compiling results under Windows VC6.0 are as follows:

C :\ Documents and Settings \ Administrator \ Desktop \ Test.c

——————————————————————————————————————————————————————————————————– ————————————————————————–

__LINE__ in C is used to indicate the position of the statement in the source file. Examples are as follows:

    #include < stdio.h>

    main() { printf(“%d\n”,__LINE__); printf(“%d\n”,__LINE__); printf(“%d\n”,__LINE__); };

The program is compiled in Linux with GCC, in Windows VC6.0 under the compilation can pass, the execution results are:

7

8

9

__LINE__ can also be reset with the #line statement, for example:

    #include < stdio.h>

    # line 200 // specify the next row __LINE__ for 200 main () { printf (” % d \ n “, __LINE__); printf(“%d\n”,__LINE__); printf(“%d\n”,__LINE__); };

After compilation and execution, the output is:

202

203

204

——————————————————————————————————————————————————————————————————– —————————————————————————

GCC also supports __func__, which indicates the function, but this keyword is not supported in VC 6.0 under Windows, for example:

    #include < stdio.h> void main() { printf(“this is print by function %s\n”,__func__); }

The output result after compilation is

this is print by function main

Note # “line”, “__LINE__”, “a __FILE__” and “__func__” are case sensitive.

 

Installation of Ubuntu + VTK

Sudo apt-get install libvtk5.2 libvtk5-qt4-dev sudo apt-get install libvtk5.2 libvtk5-qt4-dev
Different Ubuntu versions support different versions of VTK, here is Ubuntu 10.04, followed by QT4 support.
 
two
1. Download source code
Address: http://www.vtk.org/VTK/resources/software.html
The version is the latest
2. Unzip
The tar ZXVF… .
A VTK folder is created in the current directory
3. Install OpenGL
apt-get install mesa-common-dev libgl1-mesa-dev
4. Install ccmake
sudo apt-get install cmake-curses-gui
5.cd VTK
6.mkdir VTK-build
7.cd VTK-build
8.ccmake .. /
9. Press C to start the configuration and set VTK_USE_QT to ON. BUILD_SHARED_LIBS is set to ON
10. Press T to enter detailed setup, then locate QT_QMake_Executable, press ENTER to modify, and change QMAKE
The path of the input, for example:/home/zhang/QtSDK/Desktop/Qt/4.8.0/GCC/bin/qmake. Confirm and press Enter to exit the modification.
11. Press C to check the Settings.
12. Confirm by C.
13. Press G to generate makefile and exit CCMAKE automatically
14.make
15.sudo make install.
 
Add (.pro file) to the project
INCLUDEPATH =/usr/local/include/VTK to 5.10
LIBS + = L/usr/local/lib/VTK – 5.10 \
 
5.2
INCLUDEPATH =/usr/include/VTK to 5.2
LIBS += -L/usr/lib \
Select as needed at the end
-lvtkCommon -lvtksys -lQVTK -lvtkViews -lvtkWidgets -lvtkInfovis -lvtkRendering -lvtkGraphics -lvtkImaging -lvtkIO -lvtkFiltering -lvtklibxml2 -lvtkDICOMParser -lvtkpng -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg -lvtkalglib -lvtkexpat -lvtkverdict -lvtkmetaio -lvtkNetCDF -lvtksqlite -lvtkexoIIc -lvtkftgl -lvtkfreetype -lvtkHybrid
 
Command line compilation
G + + – o Cylinder – O3 – I/usr/include/VTK – 5.2 – L/usr/local/lib – Wno – deprecated – lvtkCommon lvtkDICOMParser – lvtkexoIIc – lvtkFiltering – LVTKFTGL – lvtkGenericFiltering lvtkGraphics — lvtkHybrid -lvtkImaging -lvtkIO -lvtkNetCDF -lvtkRendering -lvtksys -lvtkVolumeRendering -lvtkWidgets Cylinder.cxx
 
 

VTK (1) — compile and install

Project environment: QT+VTK+ CMAKE


The file packages used in this article are:

    visual studio 2013
    DXSDK_Jun10
    Cmake – 3.3.2 rainfall distribution on 10-12 – win32 – x86
    Qt5.7
    Qt – v – system.addin – 1 – opensource
    TBB (Thread Building Blocks)
    VTK 7.1

1. Install Visual Studio 2013 Community

    Download https://www.visualstudio.com/downloads/download-visual-studio-vs
    Select Visual Studio 2013 ->; Community 2013
    Download and install community default locations and default optional features (takes about half an hour to complete)

There is an unhandled exception at: 0xc0000005: an access conflict occurred while reading location 0x00000000.

turn
First, exclude a small probability event that is caused by system conflict. For example, if there is a similar third-party library file in the system disk directory, the program will crash and report an error of 0xC0000005: access conflict occurs when reading position 0x00000000.
You’re paying a value to a variable that shouldn’t be assigned, or you’re paying a value to a variable (or constant) that can’t be paid.
(1) The simplest and most straightforward error is probably the problem with scanf(). We all know that scanf(“% format “,& Variable), then in addition to the string (you can call & , but not), all input is required & If you lose it, you won’t be able to find it on many compilers when it’s mutated, meaning it’s not wrong, but the reason why it’s wrong is because the input data is written as scanf(“% format “, variable), so you don’t know where the input variable will be stored.
(2) Null pointer assignment.
We know that if a pointer is empty can’t directly to his assignment, the reason is null Pointers don’t know what the dow was, so he has no fixed memory, now you give his assignment, popular point to understand is that he don’t know how to save, also don’t know what there is, will not be stored, but now you have a need to let him storage, then it will appear afore-mentioned problems, then the solution is to apply for space (using malloc or new), or you try to avoid him to become a null pointer, or when he has become the possibility of a null pointer, you can discuss separately.
Here are a few examples of what is possible:

int * p = 0;
int * p = 0;
p[0] = 100;
of course, it can’t be that obvious in actual code, this is just one example, may be similar, this is you have a good look at yourself, the above 0 and NULL is actually the same, that is, NULL pointer assignment.

a=(double*)malloc(sizeof(double)*6);
h =…
a[0]=h;
First of all you don’t know if malloc is going to succeed or not and if it fails it happens to return NULL and normally you can allocate this amount of memory and it won’t fail but as you said after a couple of loops you might not be free or you might run out of memory or you might fragment and malloc fails and you don’t know so the exact problem is that you assign a NULL pointer to an exception
The following three Pointers are available online: You can compare them with your own:

1:
ar *p;
p = new char[number];
delete [] p;

// always using p…
p = xxx; // access violation
2:
char *p;
memcpy(p, xxx, number); // access violation
3:
char *p;
p = new char[number];
delete [] p;

delete [] p; // access violation
0xC0000005: Access Cheesecake error debug —
Add a word:
No problem (1) compile time
(2) the runtime is a loop calculation, set breakpoints, before a few cycle are no problem, to which a certain cycle (end of cycle conditions have not reached) will appear these problems.
You must be assigning the null pointer somewhere in the middle of the step.
(3) Array or pointer out of bounds
As long as it is related to memory is basically possible, of course, array or pointer out of bounds, this is also very common, this will not give examples, I believe that everyone can understand what consciousness, also know how to solve, this requires you to be more careful and careful.

VTK series: installation and introduction of VTK

Due to the need to do some three-dimensional things, learn some D3D, this thing is too low-level, what function should be realized by their own, then found the VTK toolkit, in the industry response is good, and there is a.NET version, so I decided to try.
I use VS2008, there are a lot of tutorials on the Internet, according to the tutorial to do, to the end of the toolbox are VTK controls, full of joy thought that can be successful, drag a control up a debug results prompt that the specified module can not be found. I can follow the tutorial but still make mistakes is a little puzzled. The net searched for a long time, still did not solve, want to despair. I saw a friend’s QQ in the Visualization Lab forum, added him, he is very nice, asked questions immediately back to me, the key is to help me to solve the problem. In the heart that thank ah, I can not say. The main problem is to put all the downloaded DLLs under the program’s “dubug” and it will work fine. There is a problem with the VTK control that is pulled from the Toolbox. The first time it is displayed, the form will not load when the project is closed and the second time it is opened. This problem is not solved.
After several days of hard work, I finally saw a HelloWord program. Everything is difficult at the beginning, so I can only take it slowly.
Here are a few good links, a good tutorial to get started with VTK.
http://ooplab.org/post/624.html VTK installation tutorial, which also have a step to c:/VTK file to add to the system environment variables.
http://www.cadcaecam.com/Forum/viewthread.php?tid=14832& extra=& page=1
C3P forum, but only wrote a small part of it.
http://hi.baidu.com/ophir/blog/category/%D7%CA%D4%B4%CF%C2%D4%D8%C7%F8 is good too.
Thanks to the articles written by these authors, it is really a great help for beginners.

The corresponding solutions to the problems of various external symbols that cannot be resolved

When using a VS2008 debugger, it is common to have problems with external symbols that cannot be resolved. There are many possible reasons. Here are some of the things I have learned over the past year.
For reference only.
 
Consider possible reasons:
[0] can’t parse may be because the.lib file is not correct, such as a 64 – bit compiler configuration, the results using the 32-bit lib package.
[1] is only to write a class declaration, but I haven’t write the implementation class, causing a call cannot resolve
[2] declaration and definition is not regulated, cause inconsistent links, cannot resolve
[3] is not in the project properties page of the linker command line options to join the corresponding class package.
[4] in the c + + contains, to join the corresponding class package repository directory path
[5] file directory to be tested in test engineering of measured classes may need to include the CPP definition file
[6] ICE interface test, cannot resolve may be because the file is not being measured include relevant CPP file, in addition, in TestSuite_ProjectRun. H file needs to contain IProjectRun. H header file, and the relevant header files (for example).
[7]import related contents cannot be resolved, the solution is to add the corresponding dynamic library in the linker dependencies
[8] The following error is usually caused by the fact that the dynamic library does not have a package. __imp
ProjectRun. Obj: error LNK2019: cannot resolve __imp__StartHistoryLocalModule external symbols, the symbol in the function “protected: virtual int __thiscall HiRTDB: : CProjectRun: : DoStart (void)” (?DoStart@CProjectRun @hirtdb @@maehxz)
[9] ERROR LNK2001: __imp___CrtDbgReportW
project properties, C/C++, code generation, runtime library select MDD,
[9] cannot resolve the external symbol “__declspec (dllimport) public: int __thiscall HiRTDB: : CTagTree: : GetObjectA (int, struct HiRTDB: : SBaseReadProps const & amp; ,struct HiRTDB::SBaseReadValues &) ” (__imp_?Public: int __thiscall hirtDB :: cStringImpl ::Get(int,struct hirtDB :: sStringReadprops const & ,struct HiRTDB::SStringReadValues &) “(?Get @cStringImpl @hirtdb @@qaehhabusStringReadProps @2 @aausStringReadValues @2@@Z
The reason may be that there are extra options in the project configuration file, please refer to the configuration options of other modules, do not have extra configuration.

OpenGL program running prompt glut32.dll missing problem

Today debug OpenGl source program, compiled through, but a running tips, computer lost glut32. DLL files, not depressed, search under the Internet provide most of the practice are more, copying the file to download this file to C: \ WINDOWS \ system in 32, but did so after found that still doesn’t work, after a long afternoon, suddenly realized that may be about my new WINDOWS 7 system, but also for loading is 64 – bit, then, Try to copy this glut32.dll to your SysWOW64 folder in C:\ Windows, and it will all be OK. Here’s a special note to remind everyone who installed Windows 7 and VC ++ 6.0 to pay attention to it.
PS: When you first start to contact OpenGL, you will inevitably encounter some problems, these problems may have nothing to do with the program, just some compile environment Settings and the installation of header files, special sorting, as follows:
PS: When you first start to contact OpenGL, you will inevitably encounter some problems, these problems may have nothing to do with the program, just some compile environment Settings and the installation of header files, special sorting, as follows:
PS
(1) Copy gult32.dll, Glut. DLL to Windows system system32(if Windows 7 is a 64-bit operating system, it is in C:\ Windows SysWOW64 file)
(2) Copy gult32.lib, Glut. lib to VC lib directory
(3) Copy ULT. H to include\GL of VC

Configuring OpenGL in Visual Studio

This semester to learn the graphics, to use C ++ to write, which is mainly used OpenGL, so first of all, to configure OpenGL in Visual Studio
1. Create a new C ++ console application. File – & gt; New – & gt; project

2. Then click Item ->; Manage the NuGet package

3. Browse here, type NupenGL and search

4. After downloading and installing both of them, import the header file at the beginning of the source program, and you can use it

How to use higher version of OpenGL SDK in windows?

 
 
Now OpenGL has version 3.2, Visual C ++ 2005 comes with OpenGL SDK is version 1.1, want to use the advanced version of OpenGL, go to the OpenGL official website, but that only defines the API standard, there is no implementation, I searched the Internet OpenGL2.0 SDK OpenGL3.0 SDK, but did not find the download address, finally found that is to use the extension library way.
 
Download glew (The OpenGL Extension Wrangler Library), http://glew.sourceforge.net/index.html
 
What’s inside:

├ ─ bin
│ glew32. DLL
│ glewinfo. Exe opengl support is used to view the current system of the graphics card
│ glewinfo. TXT
│ VisualInfo.exe is also used to view some graphics card situation
│ visualinfo. TXT

├ ─ the include
│ └ ─ GL
│ glew. H
│ glxew. H
│ wglew. H

└ ─ lib
Glew32. Lib
Glew32s. Lib
 
 
usage
 
 
1. First refer to the header file
#include < gl/glew.h> // must be put first
#include < gl/glut.h>
 
2. The initialization
// Glew is initialized after glutCreateWindow
GLenum err = glewInit ();
If (GLEW_OK! = err)
{
/* Problem: glewInit failed, something is seriously wrong. */
Fprintf (stderr, “Error: % s/n,” glewGetErrorString (err));
}
Fprintf (stdout, “Status: Using GLEW %s/n”, glewGetString(GLEW_VERSION));
 
 
Note: If you use a graphics card that does not support the advanced version of OpenGL functions, the operation will crash