Microsoft Visual C++
마이크로소프트 비주얼 C++(Microsoft Visual C++, 줄여서 MSVC)은 마이크로소프트사가 C, C++, C++/CLI 프로그래밍 언어 도구로 계획한 통합 개발 환경 (IDE) 제품이다. 개발 및 C++ (특히 마이크로소프트 윈도 API, 다이렉트X API, 닷넷 프레임워크로 작성된 코드)의 디버깅을 위한 도구를 가지고 있다.
Category
- Windows Api
- Visual Studio
- VisualStudio:Warning
- VisualStudio:Optimization
- Dynamic Library
- Windows Registry
- VisualStudio:CommandPrompt: Visual Studio 도구 모음을 사용할 수 있는 Command Prompt에 대한 설명.
- Name mangling
Commandline build
cl.exe
Example
아래와 같이 컴파일 할 수 있다. (*.obj
파일을 출력한다.)
cl.exe \
/wd"4819" \
/I"C:/Users/user/Project/opencv-x64/build/include" \
/D "NDEBUG" \
/c \
main.cpp
주의할 사항은 명령행 옵션은 대소문자를 구분한다. /C
와 /c
는 다르다.
ERROR
- C2360
- 'value' 초기화가 'case' 레이블에 의해 생략되었습니다.
- case 문 내에서 선언된 로컬변수 때문에 발생하는 오류이다. 할당된 영역이 실행 로직에 따라 가변적이므로 컴파일 시 스택 영역의 크기를 알 수 없기 떄문에 발생하는 오류. case 문 내에서 선언 및 초기화를 할 때애는
{}
를 사용하면 해결된다.
lib.exe
link.exe
Example
아래와 같이 DLL을 만들 수 있다.
link.exe \
/OUT:"C:\Users\user\Project\americano\build\Release\pyamericano.dll" \
/LIBPATH:"C:/Users/user/Project/americano/build" \
/DLL \
/MACHINE:X64 \
/SUBSYSTEM:CONSOLE \
"oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" \
src1.obj src2.obj
dumpbin.exe
Microsoft COFF Binary File Dumper(DUMPBIN.EXE)는 COFF(공용 개체 파일 형식) 이진 파일에 대한 정보를 표시합니다. DUMPBIN을 사용하여 COFF 개체 파일, COFF 개체의 표준 라이브러리, 실행 파일 및 DLL(동적 연결 라이브러리)을 검사할 수 있습니다.
ToggleHeaderCodeFile
- Stackoverflow: Is there a shortcut to move between header and source file in VC++?
- Extending Visual Studio Part 2 - Creating Addins
- Visual Studio > Tools > Switch > Switch DWM Kerr
- [추천] Visual Studio Macro to switch between CPP and H files
I’ve been doing a lot of managed C++ programming lately and I had forgotten what a pain it is switching back and forth between the header file and source file. Back in the days of Visual Studio 6 I had a macro that switched between the CPP and H file, so I went googling, but the macro I found didn’t work very well in VS2008. Like any good coder, I decided to write it myself instead.
If you haven’t written a macro before, here are the steps.
- In Visual Studio, go to Tools | Macros | Macros IDE. A new window should open and in the Project Explorer, the MyMacros project should be open.
- Right click on the MyMacros project and select Add | Add Module. Name it CppUtilities. The CppUtilities should open in the editor window.
- Add the code from below into the module and save the project.
‘=====================================================================
‘ If the currently open document is a CPP or an H file, attempts to
‘ switch between the CPP and the H file.
‘=====================================================================
Public Sub SwitchBetweenSourceAndHeader()
Dim currentDocument As String
Dim targetDocument As String
currentDocument = ActiveDocument.FullName
If currentDocument.EndsWith(“.cpp”, StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = Left(currentDocument, Len(currentDocument) - 3) + “h”
OpenDocument(targetDocument)
ElseIf currentDocument.EndsWith(“.h”, StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = Left(currentDocument, Len(currentDocument) - 1) + “cpp”
OpenDocument(targetDocument)
End If
End Sub
‘=====================================================================
‘ Given a document name, attempts to activate it if it is already open,
‘ otherwise attempts to open it.
‘=====================================================================
Private Sub OpenDocument(ByRef documentName As String)
Dim document As EnvDTE.Document
Dim activatedTarget As Boolean
activatedTarget = False
For Each document In Application.Documents
If document.FullName = documentName And document.Windows.Count > 0 Then
document.Activate()
activatedTarget = True
Exit For
End If
Next
If Not activatedTarget Then
Application.Documents.Open(documentName, “Text”)
End If
End Sub
If you switch back to Visual Studio and open the Macro Explorer, you should see the new module CppUtilities and the new macro SwitchBetweenSourceAndHeader in the tree. You could run the macro from here, but it is much easier to bind it to a keystroke.
- Click on Tools | Options then go to the Environment | Keyboard tab.
- In the Show commands containing: box, type CppUtilities. This should filter the list down to one entry, Macros.MyMacros.CppUtilitities.SwitchBetweenSourceAndHeader.
- Click on the Press shortcut keys: text box and then press the keystroke you would like to use to run the macro. If the keystroke is already used, it will show you below in the Shortcut currently used by: dropdown. When you find one that is unused, click the Assign button to use it. I use Ctrl+Shift+Alt+Bkspce.
- Click OK then open a CPP or H file and give it a try.
Debugging
Release mode debugging
Release에서 디버깅 정보를 삽입하는 방법은 아래와 같다.
-
Property Page -> Configuration Properties -> C++ -> General -> Debug Information Format (/Zi)
-
Property Page -> Configuration Properties -> C++ -> Optimization -> Optimization (/Od)
-
Property Page -> Configuration Properties -> Linker -> Debugging -> Generate Debug Info (/DEBUG)
Export symbols
Export STL
- [추천] How to export an instantiation of a Standard Template Library (STL) class and a class that contains a data member that is an STL object 1
Favorite site
Command-line helper
- MSDN: /w, /Wn, /WX, /Wall, /wln, /wdn, /wen, /won (Warning Level)
- command line cross-compiling X86, X64 and IA64 with Visual Studio 2005 2
- Compiling and Linking: Simple Example with Visual C++
- Stackoverflow: How could I create a static library using visual stdio tools on the command line and automate .def creation