Tag Archives: cpp

openSSL vs. vcpkg – some strange experiences

One of the projects I was working in the last period uses CURL that uses OpenSSL version 1.1.1.1 in foreground. At some moment in time, for some technical reasons I was tempted to try using the CPPRESTSDK library. But because I had some local NuGet miss-configuration issues in order to have the CPPRESTSDK library build I realized I need to build it myself. But in order to achieve this, I needed the vcpkg tool.

And, because with a quick search I haven’t found the download and the Azure DevOps of this tool for built was down and no Artifacts available, I said: what if I build it myself?

So, I did it… It lasted some time on my laptop but at the end was fine. I had a brand new vcpkg package and I built the cpprestsdk.

Later, returning to my project and integrating the new cpprestsdk library I realized I was started getting new linking errors.

2>Generating   Code...   
2>libcrypto.lib(comp_lib.obj)   : error LNK2005: COMP_CTX_free already defined in libeay32.lib(LIBEAY32.dll)  
2>libcrypto.lib(comp_lib.obj)   : error LNK2005: COMP_CTX_new already defined in libeay32.lib(LIBEAY32.dll)
2>libcrypto.lib(comp_lib.obj)   : error LNK2005: COMP_compress_block already defined in   libeay32.lib(LIBEAY32.dll)  
2>libcrypto.lib(comp_lib.obj)   : error LNK2005: COMP_expand_block already defined in   libeay32.lib(LIBEAY32.dll)   
2>Creating library C:\dev\ my-project\Build\x64\Debug\myproject.lib and object   C:\dev\my-project\Build\x64\Debug\myproject.exp   
2>C:\dev\my-project\Build\x64\Debug\   myproject.dll : fatal error LNK1169: one or more multiply defined symbols   found

Within the sample solution, the situation is even worth. I was able to find out even more compile errors while the vcpkg is installed.

Vcpkg uses OpenSSL to insure secure connection and googling I found out that starting with the OpenSSL 1.1.x Windows version the static LIB and DLL filenames have changed, so depending on local files, it may affect, the former DLL’s libeay32.dll and ssleay32.dll are no longer available.

I double-checked the environment variables, trying to identify paths containing the old libeay32.dll (that was renamed to openssl.dll) and to remove it. I did such investigation, but I found nothing “suspicions”.
The goal was to avoid the names’ collision in case the linker was looking to link “our” openSSL together with LIBEAY32.dll.

The salvation came from GauthamBanasandra’s suggestion. I just ran the next command within the vcpkg repository local folder.

.\vcpkg.exe integrate remove

After the execution of this command, I was able to build back the project as before. And it was fine for me… I don’t need the vcpkg for other proposes right now.
By the way, this command has to be executed within the vcpkg cloning repository folder. Otherwise, you’ll get an error: Could not detect vcpkg-root in case you don’t have an environment variable VCPKG_ROOT pointing to your vcpkg binary repository.

Off-course, in case you still need vcpkg.exe you can reinstall it temporary with vcpkg.exe integrate install. But then, until there is a fix for this situation or a better workaround, you might face the initial problem I had within OpenSSL based projects. So, most probably you will have to call again vcpkg.exe integrate remove.

The issues are created by the fact the actual vcpkg.exe manager is still using the old openSSL library, libeay32.dll.

Until the Vcpkg team didn’t upgrade to a newer OpenSSL library (1.1.x+), we will have to find such workarounds in order to compile different projects. If someone knows other workaround and is open to share, I would not mind mentioning here her/his idea.

The good news is that an upgrade to the OpenSSL 1.1.x is ongoing. The upgrade issue is already open and the pull request #8566 seems advanced in progress. Let’s stay tuned!

psa.exe partial tree sample

Process Status Analysis – the first steps

I am pleased to announce my first cross-platform and open source project, the Process Status Analysis tool, available on GitHub.

The Process Status Analysis (psa) version 0.2 is available for Windows and Linux (Debian derived / Ubuntu tested) Operating Systems.
Download: psa for Ubuntu Linux x64 (4908 downloads)
Download: psa for Ubuntu Linux x86 (4157 downloads)
Download: psa.exe for Windows x64 (4117 downloads)
Download: psa.exe for Win32 (4086 downloads)

You may wonder why I did it or what it brings new. Well, I did it for fun, in my spare time and I will continue improving it when I’ll find a time to do it.

The project is written in modern C++ using idioms from the C++ 1x standards. Even if initially was done as a C++ for Windows only, during the past days I managed the port of it for Linux using Visual Studio 2017’s project templates and a connection via SSH.
In general, the source code base is similar, differing just by OS specific stuff.

In case you want to find out more about how to develop C++ Linux projects from the best development tool (imho), Visual Studio, you can find more information on Visual Studio development team blog.

Related to this psa project, the Linux version requires libprocps4-dev library in order to build.

The main reason for starting this project was that I wanted to know what’s the total memory amount used by my Chrome browser. I know it uses a lot of resources, but not that much… 🙂

Even if my preferred processes analysis tool, the Process Hacker offers a lot of processes administration possibilities, but it didn’t provide what I want, so I decided to enjoy a bit.

Chrome processes in Process Hacker

Sample – Google Chrome processes in Process Hacker tool

So, what I achieved by psa.exe was something like:

C:\Windows\system32> psa -o chrome
PID [896] chrome.exe 237.5234 MB
PID [1496] chrome.exe 87.6875 MB
PID [2388] chrome.exe 166.5000 MB
PID [5860] chrome.exe 3.1211 MB
PID [7336] chrome.exe 273.2188 MB
PID [8444] chrome.exe 68.0508 MB
PID [8624] chrome.exe 63.3945 MB
PID [9180] chrome.exe 296.9766 MB
PID [10600] chrome.exe 292.6289 MB
PID [12352] chrome.exe 182.5977 MB
PID [13688] chrome.exe 2.3555 MB
PID [14052] chrome.exe 73.1875 MB
PID [16200] chrome.exe 211.9805 MB
PID [17284] chrome.exe 55.7148 MB
PID [18036] chrome.exe 208.6680 MB
PID [19012] chrome.exe 457.2305 MB
PID [19312] chrome.exe 143.4766 MB
-----------------------------------
Total used memory: 2824.31 MB

A bit too much in my humble opinion…
The features this tool offers includes:

Get all processes loaded in memory information

I case you want to have a snapshot of all the processes loaded in the OS’s memory you can have it with.

psa -a

Get process only used memory

With psa.exe you can reach the used memory by a specific parameter -o after the process name or at least a part of its name.

psa -o chrome             // find how much memory uses your Chrome!   o_O

Currently, there is no string replace ‘*’ but it’s ongoing.


Print processes tree

Storing the processes’ data within a generic tree done by me, I took the decision to print the processes’ tree output, similarly there is in Windows with tree.exe tool or on Linux in pstree or even htop.

./psa -t
./psa -t 1034

psa.exe partial tree sample

Process Status Analysis partial tree of Windows process

Top most “expensive” processes

In case you want to see what are the most expensive processes within your operating system, you can achieve it with:

psa -e 20

or simpler psa -e in case you’re sure you want top 10 expensive processes (the default value).

silviu@ubuntu-dev-server:~/projects/psa-lin/bin/x64/Release$ ./psa -e
Top 10 consuming memory processes
-------------------------------------------
PID        Process Name         RAM Usage
-------------------------------------------
[924]    /usr/lib/policykit-1/polkitd   270.68 MB
[906]    /usr/lib/accountsservice/accounts-daemon       269.43 MB
[842]    /usr/sbin/rsyslogd     250.39 MB
[878]    /usr/lib/snapd/snapd   197.29 MB
[531]    /lib/systemd/systemd-timesyncd         97.97 MB
[1614]    sshd: silviu@pts/0    93.16 MB
[1576]    sshd: silviu [priv]   93.16 MB
[863]    /usr/bin/lxcfs         93.13 MB
[427]    /sbin/lvmetad          92.55 MB
[1034]    /usr/sbin/sshd        63.98 MB
-------------------------------------------


C:\Windows\system32> psa -e 10
Top 10 consuming memory processes
-------------------------------------------
PID        Process Name         RAM Usage
-------------------------------------------
[19012]    chrome.exe           435.67 MB
[17684]    chrome.exe           329.51 MB
[7336]    chrome.exe            259.61 MB
[15576]    devenv.exe           248.20 MB
[896]    chrome.exe             222.85 MB
[2388]    chrome.exe            188.21 MB
[18428]    chrome.exe           184.48 MB
[15760]    chrome.exe           173.82 MB
[488]    Dropbox.exe            162.15 MB
[5488]    googledrivesync.exe   161.11 MB
-------------------------------------------
Total used memory: 2365.61 MB

Redirect output to a file

From the standard output the information can be easily redirected to a file.

c:\> psa -t > windows_processes_tree.txt
# ./psa -t > linux_processes_tree.txt        

Kill process feature

This feature was not implemented yet but in case we need it we can be done it easily with the existing tools on the target OS (ex. Task Manager, Process Exporer/Hacker, pskill.exe for Windows or the combination ps + kill on LInux).

Feedbacks and improvements
Any constructive feedback, suggestions, contributions to improvements are appreciated.
Feel free to add any issue you find, wish or suggestion you have in the GitHub repository, the 
Issues section or here as a comment.