alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization šŸ“ŠšŸ—¾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.24k stars 325 forks source link

Problem with Link Library in Mingw #260

Closed KRJackLee closed 2 years ago

KRJackLee commented 2 years ago

Bug category

Describe the bug

I am a newbie in the way of C++ and try to build some tasks as I did with Python. Since I am using mingw, I use the system-prebuilt Linux distribution for include and lib and put them into my default include and lib path. To test my installation, I run the script in examples/line_plot/plot/plot_1.cpp with g++ plot_1.cpp -lmatplot. ld could find the libmatplot.a but it complies as if no matplot functions were in the .a file. What am I doing wrong with the build process? Cmake seems a big program so I currently stick to make with simple g++ commands. The only experience I have with Cmake was building packages, so a complie-able command is highly appreciated. I used the similar command to link to other third-party libraries and it complies well, so I suppose the syntax is fine.

Steps to Reproduce

# scripts
#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;
    std::vector<double> x = linspace(0, 2 * pi);
    std::vector<double> y = transform(x, [](auto x) { return sin(x); });

    plot(x, y, "-o");
    hold(on);
    plot(x, transform(y, [](auto y) { return -y; }), "--xr");
    plot(x, transform(x, [](auto x) { return x / pi - 1.; }), "-:gs");
    plot({1.0, 0.7, 0.4, 0.0, -0.4, -0.7, -1}, "k");

    show();
    return 0;
}

# command
g++ plot_1.cpp -lmatplot
or
g++ plot_1.cpp -lmatplot -lnodesoup
or
g++ plot_1.cpp lnodesoup

Output Some user-specific details are trimmed.

```console # The output you got ld.exe: plot_1.cpp:(.text+0xd0): undefined reference to `matplot::linspace(double, double)' ld.exe: undefined reference to `matplot::transform(std::vector > const&, std::function)' ld.exe: undefined reference to `matplot::hold(bool)' ld.exe: undefined reference to `matplot::transform(std::vector > const&, std::function)' ld.exe: undefined reference to `matplot::transform(std::vector > const&, std::function)' ld.exe: plot_1.cpp:(.text$_ZN7matplot4plotERKSt6vectorIdSaIdEESt17basic_string_viewIcSt11char_traitsIcEE[_ZN7matplot4plotERKSt6vectorIdSaIdEESt17basic_string_viewIcSt11char_traitsIcEE]+0x2d): undefined reference to `matplot::gca()' ld.exe: plot_1.cpp:(.text$_ZN7matplot4plotERKSt6vectorIdSaIdEESt17basic_string_viewIcSt11char_traitsIcEE[_ZN7matplot4plotERKSt6vectorIdSaIdEESt17basic_string_viewIcSt11char_traitsIcEE]+0x66): undefined reference to `matplot::axes_type::plot(std::vector > const&, std::basic_string_view >)' ld.exe: plot_1.cpp:(.text$_ZN7matplot4showEv[_ZN7matplot4showEv]+0x13): undefined reference to `matplot::gcf()' ld.exe: plot_1.cpp:(.text$_ZN7matplot4showEv[_ZN7matplot4showEv]+0x27): undefined reference to `matplot::figure_type::show()' ld.exe: plot_1.cpp:(.text$_ZN7matplot4plotISt6vectorIdSaIdEEJRS3_RA3_KcEEEDaT_DpOT0_[_ZN7matplot4plotISt6vectorIdSaIdEEJRS3_RA3_KcEEEDaT_DpOT0_]+0x23): undefined reference to `matplot::gca()' ld.exe: plot_1.cpp:(.text$_ZN7matplot4plotISt6vectorIdSaIdEEJRS3_RA3_KcEEEDaT_DpOT0_[_ZN7matplot4plotISt6vectorIdSaIdEEJRS3_RA3_KcEEEDaT_DpOT0_]+0x8b): undefined reference to `matplot::axes_type::plot(std::vector > const&, std::vector > const&, std::basic_string_view >)' ld.exe: plot_1.cpp:(.text$_ZN7matplot4plotISt6vectorIdSaIdEEJS3_RA5_KcEEEDaT_DpOT0_[_ZN7matplot4plotISt6vectorIdSaIdEEJS3_RA5_KcEEEDaT_DpOT0_]+0x23): undefined reference to `matplot::gca()' ld.exe: plot_1.cpp:(.text$_ZN7matplot4plotISt6vectorIdSaIdEEJS3_RA5_KcEEEDaT_DpOT0_[_ZN7matplot4plotISt6vectorIdSaIdEEJS3_RA5_KcEEEDaT_DpOT0_]+0x8b): undefined reference to `matplot::axes_type::plot(std::vector > const&, std::vector > const&, std::basic_string_view >)' collect2.exe: error: ld returned 1 exit status make: *** [Makefile:2: default] Error 1 ```

Platform

Environment Details:

Additional context