Home > Backend Development > C++ > Why Does CMake Fail to Find My Library Despite Using `link_directories`?

Why Does CMake Fail to Find My Library Despite Using `link_directories`?

DDD
Release: 2024-12-02 00:41:11
Original
569 people have browsed it

Why Does CMake Fail to Find My Library Despite Using `link_directories`?

CMake Cannot Locate Library Despite Using ""link_directories"

In your CMake configuration, you specified the directory containing the shared library with link_directories(/usr/lib/x86_64-linux-gnu). However, the linker reported undefined references to functions in the protobuf library.

The key to resolving this issue lies in the ordering of your CMake commands. Ensure that link_directories is called before add_executable:

link_directories(/usr/lib/x86_64-linux-gnu)
add_executable(test main.cpp)
Copy after login

By adjusting the order, CMake will correctly locate the library and link it to your executable.

The above is the detailed content of Why Does CMake Fail to Find My Library Despite Using `link_directories`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template