Avatar ·

Linker error: /usr/bin/ld: cannot find -l<library_name> in C++ on Linux

Hello! I'm a beginner in C++ and Linux, and I've been struggling with this error for several hours. I'm writing a simple program that uses a library for working with images (libpng). I installed it via apt: `sudo apt install libpng-dev`. Here's my code (file main.cpp):\n\n```cpp\n#include \n#include \n\nint main() {\n std::cout << "Hello, PNG!" << std::endl;\n return 0;\n}\n```\n\nI compile like this: `g++ main.cpp -o test -lpng`. In response I get:\n\n```\n/usr/bin/ld: cannot find -lpng\ncollect2: error: ld returned 1 exit status\n```\n\nI checked that the library files exist: `ls /usr/lib/x86_64-linux-gnu/libpng*` shows `libpng16.a`, `libpng16.so`, `libpng.a` and `libpng.so`. Why doesn't the linker see the library? I tried different flags: `-L/usr/lib/x86_64-linux-gnu`, `-static`, but nothing works.