If you’re using , JetBrains’ powerful cross-platform IDE, you have several excellent—and sometimes confusing—options. Do you manually edit CMakeLists.txt ? Use find_package ? Or point and click in the settings?
find_package(PkgConfig REQUIRED) pkg_check_modules(LIBUSB REQUIRED libusb-1.0) target_link_libraries(my_app PRIVATE $LIBUSB_LIBRARIES) target_include_directories(my_app PRIVATE $LIBUSB_INCLUDE_DIRS) Best for: Automatically downloading libraries from GitHub during configuration.
add_library(imported_mylib STATIC IMPORTED) set_target_properties(imported_mylib PROPERTIES IMPORTED_LOCATION "/path/to/libmylib.a" INTERFACE_INCLUDE_DIRECTORIES "/path/to/include" ) target_link_libraries(my_app PRIVATE imported_mylib) Best for: Popular libraries like Boost, OpenCV, Qt, or anything that provides a CMake config file.
One of the first hurdles every C++ developer faces when moving from a simple "Hello World" to a real-world project is dependency management. You need logging, networking, graphics, or maybe just a handy utility library. But how do you tell your IDE and compiler where to find these external libraries?
find_package(Boost 1.75 REQUIRED COMPONENTS filesystem system) if(Boost_FOUND) target_link_libraries(my_app PRIVATE Boost::filesystem Boost::system) endif() CMake will automatically search standard system paths, or paths you hint via -DCMAKE_PREFIX_PATH . Not every library provides CMake configs. For those, you can use pkg-config (common on Linux):
Biztosan törölni szeretnéd?
If you’re using , JetBrains’ powerful cross-platform IDE, you have several excellent—and sometimes confusing—options. Do you manually edit CMakeLists.txt ? Use find_package ? Or point and click in the settings?
find_package(PkgConfig REQUIRED) pkg_check_modules(LIBUSB REQUIRED libusb-1.0) target_link_libraries(my_app PRIVATE $LIBUSB_LIBRARIES) target_include_directories(my_app PRIVATE $LIBUSB_INCLUDE_DIRS) Best for: Automatically downloading libraries from GitHub during configuration. clion add external library
add_library(imported_mylib STATIC IMPORTED) set_target_properties(imported_mylib PROPERTIES IMPORTED_LOCATION "/path/to/libmylib.a" INTERFACE_INCLUDE_DIRECTORIES "/path/to/include" ) target_link_libraries(my_app PRIVATE imported_mylib) Best for: Popular libraries like Boost, OpenCV, Qt, or anything that provides a CMake config file. Or point and click in the settings
One of the first hurdles every C++ developer faces when moving from a simple "Hello World" to a real-world project is dependency management. You need logging, networking, graphics, or maybe just a handy utility library. But how do you tell your IDE and compiler where to find these external libraries? One of the first hurdles every C++ developer
find_package(Boost 1.75 REQUIRED COMPONENTS filesystem system) if(Boost_FOUND) target_link_libraries(my_app PRIVATE Boost::filesystem Boost::system) endif() CMake will automatically search standard system paths, or paths you hint via -DCMAKE_PREFIX_PATH . Not every library provides CMake configs. For those, you can use pkg-config (common on Linux):