프로젝트 속성에서 C/C++ > 일반 > 경고 수준을 올려서 빌드하면 라이브러리 단에서도 경고가 발생한다.

#pragma warning(disable : 4365)

수정할 수 없는 라이브러리에서 발생하는 경고를 무시하고 싶을 때 VS 에서는 pragma warning 전처리기를 사용한다. 위와 같이 '#pragma warning(disable : xxx)' 형식으로 무시하고 싶은 경고 코드를 적어주면 된다.

unity build 를 사용하거나 header 파일에 위와 같은 선언이 있을 경우 원하지 않는 파일에도 적용될 수 있다. 

#pragma warning(push)
#pragma warning(disable:4565)

...

#pragma warning(pop)

위와 같은 문제를 막기 위해 적용되어야 하는 영역을 push, pop 으로 막아줘야 한다.

참고 : https://docs.microsoft.com/en-us/cpp/preprocessor/warning?view=msvc-170 

 

warning pragma

Learn more about the warning pragma in Microsoft C/C++

docs.microsoft.com

https://www.fluentcpp.com/2019/08/30/how-to-disable-a-warning-in-cpp/

 

How to Disable a Warning in C++

Expressive code in C++

www.fluentcpp.com

linux 로도 빌드되는 코드의 경우 위 문서를 참조해보자.

728x90
$ tree --help
usage: tree [-acdfghilnpqrstuvxACDFJQNSUX] [-H baseHREF] [-T title ]
        [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version]
        [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst]
        [--charset charset] [--filelimit[=]#] [--si] [--timefmt[=]<f>]
        [--sort[=]<name>] [--matchdirs] [--ignore-case] [--fromfile] [--]
        [<directory list>]
  ------- Listing options -------
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -R            Rerun tree when max dir level reached.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  --ignore-case Ignore case when pattern matching.
  --matchdirs   Include directory names in -P pattern matching.
  --noreport    Turn off file/directory count at end of tree listing.
  --charset X   Use charset X for terminal/HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.
  --timefmt <f> Print and format time according to the format <f>.
  -o filename   Output to file instead of stdout.
  ------- File options -------
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -Q            Quote filenames with double quotes.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  --si          Like -h, but use in SI units (powers of 1000).
  -D            Print the date of last modification or (-c) status change.
  -F            Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  ------- Sorting options -------
  -v            Sort files alphanumerically by version.
  -t            Sort files by last modification time.
  -c            Sort files by last status change time.
  -U            Leave files unsorted.
  -r            Reverse the order of the sort.
  --dirsfirst   List directories before files (-U disables).
  --sort X      Select sort: name,version,size,mtime,ctime.
  ------- Graphics options -------
  -i            Don't print indentation lines.
  -A            Print ANSI lines graphic indentation lines.
  -S            Print with CP437 (console) graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -C            Turn colorization on always.
  ------- XML/HTML/JSON options -------
  -X            Prints out an XML representation of the tree.
  -J            Prints out an JSON representation of the tree.
  -H baseHREF   Prints out HTML format with baseHREF as top directory.
  -T string     Replace the default HTML title and H1 header with string.
  --nolinks     Turn off hyperlinks in HTML output.
  ------- Input options -------
  --fromfile    Reads paths from files (.=stdin)
  ------- Miscellaneous options -------
  --version     Print version and exit.
  --help        Print usage and this help message and exit.
  --            Options processing terminator.

터미널에서 여러 디렉토리 돌아다니며 확인할 때 매우 귀찮다. 

$ tree -d logs
logs
└── 2022
    ├── 04
    │   └── 30
    └── 05
        ├── 01
        ├── 02
        ├── 03
        ├── 04
        └── 05

9 directories

예를 들어 s3 에 일별로 있는 로그 파일을 복사해 오는 스크립트를 짰을 때 각 폴더가 제대로 생성되었는지 확인하려면 일일이 cd - ls 를 이용해서 확인해야 한다. 

그나마 tree 명령어를 이용하면 한눈에 보여서 좋다.

https://www.cyberciti.biz/faq/linux-show-directory-structure-command-line/

 

728x90

linux 에서 문자열 치환(replace) 하고 싶을 때는 sed 를 사용한다.

$ sed --help
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

  -n, --quiet, --silent
                 suppress automatic printing of pattern space
      --debug
                 annotate program execution
  -e script, --expression=script
                 add the script to the commands to be executed
  -f script-file, --file=script-file
                 add the contents of script-file to the commands to be executed
  --follow-symlinks
                 follow symlinks when processing in place
  -i[SUFFIX], --in-place[=SUFFIX]
                 edit files in place (makes backup if SUFFIX supplied)
  -b, --binary
                 open files in binary mode (CR+LFs are not processed specially)
  -l N, --line-length=N
                 specify the desired line-wrap length for the `l' command
  --posix
                 disable all GNU extensions.
  -E, -r, --regexp-extended
                 use extended regular expressions in the script
                 (for portability use POSIX -E).
  -s, --separate
                 consider files as separate rather than as a single,
                 continuous long stream.
      --sandbox
                 operate in sandbox mode (disable e/r/w commands).
  -u, --unbuffered
                 load minimal amounts of data from the input files and flush
                 the output buffers more often
  -z, --null-data
                 separate lines by NUL characters
      --help     display this help and exit
      --version  output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret.  All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
use test_<suffix>;

create table tbl_test
(
);

위와 같은 create script 에서 <suffix> 만 바꿔서 돌리고 싶은 경우가 있다.

$ sed "s/<suffix>/01/g" test.txt
use test_01;

create table tbl_test
(
);

s/[기존 문자열]/[변경 후 문자열]/g 를 입력하면 test.txt 를 읽어 [기존 문자열] 을 [변경 후 문자열] 로 바꾸어 출력해 준다.

$ sed "s/<suffix>/01/g" -i test.txt

$ cat test.txt
use test_01;

create table tbl_test
(
);

-i 파라미터를 사용하면 입력 파일을 바로 바꾼다.

$ sed "s/<suffix>/01/g" -i.bak test.txt

$ ls test*
test.bat  test.txt  test.txt.bak

-i 뒤에 문자열을 입력하면 해당 확장자로 파일을 백업하고 치환 작업을 진행한다.

http://fart-it.sourceforge.net/

 

FART: Find And Replace Text

 

fart-it.sourceforge.net

참고로 윈도우즈 에서는 fart (Find And Replace Text) 라는 프로그램이 있다.

 

728x90

ssh 로 서버 작업을 하다 보니 vi 를 많이 쓸 수 밖에 없다. :( 파일 업로드도 자유롭지 않아서 copy & paste 로 스크립트를 옮겨야할 경우가 많은데 기존 내용을 지우고 복붙해야 한다. 

vi 에서 전체 내용을 지우려면 첫번째 줄로 가서 dG 를 입력하면 된다.

출처 : https://elisom.tistory.com/entry/vi-vim-%EC%A0%84%EC%B2%B4-%EB%82%B4%EC%9A%A9-%EC%A7%80%EC%9A%B0%EA%B8%B0

 

[vi, vim] 전체 내용 지우기

vim의 입력모드가 아닌 ESC를 누른 일반 모드에서, dd: 첫번째 줄로 이동 Shift + v + g: 전체 선택 d: 전체 삭제 혹은 dd: 첫번째 줄로 이동 dG: 현재 라인부터 마지막 라인까지 삭제 를 이용하여 전체 삭

elisom.tistory.com

 

728x90

라인 수가 궁금할 때는 wc 를 사용하면 된다.

$ wc --help
Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  A word is a non-zero-length sequence of
characters delimited by white space.

With no FILE, or when FILE is -, read standard input.

The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
  -L, --max-line-length  print the maximum display width
  -w, --words            print the word counts
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Full documentation <https://www.gnu.org/software/coreutils/wc>
or available locally via: info '(coreutils) wc invocation'
$ wc -l test.txt
1 test.txt

위와 같이 -l, --lines 옵션을 사용하면 된다. 

$ cat test.txt
ab cd
aa
$ wc -l test.txt
1 test.txt

주의할 점은 줄바뀜을 센다는 거다.

$ grep -Hc ".*" test.txt
test.txt:2

grep -Hc 옵션을 사용하는게 원하는 결과에 가깝다. 😕

참고 : https://www.thegeekdiary.com/how-to-count-lines-in-a-file-in-unix-linux/

 

How to Count lines in a file in UNIX/Linux – The Geek Diary

 

www.thegeekdiary.com

 

728x90

mssql 쓸 때는 ssms(sql server management studio) 라는 툴만 사용해서 몰랐는데 mysql 에 console 로 작업하려니 죽을 맛이다. 물런 mysql 도 workbench 나 유료 툴인 sqlyog 이 있지만 서버 장비에 작업 pc 로 vpn 이용하더라도 접근할 수 없다. :(

시간이 오래 걸리는 쿼리를 돌렸는데 mysql 프로세스는 열일 중이었지만 어떤 상태인지 궁금했다. mysql process 상태를 볼 때는 show processlist 를 사용한다.

mysql> show processlist;
+----+------+----------------+------+---------+------+----------+------------------+
| Id | User | Host           | db   | Command | Time | State    | Info             |
+----+------+----------------+------+---------+------+----------+------------------+
|  7 | root | localhost:6576 | NULL | Sleep   |  122 |          | NULL             |
|  8 | root | localhost:6577 | NULL | Sleep   |  122 |          | NULL             |
|  9 | root | localhost:7356 | NULL | Query   |    0 | starting | show processlist |
+----+------+----------------+------+---------+------+----------+------------------+
3 rows in set (0.00 sec)

쿼리를 실행하면 State 와 Info 를 통해 상태를 확인할 수 있다. 여러 줄의 쿼리일 경우 Info 에 실행중인 쿼리가 표시된다.

728x90

https://docs.microsoft.com/en-us/windows/wsl/install

 

Install WSL

Install Windows Subsystem for Linux with the command, wsl --install. Use a Bash terminal on your Windows machine run by your preferred Linux distribution - Ubuntu, Debian, SUSE, Kali, Fedora, Pengwin, Alpine, and more are available.

docs.microsoft.com

윈도우즈 10 부터 wsl 이라고 linux 를 윈도우즈에서 가상머신으로 실행할 수 있게 되었다.

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.26.0.1

wsl 내에서 host 윈도우즈의 mysql 과 같은 서비스에 접근하려면 host os 의 ip 를 알아야 하는데 고정된 ip 가 아니다. host 윈도우즈의 ipconfig 명령에서 WSL 목록이나 etc/resolv.conf 의 nameserver 항목을 통해 ip를 확인할 수 있다.

export WSL_WINDOWS_HOST=`cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f 2`

고정시킬 수도 있지만 위와 같은 스크립트를 통해 host os 의 ip 를 확인할 수 있다. .profile, .bash_profile, .bashrc, .zshrc, .zprofile 과 같은 사용하는 쉘 초기화 스크립트에 넣어두면 유용하게 쓸 수 있다.

출처 : https://github.com/Microsoft/WSL/issues/1032

 

How to access host ip and port? · Issue #1032 · microsoft/WSL

I am using bash on windows 10. i want to access host ip:port there be service listen on 0.0.0.0:80 of host windows 10. how do i access to host windows 10 port?

github.com

 

728x90

https://en.wikipedia.org/wiki/Unity_build

 

Unity build - Wikipedia

In software engineering, a unity build (also known as unified build or jumbo build) is a method used in C and C++ software development to speed up the compilation of projects by combining multiple translation units into a single one, usually achieved by us

en.wikipedia.org

Unity 빌드(Jumbo 빌드) 는 컴파일 시간 최적화 방법 중 하나다. 개별 cpp 파일을 묶어서 컴파일해서 중복해서 처리되는 비용을 줄이는 방법이다.

예전에는 컴파일 전에 수동으로 Unity 빌드 파일을 만들어 주는 스크립트를 돌렸는데 Visual Studio 는 옵션으로 제공하고 있다. 프로젝트 속성 > 구성 속성 > 고급 > Unity(JUMBO) 빌드 사용을 설정해주면 된다.

https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html

 

UNITY_BUILD — CMake 3.23.1 Documentation

UNITY_BUILD When this property is set to true, the target source files will be combined into batches for faster compilation. This is done by creating a (set of) unity sources which #include the original sources, then compiling these unity sources instead o

cmake.org

사용해본 적은 없지만 cmake 에서도 UNITY_BUILD 옵션이 있다.

fatal error C1128: 섹션 수가 개체 파일 형식 한도를 초과했습니다. /bigobj를 사용하여 컴파일하십시오.

여러 파일을 묶어서 빌드하다 보면 C1128 오류가 발생할 수 있다. 구성 속성 > C/C++ > 명령줄에 /bigobj 를 추가하자.

메모리 관련 문제가 발생할 수도 있는데 구성 속성 > 고급 > 기본 설정 빌드 도구 아키텍처를 64비트(x64) 로 바꿔보자.

Unity 빌드를 설정하고 빌드할 경우 예상치 못한 컴파일 오류를 발견할 수 있다. pragma once 누락된 경우는 추가하면 되고 struct 를 class 로 전방 선언을 잘못한 경우는 맞춰주면 된다.

수정하기 힘들 경우 개별 파일을 Unity Build 에서 제외하자. 개별 파일 속성에서 C/C++ > Unity 빌드 > Unity 파일에 포함을 통해 제외 설정을 할 수 있다.

예를 들어 다음과 같은 경우 컴파일 오류가 있을 수 있다.
- 미리 컴파일된 헤더를 사용하는 파일과 사용하지 않는 파일이 같이 묶인 경우
- include 된 파일에 namespace 나 struct/class 이름, OPTION, DEBUG, CONFIG 와 같은 define 과 enum 들이 재정의 된 경우
- file scope static 변수가 겹치는 경우

Unity 빌드를 적용하면 파일이 많은 프로젝트 같은 경우 25% ~ 50% 정도 빌드 시간이 줄어드는 것 같다.

Unity 빌드를 적용하면 Include 누락을 조심해야 한다. 다른 파일에 include 되어 자신의 개발 환경이나 커밋한 시점에는 빌드에 문제가 없을 수 있지만 다른 사람이 커밋할 경우 Unity 빌드 파일 구성이 변경되어 include 오류가 발생할 수 있다. Unity 빌드를 사용하지 않는 다른 빌드 환경에서는 바로 문제가 발생한다. ReSharper 와 같은 툴의 도움을 받을 수도 있지만 작업 파일을 수시로 개별 컴파일(Ctrl+F7) 해서 실수를 줄일 수 있다.

참고로 Unreal Build Tool 의 경우 Adaptive Unity Build 라고 자체적으로 만든 기능이 있다. git 이나 perforce 으로 수정 중인 파일(checkout) 은 Unity Build 에서 빼서 컴파일 해준다. 수정 중인 파일을 unity 에서 분리해서 컴파일 시간을 줄여주는 효과만 생각했었는데 이런 include 오류를 잡아주는 효과도 큰 것 같다.

P.S. (2022-04-30) #pragma warning(disable:nnnn) 같은 선언이 다른 파일에 영향을 줄 수 있으니 #pragma warning(push) - #pragma warning(pop) 으로 잘 묶어서 사용하자.

728x90

cherry pick 으로 commit 들을 branch 여기 저기에 밀어넣다보니 누락되는 경우가 잦다.

master 에 3 - 4 - 5 - 6 - 7 이렇게 commit 되어 있는데 5에서 branch 된 branch2 에 7 만 커밋되어 있을 때 6을 찾고 싶은 상황이다.

이 때 git log --cherry-pick 명령을 사용하면 된다.

$ git log --left-right --graph --cherry-pick --oneline master...branch2
< 6d7a4c8 master6

6 번 commit 이 누락된 것을 찾아낼 수 있다.

--cherry-pick 이나 --left-only, --right-only 의 의미는 아래와 같다.

--cherry-pick
Omit any commit that introduces the same change as another commit on the “other side” when the set of commits are limited with symmetric difference.For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right (see the example below in the description of the --left-right option). However, it shows the commits that were cherry-picked from the other branch (for example, “3rd on b” may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.
--left-only
--right-only
List only commits on the respective side of a symmetric difference, i.e. only those which would be marked < resp. > by --left-right.For example, --cherry-pick --right-only A...B omits those commits from B which are in A or are patch-equivalent to a commit in A. In other words, this lists the + commits from git cherry A B. More precisely, --cherry-pick --right-only --no-merges gives the exact list.

--committer= 를 이용해서 자신의 커밋들로 필터할 수도 있다.

--committer=<pattern>
Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression). With more than one --author=<pattern>, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer=<pattern>).

2 에서 branch 한 branch1은 4 - 5 를 commit 했다. 4 를 cherry-pick 할 때 conflict 이 발생해서 수정해서 commit 한 상황이다. 이 경우에는 별개의 commit 으로 취급되는 것 같다.

$ git log --cherry-pick --graph --left-only master...branch1 --oneline
* 04a157f (master) master7
* 6d7a4c8 master6
* 9f14aec master4
* b40362d master3

누락된 3, 6, 7 뿐 아니라 4도 목록에 보인다.

출처 : https://medium.com/@Drew_Stokes/git-tips-cherry-picking-logs-d64a71559fd

 

Git Tips: Cherry Picking Logs

Show commit diffs between branches

medium.com

참고 : https://git-scm.com/docs/git-log

 

Git - git-log Documentation

If the commit is a merge, and if the pretty-format is not oneline, email or raw, an additional line is inserted before the Author: line. This line begins with "Merge: " and the hashes of ancestral commits are printed, separated by spaces. Note that the lis

git-scm.com

 

728x90

타이틀바에 솔루션 명이 보이지만 여러 브랜치를 clone / checkout 해서 사용하다 보면 솔루션 명이 같다보니 어디에서 작업하고 있는지 헤깔린다.

아래에 브랜치 명이 보이지만 눈에 잘 띄지 않는다.

https://marketplace.visualstudio.com/items?itemName=mayerwin.RenameVisualStudioWindowTitle&ssr=false#overview 

 

Customize Visual Studio Window Title - Visual Studio Marketplace

Extension for Visual Studio - This lightweight extension allows changing the window title of Visual Studio to include a folder tree with a configurable min depth and max depth distance from the solution/project file, and the use of special tags to help wit

marketplace.visualstudio.com

타이틀을 바꿀 수 있는 방법이 없는지 찾아보다가 Customize Visual Studio Window Title 이라는 확장을 발견했다. Visual Studio 2015, 2017, 2019 는 검색해서 설치할 수 있다.

https://github.com/mayerwin/vs-customize-window-title/releases/tag/5.0.1

 

Release CustomizeVSWindowTitle 5.1.0 (Visual Studio 2022 Support) · mayerwin/vs-customize-window-title

You may use this release to install the extension on Visual Studio 2022. The extension available on the Visual Studio Marketplace will be updated to support Visual Studio 2022 when Microsoft will h...

github.com

Visual Studio 2022 는 임시로 github 에서 vsix 파일을 다운받아 설치할 수 있다.

도구 > 옵션 > Customize VS Window Title 메뉴에서 설정할 수 있다.

[gitBranchName] 을 사용하면 상단 타이틀에 위와 같은 모양으로 표시된다.

하단 작업 표시줄이나 작업 관리자에서도 브랜치 명을 확인할 수 있다.

출처 : https://chomdoo.tistory.com/10

 

비주얼 스튜디오 윈도우 타이틀에 브랜치 이름 표시하기

위와 같이 솔루션 이름 뒤에 브랜치 이름을 붙일 수 있는 플러그인 발견했다. 플러그인 다운로드 경로 : marketplace.visualstudio.com/items?itemName=mayerwin.RenameVisualStudioWindowTitle Customize Visual..

chomdoo.tistory.com

 

728x90

+ Recent posts