Pages - Menu
標籤
搜尋此網誌
2021年6月18日星期五
2021年3月27日星期六
C++ package manager CMake vcpkg
How to use vcpkg with CMake
Steps
- Create C++ project by CCreate
- CCreate -p TradingPlatform
- cd TradingPlatform/Projects/TradingPlatform/app
- CCreate -a ThePlatform
- Install vcpkg
- https://docs.microsoft.com/en-us/cpp/build/install-vcpkg?view=msvc-160&tabs=linux
- git clone https://github.com/microsoft/vcpkg
- cd ./vcpkg
- ./bootstrap-vcpkg.sh
- Install package
- cd ./vcpkg
- ./vcpkg search | grep json
- ./vcpkg install rapidjson
Computing installation plan...
The following packages will be built and installed:
rapidjson[core]:x64-linux -> 2020-09-14
Detecting compiler hash for triplet x64-linux...
Could not locate cached archive: /home/sulfred/.cache/vcpkg/archives/16/16e324f00567b9fbcd2f106e12e631094b31b5de.zip
Starting package 1/1: rapidjson:x64-linux
Building package rapidjson[core]:x64-linux...
-- Downloading https://github.com/Tencent/rapidjson/archive/ce81bc9edfe773667a7a4454ba81dac72ed4364c.tar.gz -> Tencent-rapidjson-ce81bc9edfe773667a7a4454ba81dac72ed4364c.tar.gz...
-- Extracting source /home/sulfred/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform/Projects/vcpkg/downloads/Tencent-rapidjson-ce81bc9edfe773667a7a4454ba81dac72ed4364c.tar.gz
-- Using source at /home/sulfred/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform/Projects/vcpkg/buildtrees/rapidjson/src/c72ed4364c-35829b36f2.clean
-- Configuring x64-linux-dbg
-- Configuring x64-linux-rel
-- Building x64-linux-dbg
-- Building x64-linux-rel
-- Installing: /home/sulfred/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform/Projects/vcpkg/packages/rapidjson_x64-linux/share/rapidjson/copyright
-- Installing: /home/sulfred/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform/Projects/vcpkg/packages/rapidjson_x64-linux/share/rapidjson/usage
-- Performing post-build validation
-- Performing post-build validation done
Stored binary cache: /home/sulfred/.cache/vcpkg/archives/16/16e324f00567b9fbcd2f106e12e631094b31b5de.zip
Building package rapidjson[core]:x64-linux... done
Installing package rapidjson[core]:x64-linux...
Installing package rapidjson[core]:x64-linux... done
Elapsed time for package rapidjson:x64-linux: 1.485 s
Total elapsed time: 1.76 s
The package rapidjson provides CMake integration:
find_package(RapidJSON CONFIG REQUIRED)
target_include_directories(main PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
- Cmake setting
-DCMAKE_TOOLCHAIN_FILE=../Projects/vcpkg/scripts/buildsystems/vcpkg.cmake
sulfred@sulfred-PC:~/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform/Debug$ cat readme.txt | grep cmake cmake -G Ninja ../Projects -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../Install -DCMAKE_TOOLCHAIN_FILE=../Projects/vcpkg/scripts/buildsystems/vcpkg.cmake sulfred@sulfred-PC:~/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform/Debug$ cd .. sulfred@sulfred-PC:~/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform$ ll total 24 drwxrwxr-x 6 sulfred sulfred 4096 Mar 27 20:05 ./ drwxrwxr-x 3 sulfred sulfred 4096 Mar 27 20:10 ../ drwxrwxr-x 4 sulfred sulfred 4096 Mar 27 20:29 Debug/ drwxrwxr-x 3 sulfred sulfred 4096 Mar 27 20:30 Install/ drwxrwxr-x 4 sulfred sulfred 4096 Mar 27 20:30 Projects/ drwxrwxr-x 2 sulfred sulfred 4096 Mar 27 20:05 Release/ sulfred@sulfred-PC:~/Documents/SoftwareDev/github/SulfredLee/DailyProblem/cpp/app/ProjectCreater/bin/TradingPlatform$ ll Projects/ total 24 drwxrwxr-x 4 sulfred sulfred 4096 Mar 27 20:30 ./ drwxrwxr-x 6 sulfred sulfred 4096 Mar 27 20:05 ../ -rw-rw-r-- 1 sulfred sulfred 1025 Mar 27 20:28 CMakeLists.txt drwxrwxr-x 5 sulfred sulfred 4096 Mar 27 20:30 TradingPlatform/ -rw-rw-r-- 1 sulfred sulfred 560 Mar 27 20:05 TradingPlatform.cmake drwxrwxr-x 14 sulfred sulfred 4096 Mar 27 20:12 vcpkg/
- cat ../Projects/CMakeLists.txt
- find_package(RapidJSON CONFIG REQUIRED)
- message(STATUS "Rapid include PATH: " ${RAPIDJSON_INCLUDE_DIRS})
2020年11月15日星期日
Use winmerge in git bash
.gitconfig
location
- C:\Users\<name>\.gitconfig
.gitconfig
[diff] tool = winmerge prompt = false [difftool "winmerge"] path = C:/Program Files/WinMerge/winmergeu.exe cmd = \"C:/Program Files/WinMerge/winmergeu.exe\" /e /u /wl /dl "$LOCAL" /dr "$REMOTE" "$LOCAL" "$REMOTE" [merge] tool = winmerge prompt = false [mergetool "winmerge"] path = C:/Program Files/WinMerge/winmergeu.exe cmd = \"C:/Program Files/WinMerge/winmergeu.exe\" /e /u /wl /dl "$LOCAL" /dr "$REMOTE" "$LOCAL" "$REMOTE" -o "$MERGED" trustExitCode = true keepBackup = false
[diff] tool = meld prompt = false [difftool "meld"] path = C:/Program Files (x86)/Meld/Meld.exe cmd = \"C:/Program Files (x86)/Meld/Meld.exe\" "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED" [merge] tool = meld prompt = false [mergetool "meld"] path = C:/Program Files (x86)/Meld/Meld.exe cmd = \"C:/Program Files (x86)/Meld/Meld.exe\" "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED" trustExitCode = true keepBackup = false [user] email = sflee1112@gmail.com name = SulfredLee
2020年11月6日星期五
How cmake find package works
Aim
Here are some examples showing how to use cmake find packet.
Learn from
Examples - use default modules
ALSA library
You can install the library first.
$ sudo apt-get install libasound2
You can put the following code into CMakeLists.txt.
# Handle ALSA / ASound libraries find_package(ALSA) if (ALSA_FOUND) message (STATUS "Info - Found ALSA library: ${ALSA_LIBRARY}") message (STATUS "Info - Found ALSA include: ${ALSA_INCLUDE_DIR}") else (ALSA_FOUND) message (FATAL_ERROR "Info - ALSA is not found") endif (ALSA_FOUND)
How can I know which variables I can use?
- Go to official web site 001 or official web site 002
- In ubuntu you can go to the installation path and find all the modules
- /usr/share/cmake-3.16/Modules
- FindALSA.cmake
2020年10月23日星期五
Install xrdp on ubuntu
Ubuntu 20.04
Install and use (Basic)
- Install xrdp by
$ sudo apt-get install xrdp
- Logout, since you cannot remote login while the session is begin used.
- Connect from other PC, for example:
- DONE
If not working
- By default Xrdp uses the /etc/ssl/private/ssl-cert-snakeoil.key file which is readable only by users that are members of the “ssl-cert” group. Learn From
- Add to group ssl-start.
Change close lip behavior
- Restart service to activate your change
2020年10月3日星期六
Core dump file in ubuntu
Aim
When running c++ application, we would like to get the core dump when the application is crashed. How to get those files under linux?
Learn from
Steps
Add to ~/.bashrc
ulimit -c unlimited
Add to /etc/sysctl.conf
kernel.core_pattern = core.%e.%p.%t
Run command:
$ sudo sysctl --system
Ubuntu KVM guest os network
On Ubuntu 20.04
You can use the default setting first:
If the guest OS cannot connect to internet, you may try the host nic and bridge it:
If that is not okay, you may need to create a new network source. The easiest way is to install VMWare workstation or Virtual box. They will create the needed network configuration for their VMs. Now you can use the network source created by them. Here is an example:
Ubuntu KVM OpenGL
On Ubuntu 20.04
Setup
This acceleration can be use only locally. You have to disable the spice server first.
Then you can start your VM through graphical console
Ubuntu KVM multiple monitors
On Ubuntu 20.04
Learn From
Steps
Add one more Video QXL
Start VM without using virt-manager graphical console
Finally, you need to use remote-viewer and open up the guest firewall:
You may try directly remote-view the instance first, if not work, you may add the firewall steps
$ sudo apt-get install firewalld $ sudo firewall-cmd --permanent --add-service=vdsm $ sudo firewall-cmd --reload $ remote-viewer spice://localhost:5907
2020年10月2日星期五
Screenshot tools
2020年5月7日星期四
Concurrency message queue in C++
Aim
Source
Testing method
Lock Free MsgQ
- MsgQLockFree with Ring Buffer
Using Linux Concurrency library
- MsgQOneLock with Ring Buffer
- MsgQTwoLock with Ring Buffer
- MsgQOneLock with LinkList
- MsgQTwoLock with LinkList
Using C++ standard library
- MsgQOneLock with Ring Buffer
- MsgQTwoLock with Ring Buffer
- MsgQOneLock with LinkList
- MsgQTwoLock with LinkList
- Lock free
- One lock
- Two lock
More on Queue
Lock Free
One Lock
Two Lock
The Test
Hardware
- Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
- 4 core
- 4 threads
- Ubuntu 20.04 LTS
Test Info
- 300000 messages
- Threads
- 1 in, 1 out
- 2 in , 2 out
- 4 in, 4 out
- 10 in, 10 out
- 5 total tests and get the average time spend
Result
| MsgQ Type | Thread IN | Thread OUT | Total Message | Total test | Time spend Msec |
| Lock Free | 1 | 1 | 300000 | 5 | 46 |
| One Lock | 1 | 1 | 300000 | 5 | 115 |
| Two Lock | 1 | 1 | 300000 | 5 | 102.5 |
The above grape comparing 1 thread in and 1 thread out case. The lock free message queue is the fastest one. This is expected.
| Thread IO | Total Message | Total test | Msec One Lock | Msec Two Lock |
| Two | 300000 | 5 | 122 | 135.5 |
| Four | 300000 | 5 | 133.5 | 119 |
| Ten | 300000 | 5 | 150.5 | 124 |
Raw Result
| MsgQLockFree_Linux | 1 | 1 | 300000 | 5 | 46 |
| MsgQLockFree_LinkList_Std | 1 | 1 | 300000 | 5 | 100 |
| MsgStackLockFree_LinkList_Std | 1 | 1 | 300000 | 5 | 296 |
| MsgStackLockFree_LinkList_Std | 2 | 2 | 300000 | 5 | 406 |
| MsgStackLockFree_LinkList_Std | 4 | 4 | 300000 | 5 | 806 |
| MsgStackLockFree_LinkList_Std | 10 | 10 | 300000 | 5 | 568 |
| MsgQOneLock_RingBuf_Linux | 1 | 1 | 300000 | 5 | 111 |
| MsgQOneLock_RingBuf_Linux | 2 | 2 | 300000 | 5 | 109 |
| MsgQOneLock_RingBuf_Linux | 4 | 4 | 300000 | 5 | 135 |
| MsgQOneLock_RingBuf_Linux | 10 | 10 | 300000 | 5 | 186 |
| MsgQTwoLock_RingBuf_Linux | 1 | 1 | 300000 | 5 | 86 |
| MsgQTwoLock_RingBuf_Linux | 2 | 2 | 300000 | 5 | 135 |
| MsgQTwoLock_RingBuf_Linux | 4 | 4 | 300000 | 5 | 132 |
| MsgQTwoLock_RingBuf_Linux | 10 | 10 | 300000 | 5 | 128 |
| MsgQOneLock_RingBuf_Std | 1 | 1 | 300000 | 5 | 119 |
| MsgQOneLock_RingBuf_Std | 2 | 2 | 300000 | 5 | 137 |
| MsgQOneLock_RingBuf_Std | 4 | 4 | 300000 | 5 | 106 |
| MsgQOneLock_RingBuf_Std | 10 | 10 | 300000 | 5 | 115 |
| MsgQTwoLock_RingBuf_Std | 1 | 1 | 300000 | 5 | 100 |
| MsgQTwoLock_RingBuf_Std | 2 | 2 | 300000 | 5 | 136 |
| MsgQTwoLock_RingBuf_Std | 4 | 4 | 300000 | 5 | 106 |
| MsgQTwoLock_RingBuf_Std | 10 | 10 | 300000 | 5 | 120 |
| MsgQOneLock_LinkList_Linux | 1 | 1 | 300000 | 5 | 229 |
| MsgQOneLock_LinkList_Linux | 2 | 2 | 300000 | 5 | 201 |
| MsgQOneLock_LinkList_Linux | 4 | 4 | 300000 | 5 | 195 |
| MsgQOneLock_LinkList_Linux | 10 | 10 | 300000 | 5 | 197 |
| MsgQTwoLock_LinkList_Linux | 1 | 1 | 300000 | 5 | 179 |
| MsgQTwoLock_LinkList_Linux | 2 | 2 | 300000 | 5 | 268 |
| MsgQTwoLock_LinkList_Linux | 4 | 4 | 300000 | 5 | 225 |
| MsgQTwoLock_LinkList_Linux | 10 | 10 | 300000 | 5 | 213 |
| MsgQOneLock_LinkList_Std | 1 | 1 | 300000 | 5 | 250 |
| MsgQOneLock_LinkList_Std | 2 | 2 | 300000 | 5 | 189 |
| MsgQOneLock_LinkList_Std | 4 | 4 | 300000 | 5 | 209 |
| MsgQOneLock_LinkList_Std | 10 | 10 | 300000 | 5 | 223 |
| MsgQTwoLock_LinkList_Std | 1 | 1 | 300000 | 5 | 166 |
| MsgQTwoLock_LinkList_Std | 2 | 2 | 300000 | 5 | 267 |
| MsgQTwoLock_LinkList_Std | 4 | 4 | 300000 | 5 | 212 |
| MsgQTwoLock_LinkList_Std | 10 | 10 | 300000 | 5 | 219 |
| MsgQOneLock_Queue_Linux | 1 | 1 | 300000 | 5 | 203 |
| MsgQOneLock_Queue_Linux | 2 | 2 | 300000 | 5 | 158 |
| MsgQOneLock_Queue_Linux | 4 | 4 | 300000 | 5 | 152 |
| MsgQOneLock_Queue_Linux | 10 | 10 | 300000 | 5 | 172 |
| MsgQOneLock_Queue_Std | 1 | 1 | 300000 | 5 | 178 |
| MsgQOneLock_Queue_Std | 2 | 2 | 300000 | 5 | 151 |
| MsgQOneLock_Queue_Std | 4 | 4 | 300000 | 5 | 150 |
| MsgQOneLock_Queue_Std | 10 | 10 | 300000 | 5 | 154 |

















