This is the first time I am installing a library from github in a Linux distribution, I successfully installed it but I had some doubts on how this magnificent utilities work. Moreover, I wanted to still have some doubts on how the headers actually include the libraries(statically or dynamically). I have successfully installed a C modbus library from the github source:
https://github.com/stephane/libmodbus
The library has also a set of tests to use the library. The README file tells to run the pkg-config command that of course allows gcc to find for the compiled library automatically.
Btw, I wanted to compile the sources from the test directory by using just gcc. After installing and running pkg--config, I have in the two following paths:
/usr/local/lib/include/modbus
/usr/local/include/modbus
while the file modbus.a and modbus.so are in the directories:
/usr/local/lib
/usr/local/lib/lib
First of all I have no idea if the library are linked statically or dynamically. At the link:
https://www.cyberciti.biz/faq/linux-setting-changing-library-path/
it explain how to use the utility ldconfig to allow dynamical linking of installed libraries. So I simply created the libc.conf file where I added:
/usr/local/include
When I run the command to check if it was updated
ldconfig -v | grep /usr/local/lib
I get is:
/sbin/ldconfig.real: Can't stat /usr/local/lib/x86_64-linux-gnu: No such file or directory
/sbin/ldconfig.real: Path /lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path
/usr/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.27.so is the dynamic linker, ignoring
/usr/local/lib: /sbin/ldconfig.real: /lib32/ld-2.27.so is the dynamic linker, ignoring
Next I ran :
sudo gcc random-test-client.c
but I got:
random-test-client.c:15:10: fatal error: modbus.h: No such file or directory
#include <modbus.h>
^~~~~~~~~~
compilation terminated.
What I did was also to directly add the path of the library and header file:
gcc -Wl,-R/usr/local/lib -I/usr/local/lib/include/modbus -L/usr/local/lib -o myAppName random-test-server -llibapp2
and I got :
/usr/bin/ld: random-test-server: stderr: invalid version 2 (max 0)
random-test-server: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Finally I tried to upload the epath environment variable for the linux shared library variable by running:
export LD_LIBRARY_PATH=/usr/local/lib
But again the gcc command (in the two versions )gave me the same identical errors. I have no experience at software development, but I would like to get started. The fact is that I know what I want to do but still I don't which tools to use to achieve the objective. I hope you could give more info of what I am doing wrong and most of all why it is wrong.