alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.24k stars 325 forks source link

Followed build and install instruction but failed to compile sample elsewhere. #372

Open fhvirus opened 1 year ago

fhvirus commented 1 year ago

Bug category Installation issues.

Describe the bug I followed build and install instruction, but when compiling an example manually (not with cmake, it failes to link and gives following error for each function I use from matplot++:

/usr/bin/ld: /tmp/ccqhfOPZ.o: in function `main':
t.cpp:(.text+0x3c): undefined reference to `matplot::linspace(double, double)'
collect2: error: ld returned 1 exit status

Steps to Reproduce

Following Build and install guide for Ubuntu + GCC.

Output

There is no `.cpp` files under `/usr/local/include/matplot`. Installed files: ``` -- Install configuration: "Release" -- Installing: /usr/local/lib/Matplot++/libnodesoup.a -- Installing: /usr/local/include/matplot/detail/exports.h -- Installing: /usr/local/lib/libmatplot.a -- Up-to-date: /usr/local/include/matplot -- Up-to-date: /usr/local/include/matplot/backend -- Installing: /usr/local/include/matplot/backend/opengl_embed.h -- Installing: /usr/local/include/matplot/backend/backend_interface.h -- Installing: /usr/local/include/matplot/backend/opengl.h -- Installing: /usr/local/include/matplot/backend/backend_registry.h -- Installing: /usr/local/include/matplot/backend/gnuplot.h -- Up-to-date: /usr/local/include/matplot/util -- Installing: /usr/local/include/matplot/util/geodata.h -- Installing: /usr/local/include/matplot/util/popen.h -- Installing: /usr/local/include/matplot/util/type_traits.h -- Installing: /usr/local/include/matplot/util/common.h -- Installing: /usr/local/include/matplot/util/contourc.h -- Installing: /usr/local/include/matplot/util/handle_types.h -- Installing: /usr/local/include/matplot/util/keywords.h -- Installing: /usr/local/include/matplot/util/concepts.h -- Installing: /usr/local/include/matplot/util/colors.h -- Up-to-date: /usr/local/include/matplot/freestanding -- Installing: /usr/local/include/matplot/freestanding/figure_functions.h -- Installing: /usr/local/include/matplot/freestanding/axes_lim.h -- Installing: /usr/local/include/matplot/freestanding/plot.h -- Installing: /usr/local/include/matplot/freestanding/histcounts.h -- Installing: /usr/local/include/matplot/freestanding/axes_functions.h -- Up-to-date: /usr/local/include/matplot/core -- Installing: /usr/local/include/matplot/core/axis_type.h -- Installing: /usr/local/include/matplot/core/legend.h -- Installing: /usr/local/include/matplot/core/figure_registry.h -- Installing: /usr/local/include/matplot/core/axes_type.h -- Installing: /usr/local/include/matplot/core/line_spec.h -- Installing: /usr/local/include/matplot/core/figure_type.h -- Installing: /usr/local/include/matplot/core/axes_object.h -- Up-to-date: /usr/local/include/matplot/detail -- Installing: /usr/local/include/matplot/detail/config.h -- Installing: /usr/local/include/matplot/matplot.h -- Up-to-date: /usr/local/include/matplot/axes_objects -- Installing: /usr/local/include/matplot/axes_objects/bars.h -- Installing: /usr/local/include/matplot/axes_objects/surface.h -- Installing: /usr/local/include/matplot/axes_objects/stair.h -- Installing: /usr/local/include/matplot/axes_objects/box_chart.h -- Installing: /usr/local/include/matplot/axes_objects/circles.h -- Installing: /usr/local/include/matplot/axes_objects/line.h -- Installing: /usr/local/include/matplot/axes_objects/function_line.h -- Installing: /usr/local/include/matplot/axes_objects/parallel_lines.h -- Installing: /usr/local/include/matplot/axes_objects/labels.h -- Installing: /usr/local/include/matplot/axes_objects/vectors.h -- Installing: /usr/local/include/matplot/axes_objects/contours.h -- Installing: /usr/local/include/matplot/axes_objects/filled_area.h -- Installing: /usr/local/include/matplot/axes_objects/network.h -- Installing: /usr/local/include/matplot/axes_objects/string_function.h -- Installing: /usr/local/include/matplot/axes_objects/histogram.h -- Installing: /usr/local/include/matplot/axes_objects/matrix.h -- Installing: /usr/local/include/matplot/axes_objects/error_bar.h -- Installing: /usr/local/lib/cmake/Matplot++/Matplot++Targets.cmake -- Installing: /usr/local/lib/cmake/Matplot++/Matplot++Targets-release.cmake -- Installing: /usr/local/lib/cmake/Matplot++/Matplot++ConfigVersion.cmake -- Installing: /usr/local/lib/cmake/Matplot++/Matplot++Config.cmake ```

Platform

Environment Details:

alandefreitas commented 1 year ago

not with cmake

The instructions use cmake to link the libraries. By not using cmake, you have the responsibility to do all the linking the cmake scripts do by yourself. Simply not linking it won't work.

ak-ferhat commented 10 months ago

I had the same problem on Almalinux 8.8. Here is what I did.

Suppose the libmatplot.a (libmatplot.so) library is in "/matplot1.2.0/lib64" folder

1- For compiling you example (main.cpp), you have to specify all the required libraries, and the path to "matplotlib.a":

g++ -std=c++17 -L/matplot1.2.0/lib64 -lmatplot -lstdc++fs -lpng -ljpeg -ltiff -llapack -lblas -lfftw3 -lpthread -lz main.cpp -o myoutfile

Notice -L/matplot1.2.0/lib64 to specify the path

2- For launching Now you have to specify the path to the library for launch your example (myoutfile). You may have the same problem if you test the examples which come the package.

eport LD_LIBRARY_PATH=/matplot1.2.0/lib64:$LD_LIBRARY_PATH ./myoutfile

This works for me.