0

I am trying to troubleshoot a problem I have in using the library matplot++. I need someone to teach me how to fish here instead of giving me a fish, because I'm struggling to google search the right terms to solve my problem.

My folder structure is as follows

-music_vis  
|-libs  
 |-3rd party  
 |-matplot  
  |-matplot.h  
  |-other_folders_for_matplot
|-wavs  
|build.sh  
|main.cpp  
|thread_pool.hpp

build.sh is as follows right now:
g++ -Wall -lmatplot -I /$(pwd)/libs -g -o music_vis_cpp ./music_vis_main.cpp -lstdc++fs -std=c++17 -pthread

Everything 100% works in this shell script except for something within this section: -lmatplot -I /$(pwd)/libs

For which I get the following error:

/usr/bin/ld: cannot find -lmatplot 
collect2: error: ld returned 1 exit status

Is g++ spuriously looking in my /usr/bin/ for files? Shouldn't it be looking in $(pwd)/libs?

From what I have researched, I am also supposed to have .so files, but everything under the matplot folder is .cpp or .h files. Does this mean I installed the library incorrectly into my /lib/ folder? I cloned from github and simply copied into my /lib/ folder. Without the -lmatplot flag I get the following error:

enter image description here

Any thoughts, resources, guidance or guidelines on how to troubleshoot these problems in the future? Thanks friends.

I followed the instructions on the repo, but piggybacking off of Compiler not finding jpeg and png libraries , I added the following flag to the cmake. This created object files for me.

-DBUILD_SHARED_LIBS=ON

  • 1
    echo $LD_LIBRARY_PATH, also see where libbmatplot.so exists? – Omid CompSCI Nov 23 '21 at 05:00
  • 1
    Just FYI, stackoverflow is for specific questions. This is a really nice question, but isn't a good fit for stackoverflow. Hopefully you'll find your answer anyway. – Elliott Nov 23 '21 at 05:03
  • 2
    `-I` is for include directories for header files during the compilation phase, you want `-L` to add places to look for libraries during linking. – Nathan Pierson Nov 23 '21 at 05:11
  • @OmidCompSCI Would you assert that I must have .so files somewhere? I checked the whole folder tree and there is no .so file to be found. there is a Makefile but I wanted to avoid running commands I don't understand, and focus on producing c++ code. Does this imply I must make the repo after cloning? thx – WhisperingShiba Nov 23 '21 at 05:31
  • @NathanPierson if I change the -I flag to -L my #include "matplot/matplot.h" line errors out upon build. – WhisperingShiba Nov 23 '21 at 05:32
  • 2
    `-lmatplot` instructs gcc to look for `libmatplot.so` file if your platform is anything like linux. That does look like part of of three there, so it might need to be compiled. If library got non-standard location, `L` key is required along with `-l` key. And ` -I` key you need too, for includes. The source of information you seek is documentation on compiler you're using, you hardly can waltz on improvisation. – Swift - Friday Pie Nov 23 '21 at 05:38
  • @Swift-FridayPie This was helpful. Even with some direction to go, I could only find guides on how to build .so files for single .c files. This library is a full tree of .h and .cpp files, and just naively substituting "./matplot" for ./cLibrary.c didn't work. Thx – WhisperingShiba Nov 23 '21 at 06:05
  • 2
    Sometimes we look not where we should... GCC docs: https://gcc.gnu.org/onlinedocs/ As your project is C++ there are related links on isocpp site https://isocpp.org/faq – Swift - Friday Pie Nov 23 '21 at 06:14

1 Answers1

0

I was able to build a .so file by following the build instructions included in the matplot++ .md file, but supplying an extra flag -DBUILD_SHARED_LIBS=ON

From there, under the build folder, I found a .so file somewhere in the folder tree, moved that to my /lib/ directory, and ran the following shell script:

#!/bin/bash
g++ -I /$(pwd)/libs -L /$(pwd)/libs -Wall -g -o music_vis_cpp ./music_vis_main.cpp -lstdc++fs  -std=c++17  -pthread   -lmatplot

And this finally built my program. However it doesn't run because shared object file doesn't exist or something.

Edit: More steps to make the program run; Create a folder on your filesystem you want to put your .so files into and then...

export LD_LIBRARY_PATH=/home/harrison/Documents/computer/cpp_packages/shared_object_lib/

I need to run this export line every time I restart my computer, so I just add it to my build script.

So the .so file is in two places, one necessary at build time and the other necessary at run time. My binaries can be run anywhere on my computer with this method.